Skip to content

Commit

Permalink
core-ext/contextMenu: fix patches
Browse files Browse the repository at this point in the history
Co-Authored-By: [email protected]
  • Loading branch information
adryd325 committed Sep 30, 2024
1 parent 474c7ea commit b73b2d7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 53 deletions.
3 changes: 1 addition & 2 deletions packages/core-extensions/src/contextMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export const patches: Patch[] = [
find: "Menu API only allows Items and groups of Items as children.",
replace: [
{
match:
/(?<=let{navId[^}]+?}=(.),(.)=function .\(.\){.+(?=,.=function))/,
match: /(?<=let{navId[^}]+?}=(.),(.)=.\(.\))/,
replacement: (_, props, items) =>
`,__contextMenu=!${props}.__contextMenu_evilMenu&&require("contextMenu_contextMenu")._patchMenu(${props}, ${items})`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ let code =
"Menu API only allows Items and groups of Items as children."
)[0].id
].toString();
code = code.replace(/,.=(?=function .\(.\){.+?,.=function)/, ";return ");
code = code.replace(/,(?=__contextMenu)/, ";let ");
code = code.replace(
/onSelect:(.)}=(.),.=(.\(.\)),/,
`onSelect:$1}=$2;return $3;let `
);
const mod = new Function(
"module",
"exports",
Expand All @@ -16,10 +18,7 @@ const mod = new Function(
);
const exp: any = {};
mod({}, exp, require);
const Menu = spacepack.findFunctionByStrings(
exp,
"Menu API only allows Items and groups of Items as children."
)!;
const Menu = spacepack.findFunctionByStrings(exp, "isUsingKeyboardNavigation")!;
module.exports = (el: any) => {
return Menu({
children: el,
Expand Down
100 changes: 55 additions & 45 deletions packages/types/src/coreExtensions/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,49 @@ export type MenuGroup = React.FunctionComponent<{
color?: string;
children: React.ReactComponentElement<MenuElement>[];
}>;
export type MenuItem = React.FunctionComponent<{
id: any;
dontCloseOnActionIfHoldingShiftKey?: boolean;
} & ({
label: string;
subtext?: string;
color?: string;
hint?: string;
disabled?: boolean;
icon?: any;
showIconFirst?: boolean;
imageUrl?: string;
export type MenuItem = React.FunctionComponent<
{
id: any;
dontCloseOnActionIfHoldingShiftKey?: boolean;
} & (
| {
label: string;
subtext?: string;
color?: string;
hint?: string;
disabled?: boolean;
icon?: any;
showIconFirst?: boolean;
imageUrl?: string;

className?: string;
focusedClassName?: string;
subMenuIconClassName?: string;
className?: string;
focusedClassName?: string;
subMenuIconClassName?: string;

action?: () => void;
onFocus?: () => void;
action?: () => void;
onFocus?: () => void;

iconProps?: any;
sparkle?: any;
iconProps?: any;
sparkle?: any;

children?: React.ReactComponentElement<MenuElement>[];
onChildrenScroll?: any;
childRowHeight?: any;
listClassName?: string;
subMenuClassName?: string;
} | {
color?: string;
disabled?: boolean;
keepItemStyles?: boolean;
children?: React.ReactComponentElement<MenuElement>[];
onChildrenScroll?: any;
childRowHeight?: any;
listClassName?: string;
subMenuClassName?: string;
}
| {
color?: string;
disabled?: boolean;
keepItemStyles?: boolean;

action?: () => void;
action?: () => void;

render: any;
navigable?: boolean;
})>;
render: any;
navigable?: boolean;
}
)
>;
export type MenuCheckboxItem = React.FunctionComponent<{
id: any;
label: string;
Expand All @@ -84,19 +89,24 @@ export type MenuRadioItem = React.FunctionComponent<{
disabled?: boolean;
action?: () => void;
}>;
export type MenuControlItem = React.FunctionComponent<{
id: any;
label: string;
color?: string;
disabled?: boolean;
showDefaultFocus?: boolean;
} & ({
control: any;
} | {
control?: undefined;
interactive?: boolean;
children?: React.ReactComponentElement<MenuElement>[];
})>;
export type MenuControlItem = React.FunctionComponent<
{
id: any;
label: string;
color?: string;
disabled?: boolean;
showDefaultFocus?: boolean;
} & (
| {
control: any;
}
| {
control?: undefined;
interactive?: boolean;
children?: React.ReactComponentElement<MenuElement>[];
}
)
>;
/* eslint-disable prettier/prettier */

export type ContextMenu = {
Expand Down

0 comments on commit b73b2d7

Please sign in to comment.