From b73b2d7ceb97bc9cce88e5395fefa2608635b08f Mon Sep 17 00:00:00 2001 From: adryd Date: Mon, 30 Sep 2024 10:42:12 -0400 Subject: [PATCH] core-ext/contextMenu: fix patches Co-Authored-By: hi@notnite.com --- .../core-extensions/src/contextMenu/index.tsx | 3 +- .../contextMenu/webpackModules/evilMenu.ts | 11 +- .../types/src/coreExtensions/contextMenu.ts | 100 ++++++++++-------- 3 files changed, 61 insertions(+), 53 deletions(-) diff --git a/packages/core-extensions/src/contextMenu/index.tsx b/packages/core-extensions/src/contextMenu/index.tsx index ce6ffe0..89461f8 100644 --- a/packages/core-extensions/src/contextMenu/index.tsx +++ b/packages/core-extensions/src/contextMenu/index.tsx @@ -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})` } diff --git a/packages/core-extensions/src/contextMenu/webpackModules/evilMenu.ts b/packages/core-extensions/src/contextMenu/webpackModules/evilMenu.ts index 4b009f3..2a7f531 100644 --- a/packages/core-extensions/src/contextMenu/webpackModules/evilMenu.ts +++ b/packages/core-extensions/src/contextMenu/webpackModules/evilMenu.ts @@ -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", @@ -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, diff --git a/packages/types/src/coreExtensions/contextMenu.ts b/packages/types/src/coreExtensions/contextMenu.ts index d7f39fa..710909d 100644 --- a/packages/types/src/coreExtensions/contextMenu.ts +++ b/packages/types/src/coreExtensions/contextMenu.ts @@ -27,44 +27,49 @@ export type MenuGroup = React.FunctionComponent<{ color?: string; children: React.ReactComponentElement[]; }>; -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[]; - onChildrenScroll?: any; - childRowHeight?: any; - listClassName?: string; - subMenuClassName?: string; -} | { - color?: string; - disabled?: boolean; - keepItemStyles?: boolean; + children?: React.ReactComponentElement[]; + 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; @@ -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[]; -})>; +export type MenuControlItem = React.FunctionComponent< + { + id: any; + label: string; + color?: string; + disabled?: boolean; + showDefaultFocus?: boolean; + } & ( + | { + control: any; + } + | { + control?: undefined; + interactive?: boolean; + children?: React.ReactComponentElement[]; + } + ) +>; /* eslint-disable prettier/prettier */ export type ContextMenu = {