Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
thororen1234 2025-01-29 07:52:55 -05:00
commit 8222eb430e
42 changed files with 450 additions and 289 deletions

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { findByPropsLazy, findModuleId, proxyLazyWebpack, wreq } from "@webpack";
import { filters, findModuleId, mapMangledModuleLazy, proxyLazyWebpack, wreq } from "@webpack";
import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react";
import { LazyComponent } from "./react";
@ -49,7 +49,7 @@ export interface ModalOptions {
type RenderFunction = (props: ModalProps) => ReactNode | Promise<ReactNode>;
export const Modals = findByPropsLazy("ModalRoot", "ModalCloseButton") as {
interface Modals {
ModalRoot: ComponentType<PropsWithChildren<{
transitionState: ModalTransitionState;
size?: ModalSize;
@ -99,7 +99,21 @@ export const Modals = findByPropsLazy("ModalRoot", "ModalCloseButton") as {
hideOnFullscreen?: boolean;
className?: string;
}>;
};
}
const Modals: Modals = mapMangledModuleLazy(':"thin")', {
ModalRoot: filters.componentByCode('.MODAL,"aria-labelledby":'),
ModalHeader: filters.componentByCode(",id:"),
ModalContent: filters.componentByCode(".content,"),
ModalFooter: filters.componentByCode(".footer,"),
ModalCloseButton: filters.componentByCode(".close]:")
});
export const ModalRoot = LazyComponent(() => Modals.ModalRoot);
export const ModalHeader = LazyComponent(() => Modals.ModalHeader);
export const ModalContent = LazyComponent(() => Modals.ModalContent);
export const ModalFooter = LazyComponent(() => Modals.ModalFooter);
export const ModalCloseButton = LazyComponent(() => Modals.ModalCloseButton);
export type MediaModalItem = {
url: string;
@ -135,38 +149,33 @@ export const openMediaModal: (props: MediaModalProps) => void = proxyLazyWebpack
return Object.values<any>(openMediaModalModule).find(v => String(v).includes("modalKey:"));
});
export const ModalRoot = LazyComponent(() => Modals.ModalRoot);
export const ModalHeader = LazyComponent(() => Modals.ModalHeader);
export const ModalContent = LazyComponent(() => Modals.ModalContent);
export const ModalFooter = LazyComponent(() => Modals.ModalFooter);
export const ModalCloseButton = LazyComponent(() => Modals.ModalCloseButton);
interface ModalAPI {
/**
* Wait for the render promise to resolve, then open a modal with it.
* This is equivalent to render().then(openModal)
* You should use the Modal components exported by this file
*/
openModalLazy: (render: () => Promise<RenderFunction>, options?: ModalOptions & { contextKey?: string; }) => Promise<string>;
/**
* Open a Modal with the given render function.
* You should use the Modal components exported by this file
*/
openModal: (render: RenderFunction, options?: ModalOptions, contextKey?: string) => string;
/**
* Close a modal by its key
*/
closeModal: (modalKey: string, contextKey?: string) => void;
/**
* Close all open modals
*/
closeAllModals: () => void;
}
export const ModalAPI = findByPropsLazy("openModalLazy");
/**
* Wait for the render promise to resolve, then open a modal with it.
* This is equivalent to render().then(openModal)
* You should use the Modal components exported by this file
*/
export const openModalLazy: (render: () => Promise<RenderFunction>, options?: ModalOptions & { contextKey?: string; }) => Promise<string>
= proxyLazyWebpack(() => ModalAPI.openModalLazy);
/**
* Open a Modal with the given render function.
* You should use the Modal components exported by this file
*/
export const openModal: (render: RenderFunction, options?: ModalOptions, contextKey?: string) => string
= proxyLazyWebpack(() => ModalAPI.openModal);
/**
* Close a modal by its key
*/
export const closeModal: (modalKey: string, contextKey?: string) => void
= proxyLazyWebpack(() => ModalAPI.closeModal);
/**
* Close all open modals
*/
export const closeAllModals: () => void
= proxyLazyWebpack(() => ModalAPI.closeAllModals);
export const ModalAPI: ModalAPI = mapMangledModuleLazy(".modalKey?", {
openModalLazy: filters.byCode(".modalKey?"),
openModal: filters.byCode(",instant:"),
closeModal: filters.byCode(".onCloseCallback()"),
closeAllModals: filters.byCode(".getState();for")
});
export const { openModalLazy, openModal, closeModal, closeAllModals } = ModalAPI;