|
|
@ -25,14 +25,14 @@ type ContextMenuPatchCallbackReturn = (() => void) | void;
|
|
|
|
* @param args Any arguments passed into making the context menu, like the guild, channel, user or message for example
|
|
|
|
* @param args Any arguments passed into making the context menu, like the guild, channel, user or message for example
|
|
|
|
* @returns A callback which is only ran once used to modify the context menu elements (Use to avoid duplicates)
|
|
|
|
* @returns A callback which is only ran once used to modify the context menu elements (Use to avoid duplicates)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export type NavContextMenuPatchCallback = (children: Array<React.ReactElement>, ...args: Array<any>) => ContextMenuPatchCallbackReturn;
|
|
|
|
export type NavContextMenuPatchCallback = (children: Array<ReactElement | null>, ...args: Array<any>) => ContextMenuPatchCallbackReturn;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param navId The navId of the context menu being patched
|
|
|
|
* @param navId The navId of the context menu being patched
|
|
|
|
* @param children The rendered context menu elements
|
|
|
|
* @param children The rendered context menu elements
|
|
|
|
* @param args Any arguments passed into making the context menu, like the guild, channel, user or message for example
|
|
|
|
* @param args Any arguments passed into making the context menu, like the guild, channel, user or message for example
|
|
|
|
* @returns A callback which is only ran once used to modify the context menu elements (Use to avoid duplicates)
|
|
|
|
* @returns A callback which is only ran once used to modify the context menu elements (Use to avoid duplicates)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export type GlobalContextMenuPatchCallback = (navId: string, children: Array<React.ReactElement>, ...args: Array<any>) => ContextMenuPatchCallbackReturn;
|
|
|
|
export type GlobalContextMenuPatchCallback = (navId: string, children: Array<ReactElement | null>, ...args: Array<any>) => ContextMenuPatchCallbackReturn;
|
|
|
|
|
|
|
|
|
|
|
|
const ContextMenuLogger = new Logger("ContextMenu");
|
|
|
|
const ContextMenuLogger = new Logger("ContextMenu");
|
|
|
|
|
|
|
|
|
|
|
@ -89,15 +89,18 @@ export function removeGlobalContextMenuPatch(patch: GlobalContextMenuPatchCallba
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A helper function for finding the children array of a group nested inside a context menu based on the id of one of its childs
|
|
|
|
* A helper function for finding the children array of a group nested inside a context menu based on the id(s) of its children
|
|
|
|
* @param id The id of the child
|
|
|
|
* @param id The id of the child. If an array is specified, all ids will be tried
|
|
|
|
* @param children The context menu children
|
|
|
|
* @param children The context menu children
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function findGroupChildrenByChildId(id: string, children: Array<React.ReactElement>, _itemsArray?: Array<React.ReactElement>): Array<React.ReactElement> | null {
|
|
|
|
export function findGroupChildrenByChildId(id: string | string[], children: Array<ReactElement | null>, _itemsArray?: Array<ReactElement | null>): Array<ReactElement | null> | null {
|
|
|
|
for (const child of children) {
|
|
|
|
for (const child of children) {
|
|
|
|
if (child == null) continue;
|
|
|
|
if (child == null) continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (child.props?.id === id) return _itemsArray ?? null;
|
|
|
|
if (
|
|
|
|
|
|
|
|
(Array.isArray(id) && id.some(id => child.props?.id === id))
|
|
|
|
|
|
|
|
|| child.props?.id === id
|
|
|
|
|
|
|
|
) return _itemsArray ?? null;
|
|
|
|
|
|
|
|
|
|
|
|
let nextChildren = child.props?.children;
|
|
|
|
let nextChildren = child.props?.children;
|
|
|
|
if (nextChildren) {
|
|
|
|
if (nextChildren) {
|
|
|
@ -117,7 +120,7 @@ export function findGroupChildrenByChildId(id: string, children: Array<React.Rea
|
|
|
|
interface ContextMenuProps {
|
|
|
|
interface ContextMenuProps {
|
|
|
|
contextMenuApiArguments?: Array<any>;
|
|
|
|
contextMenuApiArguments?: Array<any>;
|
|
|
|
navId: string;
|
|
|
|
navId: string;
|
|
|
|
children: Array<ReactElement>;
|
|
|
|
children: Array<ReactElement | null>;
|
|
|
|
"aria-label": string;
|
|
|
|
"aria-label": string;
|
|
|
|
onSelect: (() => void) | undefined;
|
|
|
|
onSelect: (() => void) | undefined;
|
|
|
|
onClose: (callback: (...args: Array<any>) => any) => void;
|
|
|
|
onClose: (callback: (...args: Array<any>) => any) => void;
|
|
|
|