More documentation improvements (#1509)

* Doc fixes & consistency

* Document animate timing function

* Fix missing return docs

* Fix UI class description

* Document debounce params & return

* Document className return

* Remove internal context menu noBlurEvent

* Improve period & hyphen consistency

* Fix capitalized primitive types
This commit is contained in:
Zerthox 2023-04-17 21:12:00 +02:00 committed by GitHub
parent d7ea2e1171
commit d25dae12f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 199 additions and 181 deletions

View File

@ -14,39 +14,39 @@
get folder() {return this.#manager.addonFolder;}
/**
* Determines if a particular adon is enabled.
* @param {string} idOrFile Addon id or filename.
* Determines if a particular addon is enabled.
* @param {string} idOrFile Addon ID or filename
* @returns {boolean}
*/
isEnabled(idOrFile) {return this.#manager.isEnabled(idOrFile);}
/**
* Enables the given addon.
* @param {string} idOrFile Addon id or filename.
* @param {string} idOrFile Addon ID or filename
*/
enable(idOrAddon) {return this.#manager.enableAddon(idOrAddon);}
/**
* Disables the given addon.
* @param {string} idOrFile Addon id or filename.
* @param {string} idOrFile Addon ID or filename
*/
disable(idOrAddon) {return this.#manager.disableAddon(idOrAddon);}
/**
* Toggles if a particular addon is enabled.
* @param {string} idOrFile Addon id or filename.
* @param {string} idOrFile Addon ID or filename
*/
toggle(idOrAddon) {return this.#manager.toggleAddon(idOrAddon);}
/**
* Reloads if a particular addon is enabled.
* @param {string} idOrFile Addon id or filename.
* @param {string} idOrFile Addon ID or filename
*/
reload(idOrFileOrAddon) {return this.#manager.reloadAddon(idOrFileOrAddon);}
/**
* Gets a particular addon.
* @param {string} idOrFile Addon id or filename.
* @param {string} idOrFile Addon ID or filename
* @returns {object} Addon instance
*/
get(idOrFile) {return this.#manager.getAddon(idOrFile);}

View File

@ -153,9 +153,9 @@ class ContextMenu {
/**
* Allows you to patch a given context menu. Acts as a wrapper around the `Patcher`.
*
* @param {string} navId Discord's internal navId used to identify context menus
* @param {function} callback callback function that accepts the react render tree
* @returns {function} a function that automatically unpatches
* @param {string} navId Discord's internal `navId` used to identify context menus
* @param {function} callback Callback function that accepts the React render tree
* @returns {function} A function that automatically unpatches
*/
patch(navId, callback) {
MenuPatcher.patch(navId, callback);
@ -166,8 +166,8 @@ class ContextMenu {
/**
* Allows you to remove the patch added to a given context menu.
*
* @param {string} navId the original navId from patching
* @param {function} callback the original callback from patching
* @param {string} navId The original `navId` from patching
* @param {function} callback The original callback from patching
*/
unpatch(navId, callback) {
MenuPatcher.unpatch(navId, callback);
@ -178,9 +178,9 @@ class ContextMenu {
* 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.
*
* @param {object} props - props used to build the item
* @param {string} [props.type="text"] - type of the item, options: text, submenu, toggle, radio, custom, separator
* @returns {object} the created component
* @param {object} props Props used to build the item
* @param {string} [props.type="text"] Type of the item, options: text, submenu, toggle, radio, custom, separator
* @returns {object} The created component
*
* @example
* // Creates a single menu item that prints "MENU ITEM" on click
@ -237,8 +237,9 @@ class ContextMenu {
* 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.
* @param {Array<object>} setup - array of item props used to build items. See {@link ContextMenu.buildItem}
* @returns {Array<object>} array of the created component
*
* @param {Array<object>} setup Array of item props used to build items. See {@link ContextMenu.buildItem}.
* @returns {Array<object>} Array of the created component
*
* @example
* // Creates a single item group item with a toggle item
@ -292,8 +293,9 @@ class ContextMenu {
* Creates the menu *component* including the wrapping `ContextMenu`.
* Calls {@link ContextMenu.buildMenuChildren} under the covers.
* Used to call in combination with {@link ContextMenu.open}.
* @param {Array<object>} setup - array of item props used to build items. See {@link ContextMenu.buildMenuChildren}
* @returns {function} the unique context menu component
*
* @param {Array<object>} setup Array of item props used to build items. See {@link ContextMenu.buildMenuChildren}.
* @returns {function} The unique context menu component
*/
buildMenu(setup) {
return (props) => {return React.createElement(MenuComponents.Menu, props, this.buildMenuChildren(setup));};
@ -302,13 +304,12 @@ class ContextMenu {
/**
* Function that allows you to open an entire context menu. Recommended to build the menu with this module.
*
* @param {MouseEvent} event - The context menu event. This can be emulated, requires target, and all X, Y locations.
* @param {function} menuComponent - Component to render. This can be any react component or output of {@link ContextMenu.buildMenu}
* @param {object} config - configuration/props for the context menu
* @param {string} [config.position="right"] - default position for the menu, options: "left", "right"
* @param {string} [config.align="top"] - default alignment for the menu, options: "bottom", "top"
* @param {function} [config.onClose] - function to run when the menu is closed
* @param {boolean} [config.noBlurEvent=false] - No clue
* @param {MouseEvent} event The context menu event. This can be emulated, requires target, and all X, Y locations.
* @param {function} menuComponent Component to render. This can be any React component or output of {@link ContextMenu.buildMenu}.
* @param {object} config Configuration/props for the context menu
* @param {string} [config.position="right"] Default position for the menu, options: "left", "right"
* @param {string} [config.align="top"] Default alignment for the menu, options: "bottom", "top"
* @param {function} [config.onClose] Function to run when the menu is closed
*/
open(event, menuComponent, config) {
return ContextMenuActions.openContextMenu(event, function(e) {

View File

@ -47,10 +47,10 @@ class Data {
}
/**
* Deletes a piece of stored data, this is different than saving as null or undefined.
* Deletes a piece of stored data. This is different than saving `null` or `undefined`.
*
* @param {string} pluginName Name of the plugin deleting data
* @param {string} key Which piece of data to delete
* @param {string} key Which piece of data to delete.
*/
delete(pluginName, key) {
if (this.#callerName) {

View File

@ -49,7 +49,7 @@ class DOM {
/**
* Removes a `<style>` from the document corresponding to the given ID.
*
* @param {string} id ID uses for the style element
* @param {string} id ID used for the style element
*/
removeStyle(id) {
if (this.#callerName && arguments.length === 1) {
@ -66,18 +66,19 @@ class DOM {
* Adds a listener for when the node is removed from the document body.
*
* @param {HTMLElement} node Node to be observed
* @param {function} callback Function to run when fired
* @param {function} callback Function to run when removed
*/
onRemoved(node, callback) {
return DOMManager.onRemoved(node, callback);
}
/**
* Utility to help smoothly animate using JavaScript
* Utility to help smoothly animate using JavaScript.
*
* @param {function} update render function indicating the style should be updates
* @param {number} duration duration in ms to animate for
* @param {object} [options] option to customize the animation
* @param {function} update Render function indicating the style should be updated
* @param {number} duration Duration in ms to animate for
* @param {object} [options] Options to customize the animation
* @param {function} [options.timing] Optional function calculating progress based on current time fraction. Linear by default.
*/
animate(update, duration, options = {}) {
return DOMManager.animate({update, duration, timing: options.timing});
@ -88,12 +89,12 @@ class DOM {
* to `React.createElement`
*
* @param {string} tag HTML tag name to create
* @param {object} [options] options object to customize the element
* @param {string} [options.className] class name to add to the element
* @param {string} [options.id] id to set for the element
* @param {HTMLElement} [options.target] target element to automatically append to
* @param {HTMLElement} [child] child node to add
* @returns HTMLElement
* @param {object} [options] Options object to customize the element
* @param {string} [options.className] Class name to add to the element
* @param {string} [options.id] ID to set for the element
* @param {HTMLElement} [options.target] Target element to automatically append to
* @param {HTMLElement} [child] Child node to add
* @returns {HTMLElement} The created HTML element
*/
createElement(tag, options = {}, child = null) {
return DOMManager.createElement(tag, options, child);
@ -106,9 +107,10 @@ class DOM {
*
* 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.
* @param {string} html - HTML to be parsed
* @param {boolean} [fragment=false] - Whether or not the return should be the raw `DocumentFragment`
* @returns {(DocumentFragment|NodeList|HTMLElement)} - The result of HTML parsing
*
* @param {string} html HTML to be parsed
* @param {boolean} [fragment=false] Whether or not the return should be the raw `DocumentFragment`
* @returns {(DocumentFragment|NodeList|HTMLElement)} The result of HTML parsing
*/
parseHTML(html, fragment = false) {
return DOMManager.parseHTML(html, fragment);

View File

@ -117,7 +117,7 @@ BdApi.Utils = Utils;
BdApi.DOM = DOMAPI;
/**
* An instance of {@link ContextMenu} for interacting with context menus
* An instance of {@link ContextMenu} for interacting with context menus.
* @type ContextMenu
*/
BdApi.ContextMenu = ContextMenuAPI;

View File

@ -100,8 +100,8 @@ function unlinkJS(id) {
* Shows a generic but very customizable modal.
*
* @deprecated
* @param {string} title title of the modal
* @param {(string|ReactElement|Array<string|ReactElement>)} content a string of text to display in the modal
* @param {string} title Title of the modal
* @param {(string|ReactElement|Array<string|ReactElement>)} content A string of text to display in the modal
* @memberof BdApi
*/
function alert(title, content) {
@ -112,14 +112,15 @@ function alert(title, content) {
* Shows a generic but very customizable confirmation modal with optional confirm and cancel callbacks.
*
* @deprecated
* @param {string} title title of the modal
* @param {(string|ReactElement|Array<string|ReactElement>)} children a single or mixed array of react elements and strings. Everything is wrapped in Discord's `TextElement` component so strings will show and render properly.
* @param {object} [options] options to modify the modal
* @param {boolean} [options.danger=false] whether the main button should be red or not
* @param {string} [options.confirmText=Okay] text for the confirmation/submit button
* @param {string} [options.cancelText=Cancel] text for the cancel button
* @param {callable} [options.onConfirm=NOOP] callback to occur when clicking the submit button
* @param {callable} [options.onCancel=NOOP] callback to occur when clicking the cancel button
* @param {string} title Title of the modal
* @param {(string|ReactElement|Array<string|ReactElement>)} children Single or mixed array of React elements and strings. Everything is wrapped in Discord's `TextElement` component so strings will show and render properly.
* @param {object} [options] Options to modify the modal
* @param {boolean} [options.danger=false] Whether the main button should be red or not
* @param {string} [options.confirmText=Okay] Text for the confirmation/submit button
* @param {string} [options.cancelText=Cancel] Text for the cancel button
* @param {callable} [options.onConfirm=NOOP] Callback to occur when clicking the submit button
* @param {callable} [options.onCancel=NOOP] Callback to occur when clicking the cancel button
* @returns {string} The key used for this modal
* @memberof BdApi
*/
function showConfirmationModal(title, content, options = {}) {
@ -130,12 +131,12 @@ function showConfirmationModal(title, content, options = {}) {
* Shows a toast similar to android towards the bottom of the screen.
*
* @deprecated
* @param {string} content The string to show in the toast.
* @param {object} options Options object. Optional parameter.
* @param {string} [options.type=""] Changes the type of the toast stylistically and semantically. Choices: "", "info", "success", "danger"/"error", "warning"/"warn". Default: ""
* @param {boolean} [options.icon=true] Determines whether the icon should show corresponding to the type. A toast without type will always have no icon. Default: `true`
* @param {number} [options.timeout=3000] Adjusts the time (in ms) the toast should be shown for before disappearing automatically. Default: `3000`
* @param {boolean} [options.forceShow=false] Whether to force showing the toast and ignore the bd setting
* @param {string} content The string to show in the toast
* @param {object} options Options object. Optional parameter
* @param {string} [options.type=""] Changes the type of the toast stylistically and semantically. Choices: "", "info", "success", "danger"/"error", "warning"/"warn". Default: "".
* @param {boolean} [options.icon=true] Determines whether the icon should show corresponding to the type. A toast without type will always have no icon. Default: `true`.
* @param {number} [options.timeout=3000] Adjusts the time (in ms) the toast should be shown for before disappearing automatically. Default: `3000`.
* @param {boolean} [options.forceShow=false] Whether to force showing the toast and ignore the BD setting
* @memberof BdApi
*/
function showToast(content, options = {}) {
@ -147,10 +148,10 @@ function showToast(content, options = {}) {
*
* @deprecated
* @param {string|Node} content Content of the notice
* @param {object} options Options for the notice.
* @param {object} options Options for the notice
* @param {string} [options.type="info" | "error" | "warning" | "success"] Type for the notice. Will affect the color.
* @param {Array<{label: string, onClick: function}>} [options.buttons] Buttons that should be added next to the notice text.
* @param {number} [options.timeout=10000] Timeout until the notice is closed. Won't fire if it's set to 0;
* @param {Array<{label: string, onClick: function}>} [options.buttons] Buttons that should be added next to the notice text
* @param {number} [options.timeout=10000] Timeout until the notice is closed. Will not fire when set to `0`.
* @returns {function} A callback for closing the notice. Passing `true` as first parameter closes immediately without transitioning out.
* @memberof BdApi
*/
@ -159,7 +160,7 @@ function showToast(content, options = {}) {
}
/**
* Finds a webpack module using a filter
* Finds a webpack module using a filter.
*
* @deprecated
* @param {function} filter A filter given the exports, module, and moduleId. Returns `true` if the module matches.
@ -171,7 +172,7 @@ function findModule(filter) {
}
/**
* Finds multiple webpack modules using a filter
* Finds multiple webpack modules using a filter.
*
* @deprecated
* @param {function} filter A filter given the exports, module, and moduleId. Returns `true` if the module matches.
@ -208,7 +209,7 @@ function findModuleByPrototypes(...protos) {
}
/**
* Finds a webpack module by `displayName` property
* Finds a webpack module by `displayName` property.
*
* @deprecated
* @param {string} name Desired `displayName` property
@ -220,11 +221,11 @@ function findModuleByDisplayName(name) {
}
/**
* Get the internal react data of a specified node.
* Gets the internal React data of a specified node.
*
* @deprecated
* @param {HTMLElement} node Node to get the react data from
* @returns {object|undefined} Either the found data or `undefined`
* @param {HTMLElement} node Node to get the internal React data from.
* @returns {object|undefined} Either the found data or `undefined`
* @memberof BdApi
*/
function getInternalInstance(node) {
@ -259,7 +260,7 @@ function saveData(pluginName, key, data) {
}
/**
* Deletes a piece of stored data, this is different than saving as null or undefined.
* Deletes a piece of stored data. This is different than saving `null` or `undefined`.
*
* @deprecated
* @param {string} pluginName Name of the plugin deleting data
@ -278,13 +279,13 @@ function deleteData(pluginName, key) {
*
* @deprecated
* @param {object} what Object to be patched. You can can also pass class prototypes to patch all class instances.
* @param {string} methodName Name of the function to be patched.
* @param {object} options Options object to configure the patch.
* @param {string} methodName Name of the function to be patched
* @param {object} options Options object to configure the patch
* @param {function} [options.after] Callback that will be called after original target method call. You can modify return value here, so it will be passed to external code which calls target method. Can be combined with `before`.
* @param {function} [options.before] Callback that will be called before original target method call. You can modify arguments here, so it will be passed to original method. Can be combined with `after`.
* @param {function} [options.instead] Callback that will be called instead of original target method call. You can get access to original method using `originalMethod` parameter if you want to call it, but you do not have to. Can't be combined with `before` or `after`.
* @param {boolean} [options.once=false] Set to `true` if you want to automatically unpatch method after first call.
* @param {boolean} [options.silent=false] Set to `true` if you want to suppress log messages about patching and unpatching.
* @param {boolean} [options.once=false] Set to `true` if you want to automatically unpatch method after first call
* @param {boolean} [options.silent=false] Set to `true` if you want to suppress log messages about patching and unpatching
* @returns {function} A function that cancels the monkey patch
* @memberof BdApi
*/
@ -318,7 +319,7 @@ function monkeyPatch(what, methodName, options) {
*
* @deprecated
* @param {HTMLElement} node Node to be observed
* @param {function} callback Function to run when fired
* @param {function} callback Function to run when removed
* @memberof BdApi
*/
function onRemoved(node, callback) {
@ -330,7 +331,7 @@ function onRemoved(node, callback) {
*
* @deprecated
* @param {function} method Function to wrap
* @param {string} message Additional messasge to print when an error occurs
* @param {string} message Additional message to print when an error occurs
* @returns {function} The new wrapped function
* @memberof BdApi
*/
@ -373,7 +374,7 @@ function isSettingEnabled(collection, category, id) {
}
/**
* Enables a BetterDiscord setting by ids.
* Enables a BetterDiscord setting by IDs.
*
* @deprecated
* @param {string} [collection="settings"] Collection ID
@ -386,7 +387,7 @@ function enableSetting(collection, category, id) {
}
/**
* Disables a BetterDiscord setting by ids.
* Disables a BetterDiscord setting by IDs.
*
* @deprecated
* @param {string} [collection="settings"] Collection ID
@ -399,7 +400,7 @@ function disableSetting(collection, category, id) {
}
/**
* Toggles a BetterDiscord setting by ids.
* Toggles a BetterDiscord setting by IDs.
*
* @deprecated
* @param {string} [collection="settings"] Collection ID
@ -415,7 +416,7 @@ function toggleSetting(collection, category, id) {
* Gets some data in BetterDiscord's misc data.
*
* @deprecated
* @param {string} key Key of the data to load.
* @param {string} key Key of the data to load
* @returns {any} The stored data
* @memberof BdApi
*/
@ -427,7 +428,7 @@ function getBDData(key) {
* Sets some data in BetterDiscord's misc data.
*
* @deprecated
* @param {string} key Key of the data to store.
* @param {string} key Key of the data to store
* @returns {any} The stored data
* @memberof BdApi
*/
@ -440,19 +441,19 @@ function setBDData(key, data) {
* Returns a `Promise` that resolves to an `object` that has a `boolean` cancelled and a `filePath` string for saving and a `filePaths` string array for opening.
*
* @deprecated
* @param {object} options Options object to configure the dialog.
* @param {"open"|"save"} [options.mode="open"] Determines whether the dialog should open or save files.
* @param {string} [options.defaultPath=~] Path the dialog should show on launch.
* @param {Array<object<string, string[]>>} [options.filters=[]] An array of [file filters](https://www.electronjs.org/docs/latest/api/structures/file-filter).
* @param {string} [options.title] Title for the titlebar.
* @param {string} [options.message] Message for the dialog.
* @param {boolean} [options.showOverwriteConfirmation=false] Whether the user should be prompted when overwriting a file.
* @param {boolean} [options.showHiddenFiles=false] Whether hidden files should be shown in the dialog.
* @param {boolean} [options.promptToCreate=false] Whether the user should be prompted to create non-existant folders.
* @param {boolean} [options.openDirectory=false] Whether the user should be able to select a directory as a target.
* @param {boolean} [options.openFile=true] Whether the user should be able to select a file as a target.
* @param {boolean} [options.multiSelections=false] Whether the user should be able to select multiple targets.
* @param {boolean} [options.modal=false] Whether the dialog should act as a modal to the main window.
* @param {object} options Options object to configure the dialog
* @param {"open"|"save"} [options.mode="open"] Determines whether the dialog should open or save files
* @param {string} [options.defaultPath=~] Path the dialog should show on launch
* @param {Array<object<string, string[]>>} [options.filters=[]] An array of [file filters](https://www.electronjs.org/docs/latest/api/structures/file-filter)
* @param {string} [options.title] Title for the titlebar
* @param {string} [options.message] Message for the dialog
* @param {boolean} [options.showOverwriteConfirmation=false] Whether the user should be prompted when overwriting a file
* @param {boolean} [options.showHiddenFiles=false] Whether hidden files should be shown in the dialog
* @param {boolean} [options.promptToCreate=false] Whether the user should be prompted to create non-existant folders
* @param {boolean} [options.openDirectory=false] Whether the user should be able to select a directory as a target
* @param {boolean} [options.openFile=true] Whether the user should be able to select a file as a target
* @param {boolean} [options.multiSelections=false] Whether the user should be able to select multiple targets
* @param {boolean} [options.modal=false] Whether the dialog should act as a modal to the main window
* @returns {Promise<object>} Result of the dialog
* @memberof BdApi
*/

View File

@ -19,11 +19,12 @@ class Patcher {
/**
* This method patches onto another function, allowing your code to run beforehand.
* Using this, you are also able to modify the incoming arguments before the original method is run.
* @param {string} caller Name of the caller of the patch function.
*
* @param {string} caller Name of the caller of the patch function
* @param {object} moduleToPatch Object with the function to be patched. Can also be an object's prototype.
* @param {string} functionName Name of the function to be patched.
* @param {string} functionName Name of the function to be patched
* @param {function} callback Function to run before the original method. The function is given the `this` context and the `arguments` of the original function.
* @returns {function} Function that cancels the original patch.
* @returns {function} Function that cancels the original patch
*/
before(caller, moduleToPatch, functionName, callback) {
if (this.#callerName) {
@ -38,11 +39,12 @@ class Patcher {
/**
* This method patches onto another function, allowing your code to run instead.
* Using this, you are able to replace the original completely. You can still call the original manually if needed.
* @param {string} caller Name of the caller of the patch function.
*
* @param {string} caller Name of the caller of the patch function
* @param {object} moduleToPatch Object with the function to be patched. Can also be an object's prototype.
* @param {string} functionName Name of the function to be patched.
* @param {string} functionName Name of the function to be patched
* @param {function} callback Function to run before the original method. The function is given the `this` context, `arguments` of the original function, and also the original function.
* @returns {function} Function that cancels the original patch.
* @returns {function} Function that cancels the original patch
*/
instead(caller, moduleToPatch, functionName, callback) {
if (this.#callerName) {
@ -57,11 +59,12 @@ class Patcher {
/**
* This method patches onto another function, allowing your code to run afterwards.
* Using this, you are able to modify the return value after the original method is run.
* @param {string} caller Name of the caller of the patch function.
*
* @param {string} caller Name of the caller of the patch function
* @param {object} moduleToPatch Object with the function to be patched. Can also be an object's prototype.
* @param {string} functionName Name of the function to be patched.
* @param {string} functionName Name of the function to be patched
* @param {function} callback Function to run after the original method. The function is given the `this` context, the `arguments` of the original function, and the `return` value of the original function.
* @returns {function} Function that cancels the original patch.
* @returns {function} Function that cancels the original patch
*/
after(caller, moduleToPatch, functionName, callback) {
if (this.#callerName) {
@ -75,8 +78,9 @@ class Patcher {
/**
* Returns all patches by a particular caller. The patches all have an `unpatch()` method.
*
* @param {string} caller ID of the original patches
* @returns {Array<function>} Array of all the patch objects.
* @returns {Array<function>} Array of all the patch objects
*/
getPatchesByCaller(caller) {
if (this.#callerName) caller = this.#callerName;
@ -86,6 +90,7 @@ class Patcher {
/**
* Automatically cancels all patches created with a specific ID.
*
* @param {string} caller ID of the original patches
*/
unpatchAll(caller) {

View File

@ -12,9 +12,9 @@ const ReactUtils = {
get rootInstance() {return document.getElementById("app-mount")?._reactRootContainer?._internalRoot?.current;},
/**
* Gets the internal react data of a specified node
* Gets the internal React data of a specified node.
*
* @param {HTMLElement} node Node to get the react data from
* @param {HTMLElement} node Node to get the internal React data from
* @returns {object|undefined} Either the found data or `undefined`
*/
getInternalInstance(node) {
@ -24,13 +24,14 @@ const ReactUtils = {
/**
* Attempts to find the "owner" node to the current node. This is generally
* a node with a stateNode--a class component.
* @param {HTMLElement} node - node to obtain react instance of
* @param {object} options - options for the search
* @param {array} [options.include] - list of items to include from the search
* @param {array} [options.exclude=["Popout", "Tooltip", "Scroller", "BackgroundFlash"]] - list of items to exclude from the search
* @param {callable} [options.filter=_=>_] - filter to check the current instance with (should return a boolean)
* @return {(*|null)} the owner instance or undefined if not found.
* a node with a `stateNode` - a class component.
*
* @param {HTMLElement} node Node to obtain React instance of
* @param {object} options Options for the search
* @param {array} [options.include] List of items to include in the search
* @param {array} [options.exclude=["Popout", "Tooltip", "Scroller", "BackgroundFlash"]] List of items to exclude from the search.
* @param {callable} [options.filter=_=>_] Filter to check the current instance with (should return a boolean)
* @return {object|undefined} The owner instance or `undefined` if not found
*/
getOwnerInstance(node, {include, exclude = ["Popout", "Tooltip", "Scroller", "BackgroundFlash"], filter = _ => _} = {}) {
if (node === undefined) return undefined;
@ -57,9 +58,10 @@ const ReactUtils = {
},
/**
* Creates an unrendered react component that wraps dom elements.
* @param {HTMLElement} element - element or array of elements to wrap into a react component
* @returns {object} - unrendered react component
* Creates an unrendered React component that wraps HTML elements.
*
* @param {HTMLElement} element Element or array of elements to wrap
* @returns {object} Unrendered React component
*/
wrapElement(element) {
return class ReactWrapper extends DiscordModules.React.Component {

View File

@ -5,18 +5,17 @@ import Tooltip from "../../ui/tooltip";
import ipc from "../ipc";
/**
* `UI` is a utility class for getting internal webpack modules. Instance is accessible through the {@link BdApi}.
* This is extremely useful for interacting with the internals of Discord.
* `UI` is a utility class for creating user interfaces. Instance is accessible through the {@link BdApi}.
* @type UI
* @summary {@link UI} is a utility class for getting internal webpack modules.
* @summary {@link UI} is a utility class for creating user interfaces.
* @name UI
*/
const UI = {
/**
* Shows a generic but very customizable modal.
*
* @param {string} title title of the modal
* @param {(string|ReactElement|Array<string|ReactElement>)} content a string of text to display in the modal
* @param {string} title Title of the modal
* @param {(string|ReactElement|Array<string|ReactElement>)} content A string of text to display in the modal
*/
alert(title, content) {
Modals.alert(title, content);
@ -25,14 +24,14 @@ const UI = {
/**
* Creates a tooltip to automatically show on hover.
*
* @param {HTMLElement} node - DOM node to monitor and show the tooltip on
* @param {string|HTMLElement} content - string to show in the tooltip
* @param {object} options - additional options for the tooltip
* @param {"primary"|"info"|"success"|"warn"|"danger"} [options.style="primary"] - correlates to the discord styling/colors
* @param {"top"|"right"|"bottom"|"left"} [options.side="top"] - can be any of top, right, bottom, left
* @param {boolean} [options.preventFlip=false] - prevents moving the tooltip to the opposite side if it is too big or goes offscreen
* @param {boolean} [options.disabled=false] - whether the tooltip should be disabled from showing on hover
* @returns {Tooltip} the tooltip that was generated
* @param {HTMLElement} node DOM node to monitor and show the tooltip on
* @param {string|HTMLElement} content String to show in the tooltip
* @param {object} options Additional options for the tooltip
* @param {"primary"|"info"|"success"|"warn"|"danger"} [options.style="primary"] Correlates to the Discord styling/colors
* @param {"top"|"right"|"bottom"|"left"} [options.side="top"] Can be any of top, right, bottom, left
* @param {boolean} [options.preventFlip=false] Prevents moving the tooltip to the opposite side if it is too big or goes offscreen
* @param {boolean} [options.disabled=false] Whether the tooltip should be disabled from showing on hover
* @returns {Tooltip} The tooltip that was generated.
*/
createTooltip(node, content, options = {}) {
return Tooltip.create(node, content, options);
@ -41,14 +40,15 @@ const UI = {
/**
* Shows a generic but very customizable confirmation modal with optional confirm and cancel callbacks.
*
* @param {string} title title of the modal
* @param {(string|ReactElement|Array<string|ReactElement>)} children a single or mixed array of react elements and strings. Everything is wrapped in Discord's `TextElement` component so strings will show and render properly.
* @param {object} [options] options to modify the modal
* @param {boolean} [options.danger=false] whether the main button should be red or not
* @param {string} [options.confirmText=Okay] text for the confirmation/submit button
* @param {string} [options.cancelText=Cancel] text for the cancel button
* @param {callable} [options.onConfirm=NOOP] callback to occur when clicking the submit button
* @param {callable} [options.onCancel=NOOP] callback to occur when clicking the cancel button
* @param {string} title Title of the modal.
* @param {(string|ReactElement|Array<string|ReactElement>)} children Single or mixed array of React elements and strings. Everything is wrapped in Discord's `TextElement` component so strings will show and render properly.
* @param {object} [options] Options to modify the modal
* @param {boolean} [options.danger=false] Whether the main button should be red or not
* @param {string} [options.confirmText=Okay] Text for the confirmation/submit button
* @param {string} [options.cancelText=Cancel] Text for the cancel button
* @param {callable} [options.onConfirm=NOOP] Callback to occur when clicking the submit button
* @param {callable} [options.onCancel=NOOP] Callback to occur when clicking the cancel button
* @returns {string} The key used for this modal.
*/
showConfirmationModal(title, content, options = {}) {
return Modals.showConfirmationModal(title, content, options);
@ -57,12 +57,12 @@ const UI = {
/**
* This shows a toast similar to android towards the bottom of the screen.
*
* @param {string} content The string to show in the toast.
* @param {object} options Options object. Optional parameter.
* @param {string} [options.type=""] Changes the type of the toast stylistically and semantically. Choices: "", "info", "success", "danger"/"error", "warning"/"warn". Default: ""
* @param {boolean} [options.icon=true] Determines whether the icon should show corresponding to the type. A toast without type will always have no icon. Default: `true`
* @param {number} [options.timeout=3000] Adjusts the time (in ms) the toast should be shown for before disappearing automatically. Default: `3000`
* @param {boolean} [options.forceShow=false] Whether to force showing the toast and ignore the bd setting
* @param {string} content The string to show in the toast
* @param {object} options Options for the toast
* @param {string} [options.type=""] Changes the type of the toast stylistically and semantically. Choices: "", "info", "success", "danger"/"error", "warning"/"warn". Default: "".
* @param {boolean} [options.icon=true] Determines whether the icon should show corresponding to the type. A toast without type will always have no icon. Default: `true`.
* @param {number} [options.timeout=3000] Adjusts the time (in ms) the toast should be shown for before disappearing automatically. Default: `3000`.
* @param {boolean} [options.forceShow=false] Whether to force showing the toast and ignore the BD setting
*/
showToast(content, options = {}) {
Toasts.show(content, options);
@ -72,11 +72,11 @@ const UI = {
* Shows a notice above Discord's chat layer.
*
* @param {string|Node} content Content of the notice
* @param {object} options Options for the notice.
* @param {object} options Options for the notice
* @param {string} [options.type="info" | "error" | "warning" | "success"] Type for the notice. Will affect the color.
* @param {Array<{label: string, onClick: function}>} [options.buttons] Buttons that should be added next to the notice text.
* @param {number} [options.timeout=10000] Timeout until the notice is closed. Won't fire if it's set to 0;
* @returns {function}
* @param {Array<{label: string, onClick: function}>} [options.buttons] Buttons that should be added next to the notice text
* @param {number} [options.timeout=10000] Timeout until the notice is closed. Will not fire when set to `0`.
* @returns {function} A callback for closing the notice. Passing `true` as first parameter closes immediately without transitioning out.
*/
showNotice(content, options = {}) {
return Notices.show(content, options);
@ -86,19 +86,19 @@ const UI = {
* Gives access to the [Electron Dialog](https://www.electronjs.org/docs/latest/api/dialog/) api.
* Returns a `Promise` that resolves to an `object` that has a `boolean` cancelled and a `filePath` string for saving and a `filePaths` string array for opening.
*
* @param {object} options Options object to configure the dialog.
* @param {"open"|"save"} [options.mode="open"] Determines whether the dialog should open or save files.
* @param {string} [options.defaultPath=~] Path the dialog should show on launch.
* @param {Array<object<string, string[]>>} [options.filters=[]] An array of [file filters](https://www.electronjs.org/docs/latest/api/structures/file-filter).
* @param {string} [options.title] Title for the titlebar.
* @param {string} [options.message] Message for the dialog.
* @param {boolean} [options.showOverwriteConfirmation=false] Whether the user should be prompted when overwriting a file.
* @param {boolean} [options.showHiddenFiles=false] Whether hidden files should be shown in the dialog.
* @param {boolean} [options.promptToCreate=false] Whether the user should be prompted to create non-existant folders.
* @param {boolean} [options.openDirectory=false] Whether the user should be able to select a directory as a target.
* @param {boolean} [options.openFile=true] Whether the user should be able to select a file as a target.
* @param {boolean} [options.multiSelections=false] Whether the user should be able to select multiple targets.
* @param {boolean} [options.modal=false] Whether the dialog should act as a modal to the main window.
* @param {object} options Options object to configure the dialog
* @param {"open"|"save"} [options.mode="open"] Determines whether the dialog should open or save files
* @param {string} [options.defaultPath=~] Path the dialog should show on launch
* @param {Array<object<string, string[]>>} [options.filters=[]] An array of [file filters](https://www.electronjs.org/docs/latest/api/structures/file-filter)
* @param {string} [options.title] Title for the titlebar
* @param {string} [options.message] Message for the dialog
* @param {boolean} [options.showOverwriteConfirmation=false] Whether the user should be prompted when overwriting a file
* @param {boolean} [options.showHiddenFiles=false] Whether hidden files should be shown in the dialog
* @param {boolean} [options.promptToCreate=false] Whether the user should be prompted to create non-existent folders
* @param {boolean} [options.openDirectory=false] Whether the user should be able to select a directory as a target
* @param {boolean} [options.openFile=true] Whether the user should be able to select a file as a target
* @param {boolean} [options.multiSelections=false] Whether the user should be able to select multiple targets
* @param {boolean} [options.modal=false] Whether the dialog should act as a modal to the main window
* @returns {Promise<object>} Result of the dialog
*/
async openDialog(options) {

View File

@ -9,11 +9,12 @@ import Utilities from "../utilities";
const Utils = {
/**
* Finds a value, subobject, or array from a tree that matches a specific filter. This is a DFS.
*
* @param {object} tree Tree that should be walked
* @param {callable} searchFilter Filter to check against each object and subobject
* @param {object} options Additional options to customize the search
* @param {Array<string>|null} [options.walkable=null] Array of strings to use as keys that are allowed to be walked on. Null value indicates all keys are walkable
* @param {Array<string>} [options.ignore=[]] Array of strings to use as keys to exclude from the search, most helpful when `walkable = null`.
* @param {Array<string>|null} [options.walkable=null] Array of strings to use as keys that are allowed to be walked on. `null` indicates all keys are walkable.
* @param {Array<string>} [options.ignore=[]] Array of strings to use as keys to exclude from the search. Most helpful when `walkable = null`.
*/
findInTree(tree, searchFilter, options = {}) {
return Utilities.findInTree(tree, searchFilter, options);
@ -24,9 +25,10 @@ const Utils = {
* of `extenders` have priority, that is to say if one sets a key to be a primitive,
* it will be overwritten with the next one with the same key. If it is an object,
* and the keys match, the object is extended. This happens recursively.
* @param {object} extendee - Object to be extended
* @param {...object} extenders - Objects to extend with
* @returns {object} - A reference to `extendee`
*
* @param {object} extendee Object to be extended
* @param {...object} extenders Objects to extend with
* @returns {object} A reference to `extendee`
*/
extend(extendee, ...extenders) {
return Utilities.extend(extendee, ...extenders);
@ -35,20 +37,23 @@ const Utils = {
/**
* Returns a function, that, as long as it continues to be invoked, will not
* be triggered. The function will be called after it stops being called for
* N milliseconds.
* `delay` milliseconds. It is called at the end of the sequence (trailing edge).
*
* Adapted from the version by David Walsh (https://davidwalsh.name/javascript-debounce-function)
*
* @param {function} executor
* @param {number} delay
* @param {function} executor The function to be debounced
* @param {number} delay Number of ms to delay calls
* @return {function} A debounced version of the function
*/
debounce(executor, delay) {
return Utilities.debounce(executor, delay);
},
/**
* Takes a string of html and escapes it using the brower's own escaping mechanism.
* @param {String} html - html to be escaped
* Takes a string of HTML and escapes it using the browser's own escaping mechanism.
*
* @param {string} html HTML to be escaped
* @return {string} Escaped HTML string
*/
escapeHTML(html) {
return Utilities.escapeHTML(html);
@ -59,7 +64,9 @@ const Utils = {
* When given an array all values from the array are added to the list.
* When given an object they keys are added as the classnames if the value is truthy.
* Copyright (c) 2018 Jed Watson https://github.com/JedWatson/classnames MIT License
* @param {...Any} argument - anything that should be used to add classnames.
*
* @param {...any} argument Anything that should be used to add classnames
* @returns {string} Joined classname
*/
className() {
return Utilities.className(...arguments);

View File

@ -40,7 +40,7 @@ const Webpack = {
/**
* Generates a function that filters by strings.
* @param {...String} strings A list of strings
* @param {...string} strings A list of strings
* @returns {function} A filter that checks for a set of strings
*/
byStrings(...strings) {return Filters.byStrings(...strings);},
@ -65,9 +65,9 @@ const Webpack = {
* @memberof Webpack
* @param {function} filter A function to use to filter modules. It is given exports, module, and moduleID. Return `true` to signify match.
* @param {object} [options] Options to configure the search
* @param {Boolean} [options.first=true] Whether to return only the first matching module
* @param {Boolean} [options.defaultExport=true] Whether to return default export when matching the default export
* @param {Boolean} [options.searchExports=false] Whether to execute the filter on webpack exports
* @param {boolean} [options.first=true] Whether to return only the first matching module
* @param {boolean} [options.defaultExport=true] Whether to return default export when matching the default export
* @param {boolean} [options.searchExports=false] Whether to execute the filter on webpack exports
* @return {any}
*/
getModule(filter, options = {}) {
@ -81,10 +81,10 @@ const Webpack = {
* Finds multiple modules using multiple filters.
* @memberof Webpack
* @param {...object} queries Object representing the query to perform
* @param {Function} queries.filter A function to use to filter modules
* @param {Boolean} [queries.first=true] Whether to return only the first matching module
* @param {Boolean} [queries.defaultExport=true] Whether to return default export when matching the default export
* @param {Boolean} [queries.searchExports=false] Whether to execute the filter on webpack exports
* @param {function} queries.filter A function to use to filter modules
* @param {boolean} [queries.first=true] Whether to return only the first matching module
* @param {boolean} [queries.defaultExport=true] Whether to return default export when matching the default export
* @param {boolean} [queries.searchExports=false] Whether to execute the filter on webpack exports
* @return {any}
*/
getBulk(...queries) {return WebpackModules.getBulk(...queries);},
@ -95,8 +95,8 @@ const Webpack = {
* @param {function} filter A function to use to filter modules. It is given exports. Return `true` to signify match.
* @param {object} [options] Options for configuring the listener
* @param {AbortSignal} [options.signal] AbortSignal of an AbortController to cancel the promise
* @param {Boolean} [options.defaultExport=true] Whether to return default export when matching the default export
* @param {Boolean} [options.searchExports=false] Whether to execute the filter on webpack exports
* @param {boolean} [options.defaultExport=true] Whether to return default export when matching the default export
* @param {boolean} [options.searchExports=false] Whether to execute the filter on webpack exports
* @returns {Promise<any>}
*/
waitForModule(filter, options = {}) {