Skip to content

Commit

Permalink
contextMenu: Use types from mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
NotNite committed Oct 15, 2024
1 parent 92ecda4 commit 03752e9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { InternalItem, MenuElement, MenuProps } from "@moonlight-mod/types/coreExtensions/contextMenu";
import { InternalItem } from "@moonlight-mod/types/coreExtensions/contextMenu";
import { Menu, MenuElement } from "@moonlight-mod/mappings/discord/components/common/index";

Check failure on line 2 in packages/core-extensions/src/contextMenu/webpackModules/contextMenu.ts

View workflow job for this annotation

GitHub Actions / Lint commits

Cannot find module '@moonlight-mod/mappings/discord/components/common/index' or its corresponding type declarations.
import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
import parser from "@moonlight-mod/wp/contextMenu_evilMenu";

type Patch = {
navId: string;
item: (props: any) => React.ReactComponentElement<MenuElement> | React.ReactComponentElement<MenuElement>[];
item: (props: any) => MenuElement | MenuElement[];
anchorId: string;
before: boolean;
};

function addItem<T>(
navId: string,
item: (props: T) => React.ReactComponentElement<MenuElement> | React.ReactComponentElement<MenuElement>[],
anchorId: string,
before = false
) {
function addItem<T>(navId: string, item: (props: T) => MenuElement | MenuElement[], anchorId: string, before = false) {
patches.push({ navId, item, anchorId, before });
}

const patches: Patch[] = [];
function _patchMenu(props: MenuProps, items: InternalItem[]) {
function _patchMenu(props: React.ComponentProps<Menu>, items: InternalItem[]) {
const matches = patches.filter((p) => p.navId === props.navId);
if (!matches.length) return;

Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@moonlight-mod/lunast": "^1.0.0",
"@moonlight-mod/mappings": "^1.0.4",
"@moonlight-mod/mappings": "^1.0.5",
"@moonlight-mod/moonmap": "^1.0.3",
"@types/react": "^18.3.10",
"csstype": "^3.1.2",
Expand Down
122 changes: 11 additions & 111 deletions packages/types/src/coreExtensions/contextMenu.ts
Original file line number Diff line number Diff line change
@@ -1,113 +1,15 @@
// TODO: Deduplicate common props

export type Menu = React.FunctionComponent<{
navId: string;
variant?: string;
hideScrollbar?: boolean;
className?: string;
children: React.ReactComponentElement<MenuElement>[];
onClose?: () => void;
onSelect?: () => void;
}>;
export type MenuProps = React.ComponentProps<Menu>;

export type MenuElement = MenuSeparator | MenuGroup | MenuItem | MenuCheckboxItem | MenuRadioItem | MenuControlItem;

export type MenuSeparator = React.FunctionComponent;
export type MenuGroup = React.FunctionComponent<{
label?: string;
className?: string;
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;

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

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

iconProps?: any;
sparkle?: any;

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

action?: () => void;

render: any;
navigable?: boolean;
}
)
>;
export type MenuCheckboxItem = React.FunctionComponent<{
id: any;
label: string;
subtext?: string;
color?: string;
className?: string;
focusedClassName?: string;
disabled?: boolean;
checked: boolean;
action?: () => void;
}>;
export type MenuRadioItem = React.FunctionComponent<{
id: any;
label: string;
subtext?: string;
color?: string;
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>[];
}
)
>;
import {
MenuCheckboxItem,
MenuControlItem,
MenuGroup,
MenuRadioItem,
MenuSeparator,
MenuItem,
MenuElement
} from "@moonlight-mod/mappings/discord/components/common/index";

export type ContextMenu = {
addItem: (
navId: string,
item: (props: any) => React.ReactComponentElement<MenuElement>,
anchorId: string,
before?: boolean
) => void;
addItem: (navId: string, item: (props: any) => MenuElement, anchorId: string, before?: boolean) => void;

MenuCheckboxItem: MenuCheckboxItem;
MenuControlItem: MenuControlItem;
Expand Down Expand Up @@ -149,6 +51,4 @@ export type InternalItem_ = {
label: string;
};

export type EvilItemParser = (
el: React.ReactComponentElement<MenuElement> | React.ReactComponentElement<MenuElement>[]
) => InternalItem[];
export type EvilItemParser = (el: MenuElement | MenuElement[]) => InternalItem[];
2 changes: 1 addition & 1 deletion packages/web-preload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@moonlight-mod/core": "workspace:*",
"@moonlight-mod/lunast": "^1.0.0",
"@moonlight-mod/mappings": "^1.0.4",
"@moonlight-mod/mappings": "^1.0.5",
"@moonlight-mod/moonmap": "^1.0.3",
"@moonlight-mod/types": "workspace:*"
}
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 03752e9

Please sign in to comment.