Fix various api issues

This commit is contained in:
Zack Rauen 2022-10-13 21:53:41 -04:00
parent c0543586cb
commit 7959260f29
4 changed files with 21 additions and 9 deletions

View File

@ -89,8 +89,8 @@ class MenuPatcher {
if (!res) return res;
if (res.props?.navId) {
MenuPatcher.runPatches(res.props.navId, res, arguments[0]);
if (res.props?.navId ?? res.props?.children?.props?.navId) {
MenuPatcher.runPatches(res.props.navId ?? res.props?.children?.props?.navId, res, arguments[0]);
}
else {
const layer = res.props.children ? res.props.children : res;
@ -136,6 +136,7 @@ class MenuPatcher {
}
}
/**
* `ContextMenu` is a module to help patch and create context menus. Instance is accessible through the {@link BdApi}.
* @type ContextMenu
@ -212,6 +213,17 @@ class ContextMenu {
if (props.danger) props.color = "colorDanger";
if (props.onClick && !props.action) props.action = props.onClick;
props.extended = true;
// This is done to make sure the UI actually displays the on/off correctly
if (type === "toggle") {
const [active, doToggle] = React.useState(props.checked || false);
const originalAction = props.action;
props.checked = active;
props.action = function(ev) {
originalAction(ev);
doToggle(!active);
};
}
return React.createElement(Component, props);
}

View File

@ -35,8 +35,8 @@ class DOM {
*/
addStyle(id, css) {
if (this.#callerName && arguments.length === 2) {
id = arguments[1];
css = arguments[2];
id = arguments[0];
css = arguments[1];
}
else if (this.#callerName) {
css = id;
@ -53,7 +53,7 @@ class DOM {
*/
removeStyle(id) {
if (this.#callerName && arguments.length === 1) {
id = arguments[1];
id = arguments[0];
}
else if (this.#callerName) {
id = this.#callerName;

View File

@ -37,7 +37,7 @@ class Patcher {
/**
* This method patches onto another function, allowing your code to run instead.
* Using this, you are also able to modify the return value, using the return of your code 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.
@ -55,8 +55,8 @@ class Patcher {
}
/**
* This method patches onto another function, allowing your code to run instead.
* Using this, you are also able to modify the return value, using the return of your code instead.
* 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.

View File

@ -47,7 +47,7 @@ const ReactUtils = {
return (name !== null && !!(nameFilter.includes(name) ^ excluding));
}
let curr = ReactUtils.getReactInstance(node);
let curr = ReactUtils.getInternalInstance(node);
for (curr = curr && curr.return; !Utilities.isNil(curr); curr = curr.return) {
if (Utilities.isNil(curr)) continue;
const owner = curr.stateNode;