Fix various api issues
This commit is contained in:
parent
c0543586cb
commit
7959260f29
|
@ -89,8 +89,8 @@ class MenuPatcher {
|
||||||
|
|
||||||
if (!res) return res;
|
if (!res) return res;
|
||||||
|
|
||||||
if (res.props?.navId) {
|
if (res.props?.navId ?? res.props?.children?.props?.navId) {
|
||||||
MenuPatcher.runPatches(res.props.navId, res, arguments[0]);
|
MenuPatcher.runPatches(res.props.navId ?? res.props?.children?.props?.navId, res, arguments[0]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const layer = res.props.children ? res.props.children : res;
|
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}.
|
* `ContextMenu` is a module to help patch and create context menus. Instance is accessible through the {@link BdApi}.
|
||||||
* @type ContextMenu
|
* @type ContextMenu
|
||||||
|
@ -212,6 +213,17 @@ class ContextMenu {
|
||||||
if (props.danger) props.color = "colorDanger";
|
if (props.danger) props.color = "colorDanger";
|
||||||
if (props.onClick && !props.action) props.action = props.onClick;
|
if (props.onClick && !props.action) props.action = props.onClick;
|
||||||
props.extended = true;
|
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);
|
return React.createElement(Component, props);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,8 @@ class DOM {
|
||||||
*/
|
*/
|
||||||
addStyle(id, css) {
|
addStyle(id, css) {
|
||||||
if (this.#callerName && arguments.length === 2) {
|
if (this.#callerName && arguments.length === 2) {
|
||||||
id = arguments[1];
|
id = arguments[0];
|
||||||
css = arguments[2];
|
css = arguments[1];
|
||||||
}
|
}
|
||||||
else if (this.#callerName) {
|
else if (this.#callerName) {
|
||||||
css = id;
|
css = id;
|
||||||
|
@ -53,7 +53,7 @@ class DOM {
|
||||||
*/
|
*/
|
||||||
removeStyle(id) {
|
removeStyle(id) {
|
||||||
if (this.#callerName && arguments.length === 1) {
|
if (this.#callerName && arguments.length === 1) {
|
||||||
id = arguments[1];
|
id = arguments[0];
|
||||||
}
|
}
|
||||||
else if (this.#callerName) {
|
else if (this.#callerName) {
|
||||||
id = this.#callerName;
|
id = this.#callerName;
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Patcher {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method patches onto another function, allowing your code to run instead.
|
* 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 {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 {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.
|
||||||
|
@ -55,8 +55,8 @@ class Patcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method patches onto another function, allowing your code to run instead.
|
* This method patches onto another function, allowing your code to run afterwards.
|
||||||
* Using this, you are also able to modify the return value, using the return of your code instead.
|
* 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 {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.
|
||||||
|
|
|
@ -47,7 +47,7 @@ const ReactUtils = {
|
||||||
return (name !== null && !!(nameFilter.includes(name) ^ excluding));
|
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) {
|
for (curr = curr && curr.return; !Utilities.isNil(curr); curr = curr.return) {
|
||||||
if (Utilities.isNil(curr)) continue;
|
if (Utilities.isNil(curr)) continue;
|
||||||
const owner = curr.stateNode;
|
const owner = curr.stateNode;
|
||||||
|
|
Loading…
Reference in New Issue