1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-25 08:46:25 +00:00
This commit is contained in:
Nuckyz 2024-09-18 14:43:27 -03:00
parent a493d56487
commit 5dbe81e459
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
11 changed files with 33 additions and 43 deletions

View file

@ -17,7 +17,6 @@
*/ */
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { ComponentType, HTMLProps } from "react";
import Plugins from "~plugins"; import Plugins from "~plugins";
@ -30,7 +29,7 @@ export interface ProfileBadge {
/** The tooltip to show on hover. Required for image badges */ /** The tooltip to show on hover. Required for image badges */
description?: string; description?: string;
/** Custom component for the badge (tooltip not included) */ /** Custom component for the badge (tooltip not included) */
component?: ComponentType<ProfileBadge & BadgeUserArgs>; component?: React.ComponentType<ProfileBadge & BadgeUserArgs>;
/** The custom image to use */ /** The custom image to use */
image?: string; image?: string;
link?: string; link?: string;
@ -39,7 +38,7 @@ export interface ProfileBadge {
/** Should the user display this badge? */ /** Should the user display this badge? */
shouldShow?(userInfo: BadgeUserArgs): boolean; shouldShow?(userInfo: BadgeUserArgs): boolean;
/** Optional props (e.g. style) for the badge, ignored for component badges */ /** Optional props (e.g. style) for the badge, ignored for component badges */
props?: HTMLProps<HTMLImageElement>; props?: React.ComponentPropsWithoutRef<"img">;
/** Insert at start or end? */ /** Insert at start or end? */
position?: BadgePosition; position?: BadgePosition;
/** The badge name to display, Discord uses this. Required for component badges */ /** The badge name to display, Discord uses this. Required for component badges */

View file

@ -19,18 +19,17 @@
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import { Channel, Message } from "discord-types/general"; import { Channel, Message } from "discord-types/general";
import type { ComponentType, MouseEventHandler } from "react";
const logger = new Logger("MessagePopover"); const logger = new Logger("MessagePopover");
export interface ButtonItem { export interface ButtonItem {
key?: string, key?: string,
label: string, label: string,
icon: ComponentType<any>, icon: React.ComponentType<AnyRecord>,
message: Message, message: Message,
channel: Channel, channel: Channel,
onClick?: MouseEventHandler<HTMLButtonElement>, onClick?: React.MouseEventHandler<HTMLButtonElement>,
onContextMenu?: MouseEventHandler<HTMLButtonElement>; onContextMenu?: React.MouseEventHandler<HTMLButtonElement>;
} }
export type getButtonItem = (message: Message) => ButtonItem | null; export type getButtonItem = (message: Message) => ButtonItem | null;

View file

@ -8,13 +8,12 @@ import "./quickActions.css";
import { classNameFactory } from "@api/Styles"; import { classNameFactory } from "@api/Styles";
import { Card } from "@webpack/common"; import { Card } from "@webpack/common";
import type { ComponentType, PropsWithChildren, ReactNode } from "react";
const cl = classNameFactory("vc-settings-quickActions-"); const cl = classNameFactory("vc-settings-quickActions-");
export interface QuickActionProps { export interface QuickActionProps {
Icon: ComponentType<{ className?: string; }>; Icon: React.ComponentType<{ className?: string; }>;
text: ReactNode; text: React.ReactNode;
action?: () => void; action?: () => void;
disabled?: boolean; disabled?: boolean;
} }
@ -30,7 +29,7 @@ export function QuickAction(props: QuickActionProps) {
); );
} }
export function QuickActionCard(props: PropsWithChildren) { export function QuickActionCard(props: React.PropsWithChildren) {
return ( return (
<Card className={cl("card")}> <Card className={cl("card")}>
{props.children} {props.children}

View file

@ -24,9 +24,8 @@ import { handleComponentFailed } from "@components/handleComponentFailed";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import { onlyOnce } from "@utils/onlyOnce"; import { onlyOnce } from "@utils/onlyOnce";
import { Forms, Text } from "@webpack/common"; import { Forms, Text } from "@webpack/common";
import type { ComponentType, PropsWithChildren } from "react";
export function SettingsTab({ title, children }: PropsWithChildren<{ title: string; }>) { export function SettingsTab({ title, children }: React.PropsWithChildren<{ title: string; }>) {
return ( return (
<Forms.FormSection> <Forms.FormSection>
<Text <Text
@ -44,7 +43,7 @@ export function SettingsTab({ title, children }: PropsWithChildren<{ title: stri
export const handleSettingsTabError = onlyOnce(handleComponentFailed); export const handleSettingsTabError = onlyOnce(handleComponentFailed);
export function wrapTab(component: ComponentType<any>, tab: string) { export function wrapTab(component: React.ComponentType<AnyRecord>, tab: string) {
return ErrorBoundary.wrap(component, { return ErrorBoundary.wrap(component, {
message: `Failed to render the ${tab} tab. If this issue persists, try using the installer to reinstall!`, message: `Failed to render the ${tab} tab. If this issue persists, try using the installer to reinstall!`,
onError: handleSettingsTabError, onError: handleSettingsTabError,

4
src/globals.d.ts vendored
View file

@ -20,8 +20,8 @@ import { LoDashStatic } from "lodash";
declare global { declare global {
type AnyRecord = Record<PropertyKey, any>; type AnyRecord = Record<PropertyKey, any>;
type AnyComponentType<P extends AnyRecord> = React.ComponentType<P & AnyRecord> & AnyRecord; type AnyComponentType<P extends AnyRecord = AnyRecord> = React.ComponentType<P & AnyRecord> & AnyRecord;
type AnyComponentTypeWithChildren<P extends AnyRecord> = React.ComponentType<React.PropsWithChildren<P> & AnyRecord> & AnyRecord; type AnyComponentTypeWithChildren<P extends AnyRecord = AnyRecord> = React.ComponentType<React.PropsWithChildren<P> & AnyRecord> & AnyRecord;
/** /**
* This exists only at build time, so references to it in patches should insert it * This exists only at build time, so references to it in patches should insert it

View file

@ -28,7 +28,6 @@ import * as Webpack from "@webpack";
import { cacheFindAll, cacheFindModuleId, extract, filters, searchFactories } from "@webpack"; import { cacheFindAll, cacheFindModuleId, extract, filters, searchFactories } from "@webpack";
import * as Common from "@webpack/common"; import * as Common from "@webpack/common";
import { loadLazyChunks } from "debug/loadLazyChunks"; import { loadLazyChunks } from "debug/loadLazyChunks";
import type { ComponentType } from "react";
const DESKTOP_ONLY = (f: string) => () => { const DESKTOP_ONLY = (f: string) => () => {
throw new Error(`'${f}' is Discord Desktop only.`); throw new Error(`'${f}' is Discord Desktop only.`);
@ -129,7 +128,7 @@ function makeShortcuts() {
canonicalizeReplacement, canonicalizeReplacement,
preEnable: (plugin: string) => (Vencord.Settings.plugins[plugin] ??= { enabled: true }).enabled = true, preEnable: (plugin: string) => (Vencord.Settings.plugins[plugin] ??= { enabled: true }).enabled = true,
fakeRender: (component: ComponentType, props: any) => { fakeRender: (component: React.ComponentType<AnyRecord>, props: any) => {
const prevWin = fakeRenderWin?.deref(); const prevWin = fakeRenderWin?.deref();
const win = prevWin?.closed === false const win = prevWin?.closed === false
? prevWin ? prevWin

View file

@ -7,11 +7,10 @@
import { NoopComponent } from "@utils/react"; import { NoopComponent } from "@utils/react";
import { findComponentByCode } from "@webpack"; import { findComponentByCode } from "@webpack";
import { React } from "@webpack/common"; import { React } from "@webpack/common";
import type { ComponentType, HTMLProps, PropsWithChildren } from "react";
import { AvatarDecoration } from "../.."; import { AvatarDecoration } from "../..";
type DecorationGridItemComponent = ComponentType<PropsWithChildren<HTMLProps<HTMLDivElement>> & { type DecorationGridItemComponent = AnyComponentTypeWithChildren<React.ComponentPropsWithoutRef<"div"> & {
onSelect: () => void, onSelect: () => void,
isSelected: boolean, isSelected: boolean,
}>; }>;
@ -21,7 +20,7 @@ export const setDecorationGridItem = v => DecorationGridItem = v;
export const AvatarDecorationModalPreview = findComponentByCode(".shopPreviewBanner", component => React.memo(component)); export const AvatarDecorationModalPreview = findComponentByCode(".shopPreviewBanner", component => React.memo(component));
type DecorationGridDecorationComponent = React.ComponentType<HTMLProps<HTMLDivElement> & { type DecorationGridDecorationComponent = AnyComponentType<React.ComponentPropsWithoutRef<"div"> & {
avatarDecoration: AvatarDecoration; avatarDecoration: AvatarDecoration;
onSelect: () => void, onSelect: () => void,
isSelected: boolean, isSelected: boolean,

View file

@ -23,7 +23,6 @@ import { sleep } from "@utils/misc";
import { Queue } from "@utils/Queue"; import { Queue } from "@utils/Queue";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { Constants, FluxDispatcher, RestAPI, UserProfileStore, UserStore, useState } from "@webpack/common"; import { Constants, FluxDispatcher, RestAPI, UserProfileStore, UserStore, useState } from "@webpack/common";
import { type ComponentType, type ReactNode } from "react";
// LYING to the type checker here // LYING to the type checker here
const UserFlags = Constants.UserFlags as Record<string, number>; const UserFlags = Constants.UserFlags as Record<string, number>;
@ -60,14 +59,14 @@ interface MentionProps {
channelId?: string; channelId?: string;
content: any; content: any;
}; };
parse: (content: any, props: MentionProps["props"]) => ReactNode; parse: (content: any, props: MentionProps["props"]) => React.ReactNode;
props: { props: {
key: string; key: string;
formatInline: boolean; formatInline: boolean;
noStyleAndInteraction: boolean; noStyleAndInteraction: boolean;
}; };
RoleMention: ComponentType<any>; RoleMention: AnyComponentType;
UserMention: ComponentType<any>; UserMention: AnyComponentType;
} }
async function getUser(id: string) { async function getUser(id: string) {

View file

@ -29,7 +29,6 @@ import definePlugin from "@utils/types";
import { chooseFile } from "@utils/web"; import { chooseFile } from "@utils/web";
import { find, findByProps, findStore } from "@webpack"; import { find, findByProps, findStore } from "@webpack";
import { Button, Card, Constants, FluxDispatcher, Forms, lodash, Menu, MessageActions, PermissionsBits, PermissionStore, RestAPI, SelectedChannelStore, showToast, SnowflakeUtils, Toasts, useEffect, useState } from "@webpack/common"; import { Button, Card, Constants, FluxDispatcher, Forms, lodash, Menu, MessageActions, PermissionsBits, PermissionStore, RestAPI, SelectedChannelStore, showToast, SnowflakeUtils, Toasts, useEffect, useState } from "@webpack/common";
import { ComponentType } from "react";
import { VoiceRecorderDesktop } from "./DesktopRecorder"; import { VoiceRecorderDesktop } from "./DesktopRecorder";
import { settings } from "./settings"; import { settings } from "./settings";
@ -41,7 +40,7 @@ const CloudUpload = find(m => m.prototype?.trackUploadFinished);
const PendingReplyStore = findStore("PendingReplyStore"); const PendingReplyStore = findStore("PendingReplyStore");
const OptionClasses = findByProps("optionName", "optionIcon", "optionLabel"); const OptionClasses = findByProps("optionName", "optionIcon", "optionLabel");
export type VoiceRecorder = ComponentType<{ export type VoiceRecorder = AnyComponentType<{
setAudioBlob(blob: Blob): void; setAudioBlob(blob: Blob): void;
onRecordingChange?(recording: boolean): void; onRecordingChange?(recording: boolean): void;
}>; }>;

View file

@ -8,7 +8,7 @@ import { makeLazy } from "./lazy";
export const SYM_LAZY_COMPONENT_INNER = Symbol.for("vencord.lazyComponent.inner"); export const SYM_LAZY_COMPONENT_INNER = Symbol.for("vencord.lazyComponent.inner");
export type LazyComponentType<P extends AnyRecord> = React.FunctionComponent<P> & AnyRecord & { export type LazyComponentType<P extends AnyRecord = AnyRecord> = React.FunctionComponent<P> & AnyRecord & {
[SYM_LAZY_COMPONENT_INNER]: () => AnyComponentType<P> | null; [SYM_LAZY_COMPONENT_INNER]: () => AnyComponentType<P> | null;
}; };

View file

@ -17,7 +17,6 @@
*/ */
import { findByProps, findComponentByCode } from "@webpack"; import { findByProps, findComponentByCode } from "@webpack";
import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react";
import { NoopComponent } from "./react"; import { NoopComponent } from "./react";
@ -47,10 +46,10 @@ export interface ModalOptions {
onCloseCallback?: (() => void); onCloseCallback?: (() => void);
} }
type RenderFunction = (props: ModalProps) => ReactNode; type RenderFunction = (props: ModalProps) => React.ReactNode;
type Modals = { type Modals = {
ModalRoot: ComponentType<PropsWithChildren<{ ModalRoot: AnyComponentTypeWithChildren<{
transitionState: ModalTransitionState; transitionState: ModalTransitionState;
size?: ModalSize; size?: ModalSize;
role?: "alertdialog" | "dialog"; role?: "alertdialog" | "dialog";
@ -59,8 +58,8 @@ type Modals = {
"aria-label"?: string; "aria-label"?: string;
"aria-labelledby"?: string; "aria-labelledby"?: string;
onAnimationEnd?(): string; onAnimationEnd?(): string;
}>>; }>;
ModalHeader: ComponentType<PropsWithChildren<{ ModalHeader: AnyComponentTypeWithChildren<{
/** Flex.Justify.START */ /** Flex.Justify.START */
justify?: string; justify?: string;
/** Flex.Direction.HORIZONTAL */ /** Flex.Direction.HORIZONTAL */
@ -72,14 +71,13 @@ type Modals = {
separator?: boolean; separator?: boolean;
className?: string; className?: string;
}>>; }>;
/** This also accepts Scroller props but good luck with that */ /** This also accepts Scroller props but good luck with that */
ModalContent: ComponentType<PropsWithChildren<{ ModalContent: AnyComponentTypeWithChildren<{
className?: string; className?: string;
scrollerRef?: Ref<HTMLElement>; scrollerRef?: React.Ref<HTMLElement>;
[prop: string]: any; }>;
}>>; ModalFooter: AnyComponentTypeWithChildren<{
ModalFooter: ComponentType<PropsWithChildren<{
/** Flex.Justify.START */ /** Flex.Justify.START */
justify?: string; justify?: string;
/** Flex.Direction.HORIZONTAL_REVERSE */ /** Flex.Direction.HORIZONTAL_REVERSE */
@ -91,8 +89,8 @@ type Modals = {
separator?: boolean; separator?: boolean;
className?: string; className?: string;
}>>; }>;
ModalCloseButton: ComponentType<{ ModalCloseButton: AnyComponentType<{
focusProps?: any; focusProps?: any;
onClick(): void; onClick(): void;
withCircleBackground?: boolean; withCircleBackground?: boolean;
@ -123,8 +121,8 @@ export type ImageModalProps = {
height?: number; height?: number;
animated?: boolean; animated?: boolean;
responsive?: boolean; responsive?: boolean;
renderLinkComponent(props: any): ReactNode; renderLinkComponent(props: any): React.ReactNode;
renderForwardComponent(props: any): ReactNode; renderForwardComponent(props: any): React.ReactNode;
maxWidth?: number; maxWidth?: number;
maxHeight?: number; maxHeight?: number;
shouldAnimate?: boolean; shouldAnimate?: boolean;