Doc fixes & consistency
This commit is contained in:
parent
07d626b8ee
commit
feca69e875
|
@ -14,46 +14,46 @@
|
|||
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);}
|
||||
|
||||
/**
|
||||
* Gets all addons of this type.
|
||||
* @returns {Array<object>} Array of all addon instances
|
||||
* @returns {Array<object>} Array of all addon instances.
|
||||
*/
|
||||
getAll() {return this.#manager.addonList.map(a => this.#manager.getAddon(a.id));}
|
||||
}
|
||||
|
|
|
@ -175,9 +175,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);
|
||||
|
@ -188,8 +188,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);
|
||||
|
@ -200,9 +200,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
|
||||
|
@ -259,8 +259,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
|
||||
|
@ -314,8 +315,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));};
|
||||
|
@ -325,12 +327,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 {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.
|
||||
*/
|
||||
open(event, menuComponent, config) {
|
||||
return ContextMenuActions.openContextMenu(event, function(e) {
|
||||
|
|
|
@ -18,9 +18,9 @@ class Data {
|
|||
/**
|
||||
* Saves JSON-serializable data.
|
||||
*
|
||||
* @param {string} pluginName Name of the plugin saving data
|
||||
* @param {string} key Which piece of data to store
|
||||
* @param {any} data The data to be saved
|
||||
* @param {string} pluginName Name of the plugin saving data.
|
||||
* @param {string} key Which piece of data to store.
|
||||
* @param {any} data The data to be saved.
|
||||
*/
|
||||
save(pluginName, key, data) {
|
||||
if (this.#callerName) {
|
||||
|
@ -34,9 +34,9 @@ class Data {
|
|||
/**
|
||||
* Loads previously stored data.
|
||||
*
|
||||
* @param {string} pluginName Name of the plugin loading data
|
||||
* @param {string} key Which piece of data to load
|
||||
* @returns {any} The stored data
|
||||
* @param {string} pluginName Name of the plugin loading data.
|
||||
* @param {string} key Which piece of data to load.
|
||||
* @returns {any} The stored data.
|
||||
*/
|
||||
load(pluginName, key) {
|
||||
if (this.#callerName) {
|
||||
|
@ -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} pluginName Name of the plugin deleting data.
|
||||
* @param {string} key Which piece of data to delete.
|
||||
*/
|
||||
delete(pluginName, key) {
|
||||
if (this.#callerName) {
|
||||
|
|
|
@ -30,8 +30,8 @@ class DOM {
|
|||
/**
|
||||
* Adds a `<style>` to the document with the given ID.
|
||||
*
|
||||
* @param {string} id ID to use for style element
|
||||
* @param {string} css CSS to apply to the document
|
||||
* @param {string} id ID to use for style element.
|
||||
* @param {string} css CSS to apply to the document.
|
||||
*/
|
||||
addStyle(id, css) {
|
||||
if (this.#callerName && arguments.length === 2) {
|
||||
|
@ -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) {
|
||||
|
@ -65,19 +65,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 {HTMLElement} node Node to be observed.
|
||||
* @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.
|
||||
*/
|
||||
animate(update, duration, options = {}) {
|
||||
return DOMManager.animate({update, duration, timing: options.timing});
|
||||
|
@ -87,12 +87,12 @@ class DOM {
|
|||
* Utility function to make creating DOM elements easier. Acts similarly
|
||||
* 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
|
||||
* @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
|
||||
*/
|
||||
createElement(tag, options = {}, child = null) {
|
||||
|
@ -106,9 +106,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);
|
||||
|
|
|
@ -113,7 +113,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;
|
||||
|
|
|
@ -53,8 +53,8 @@ const version = Config.version;
|
|||
* Adds a `<style>` to the document with the given ID.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} id ID to use for style element
|
||||
* @param {string} css CSS to apply to the document
|
||||
* @param {string} id ID to use for style element.
|
||||
* @param {string} css CSS to apply to the document.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function injectCSS(id, css) {
|
||||
|
@ -65,7 +65,7 @@ function injectCSS(id, css) {
|
|||
* Removes a `<style>` from the document corresponding to the given ID.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} id ID uses for the style element
|
||||
* @param {string} id ID uses for the style element.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function clearCSS(id) {
|
||||
|
@ -76,9 +76,9 @@ function clearCSS(id) {
|
|||
* Automatically creates and links a remote JS script.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} id ID of the script element
|
||||
* @param {string} url URL of the remote script
|
||||
* @returns {Promise} Resolves upon onload event
|
||||
* @param {string} id ID of the script element.
|
||||
* @param {string} url URL of the remote script.
|
||||
* @returns {Promise} Resolves upon onload event.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function linkJS(id, url) {
|
||||
|
@ -89,7 +89,7 @@ function linkJS(id, url) {
|
|||
* Removes a remotely linked JS script.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} id ID of the script element
|
||||
* @param {string} id ID of the script element.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function unlinkJS(id) {
|
||||
|
@ -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,14 @@ 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.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function showConfirmationModal(title, content, options = {}) {
|
||||
|
@ -132,10 +132,10 @@ function showConfirmationModal(title, content, options = {}) {
|
|||
* @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} [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 = {}) {
|
||||
|
@ -150,7 +150,7 @@ function showToast(content, options = {}) {
|
|||
* @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 {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,11 +159,11 @@ 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.
|
||||
* @returns {any} Either the matching module or `undefined`
|
||||
* @returns {any} Either the matching module or `undefined`.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function findModule(filter) {
|
||||
|
@ -171,11 +171,11 @@ 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.
|
||||
* @returns {Array} Either an array of matching modules or an empty array
|
||||
* @returns {Array} Either an array of matching modules or an empty array.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function findAllModules(filter) {
|
||||
|
@ -186,8 +186,8 @@ function findAllModules(filter) {
|
|||
* Finds a webpack module by own properties.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {...string} props Any desired properties
|
||||
* @returns {any} Either the matching module or `undefined`
|
||||
* @param {...string} props Any desired properties.
|
||||
* @returns {any} Either the matching module or `undefined`.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function findModuleByProps(...props) {
|
||||
|
@ -199,8 +199,8 @@ function findModuleByProps(...props) {
|
|||
* Finds a webpack module by own prototypes.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {...string} protos Any desired prototype properties
|
||||
* @returns {any} Either the matching module or `undefined`
|
||||
* @param {...string} protos Any desired prototype properties.
|
||||
* @returns {any} Either the matching module or `undefined`.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function findModuleByPrototypes(...protos) {
|
||||
|
@ -208,11 +208,11 @@ function findModuleByPrototypes(...protos) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Finds a webpack module by `displayName` property
|
||||
* Finds a webpack module by `displayName` property.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} name Desired `displayName` property
|
||||
* @returns {any} Either the matching module or `undefined`
|
||||
* @param {string} name Desired `displayName` property.
|
||||
* @returns {any} Either the matching module or `undefined`.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function findModuleByDisplayName(name) {
|
||||
|
@ -220,11 +220,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) {
|
||||
|
@ -236,9 +236,9 @@ function getInternalInstance(node) {
|
|||
* Loads previously stored data.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} pluginName Name of the plugin loading data
|
||||
* @param {string} key Which piece of data to load
|
||||
* @returns {any} The stored data
|
||||
* @param {string} pluginName Name of the plugin loading data.
|
||||
* @param {string} key Which piece of data to load.
|
||||
* @returns {any} The stored data.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function loadData(pluginName, key) {
|
||||
|
@ -249,9 +249,9 @@ function loadData(pluginName, key) {
|
|||
* Saves JSON-serializable data.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} pluginName Name of the plugin saving data
|
||||
* @param {string} key Which piece of data to store
|
||||
* @param {any} data The data to be saved
|
||||
* @param {string} pluginName Name of the plugin saving data.
|
||||
* @param {string} key Which piece of data to store.
|
||||
* @param {any} data The data to be saved.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function saveData(pluginName, key, data) {
|
||||
|
@ -259,11 +259,11 @@ 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
|
||||
* @param {string} key Which piece of data to delete
|
||||
* @param {string} pluginName Name of the plugin deleting data.
|
||||
* @param {string} key Which piece of data to delete.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function deleteData(pluginName, key) {
|
||||
|
@ -285,7 +285,7 @@ function deleteData(pluginName, key) {
|
|||
* @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.
|
||||
* @returns {function} A function that cancels the monkey patch
|
||||
* @returns {function} A function that cancels the monkey patch.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function monkeyPatch(what, methodName, options) {
|
||||
|
@ -317,8 +317,8 @@ function monkeyPatch(what, methodName, options) {
|
|||
* Adds a listener for when the node is removed from the document body.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {HTMLElement} node Node to be observed
|
||||
* @param {function} callback Function to run when fired
|
||||
* @param {HTMLElement} node Node to be observed.
|
||||
* @param {function} callback Function to run when removed.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function onRemoved(node, callback) {
|
||||
|
@ -329,9 +329,9 @@ function onRemoved(node, callback) {
|
|||
* Wraps a given function in a `try..catch` block.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {function} method Function to wrap
|
||||
* @param {string} message Additional messasge to print when an error occurs
|
||||
* @returns {function} The new wrapped function
|
||||
* @param {function} method Function to wrap.
|
||||
* @param {string} message Additional message to print when an error occurs.
|
||||
* @returns {function} The new wrapped function.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function suppressErrors(method, message) {
|
||||
|
@ -345,8 +345,8 @@ function suppressErrors(method, message) {
|
|||
* Tests a given object to determine if it is valid JSON.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {object} data Data to be tested
|
||||
* @returns {boolean} Result of the test
|
||||
* @param {object} data Data to be tested.
|
||||
* @returns {boolean} Result of the test.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function testJSON(data) {
|
||||
|
@ -362,10 +362,10 @@ function testJSON(data) {
|
|||
* Gets a specific setting's status from BD.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} [collection="settings"] Collection ID
|
||||
* @param {string} category Category ID in the collection
|
||||
* @param {string} id Setting ID in the category
|
||||
* @returns {boolean} If the setting is enabled
|
||||
* @param {string} [collection="settings"] Collection ID.
|
||||
* @param {string} category Category ID in the collection.
|
||||
* @param {string} id Setting ID in the category.
|
||||
* @returns {boolean} If the setting is enabled.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function isSettingEnabled(collection, category, id) {
|
||||
|
@ -373,12 +373,12 @@ function isSettingEnabled(collection, category, id) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enables a BetterDiscord setting by ids.
|
||||
* Enables a BetterDiscord setting by IDs.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} [collection="settings"] Collection ID
|
||||
* @param {string} category Category ID in the collection
|
||||
* @param {string} id Setting ID in the category
|
||||
* @param {string} [collection="settings"] Collection ID.
|
||||
* @param {string} category Category ID in the collection.
|
||||
* @param {string} id Setting ID in the category.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function enableSetting(collection, category, id) {
|
||||
|
@ -386,12 +386,12 @@ function enableSetting(collection, category, id) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Disables a BetterDiscord setting by ids.
|
||||
* Disables a BetterDiscord setting by IDs.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} [collection="settings"] Collection ID
|
||||
* @param {string} category Category ID in the collection
|
||||
* @param {string} id Setting ID in the category
|
||||
* @param {string} [collection="settings"] Collection ID.
|
||||
* @param {string} category Category ID in the collection.
|
||||
* @param {string} id Setting ID in the category.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function disableSetting(collection, category, id) {
|
||||
|
@ -399,12 +399,12 @@ function disableSetting(collection, category, id) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Toggles a BetterDiscord setting by ids.
|
||||
* Toggles a BetterDiscord setting by IDs.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {string} [collection="settings"] Collection ID
|
||||
* @param {string} category Category ID in the collection
|
||||
* @param {string} id Setting ID in the category
|
||||
* @param {string} [collection="settings"] Collection ID.
|
||||
* @param {string} category Category ID in the collection.
|
||||
* @param {string} id Setting ID in the category.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function toggleSetting(collection, category, id) {
|
||||
|
@ -416,7 +416,7 @@ function toggleSetting(collection, category, id) {
|
|||
*
|
||||
* @deprecated
|
||||
* @param {string} key Key of the data to load.
|
||||
* @returns {any} The stored data
|
||||
* @returns {any} The stored data.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function getBDData(key) {
|
||||
|
@ -428,7 +428,7 @@ function getBDData(key) {
|
|||
*
|
||||
* @deprecated
|
||||
* @param {string} key Key of the data to store.
|
||||
* @returns {any} The stored data
|
||||
* @returns {any} The stored data.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
function setBDData(key, data) {
|
||||
|
@ -453,7 +453,7 @@ function setBDData(key, data) {
|
|||
* @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
|
||||
* @returns {Promise<object>} Result of the dialog.
|
||||
* @memberof BdApi
|
||||
*/
|
||||
async function openDialog(options) {
|
||||
|
|
|
@ -19,6 +19,7 @@ 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 {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.
|
||||
|
@ -38,6 +39,7 @@ 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 {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.
|
||||
|
@ -57,6 +59,7 @@ 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 {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.
|
||||
|
@ -75,7 +78,8 @@ class Patcher {
|
|||
|
||||
/**
|
||||
* Returns all patches by a particular caller. The patches all have an `unpatch()` method.
|
||||
* @param {string} caller ID of the original patches
|
||||
*
|
||||
* @param {string} caller ID of the original patches.
|
||||
* @returns {Array<function>} Array of all the patch objects.
|
||||
*/
|
||||
getPatchesByCaller(caller) {
|
||||
|
@ -86,7 +90,8 @@ class Patcher {
|
|||
|
||||
/**
|
||||
* Automatically cancels all patches created with a specific ID.
|
||||
* @param {string} caller ID of the original patches
|
||||
*
|
||||
* @param {string} caller ID of the original patches.
|
||||
*/
|
||||
unpatchAll(caller) {
|
||||
if (this.#callerName) caller = this.#callerName;
|
||||
|
|
|
@ -12,10 +12,10 @@ 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
|
||||
* @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` .
|
||||
*/
|
||||
getInternalInstance(node) {
|
||||
if (node.__reactFiber$) return node.__reactFiber$;
|
||||
|
@ -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 {(*|null)} 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,9 @@ 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 {
|
||||
|
|
|
@ -15,8 +15,8 @@ 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 +25,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 +41,14 @@ 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.
|
||||
*/
|
||||
showConfirmationModal(title, content, options = {}) {
|
||||
return Modals.showConfirmationModal(title, content, options);
|
||||
|
@ -59,10 +59,10 @@ const UI = {
|
|||
*
|
||||
* @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} [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);
|
||||
|
@ -71,11 +71,11 @@ const UI = {
|
|||
/**
|
||||
* Shows a notice above Discord's chat layer.
|
||||
*
|
||||
* @param {string|Node} content Content of the notice
|
||||
* @param {string|Node} content Content of 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 {number} [options.timeout=10000] Timeout until the notice is closed. Will not fire when set to `0`.
|
||||
* @returns {function}
|
||||
*/
|
||||
showNotice(content, options = {}) {
|
||||
|
@ -99,7 +99,7 @@ const UI = {
|
|||
* @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
|
||||
* @returns {Promise<object>} Result of the dialog.
|
||||
*/
|
||||
async openDialog(options) {
|
||||
const data = await ipc.openDialog(options);
|
||||
|
|
|
@ -9,10 +9,11 @@ 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 {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`.
|
||||
*/
|
||||
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);
|
||||
|
@ -47,8 +49,8 @@ const Utils = {
|
|||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
escapeHTML(html) {
|
||||
return Utilities.escapeHTML(html);
|
||||
|
@ -59,6 +61,7 @@ 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.
|
||||
*/
|
||||
className() {
|
||||
|
|
Loading…
Reference in New Issue