move new webpack methods to more appropriate file

This commit is contained in:
V 2023-11-22 07:04:17 +01:00
parent b21b6d7e5d
commit 7b24c8ac69
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
14 changed files with 52 additions and 57 deletions

View file

@ -24,9 +24,8 @@ import { proxyLazy } from "@utils/lazy";
import { Margins } from "@utils/margins";
import { classes, isObjectEmpty } from "@utils/misc";
import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize } from "@utils/modal";
import { findComponentByCodeLazy } from "@utils/react";
import { OptionType, Plugin } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { Button, Clickable, FluxDispatcher, Forms, React, Text, Tooltip, UserStore, UserUtils } from "@webpack/common";
import { User } from "discord-types/general";
import { Constructor } from "type-fest";

View file

@ -17,8 +17,7 @@
*/
import ErrorBoundary from "@components/ErrorBoundary";
import { findComponentByCodeLazy } from "@utils/react";
import { findByPropsLazy, findStoreLazy } from "@webpack";
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
import { useStateFromStores } from "@webpack/common";
import type { CSSProperties } from "react";

View file

@ -11,8 +11,8 @@ import { Devs } from "@utils/constants";
import { getTheme, Theme } from "@utils/discord";
import { Margins } from "@utils/margins";
import { classes } from "@utils/misc";
import { findComponentByCodeLazy } from "@utils/react";
import definePlugin, { OptionType, StartAt } from "@utils/types";
import { findComponentByCodeLazy } from "@webpack";
import { Button, Forms } from "@webpack/common";
const ColorPicker = findComponentByCodeLazy(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR");

View file

@ -20,9 +20,9 @@ import { definePluginSettings, Settings } from "@api/Settings";
import { Link } from "@components/Link";
import { Devs } from "@utils/constants";
import { isTruthy } from "@utils/guards";
import { findComponentByCodeLazy, useAwaiter } from "@utils/react";
import { useAwaiter } from "@utils/react";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { ApplicationAssetUtils, FluxDispatcher, Forms, GuildStore, React, SelectedChannelStore, SelectedGuildStore, UserStore } from "@webpack/common";
const ActivityComponent = findComponentByCodeLazy("onOpenGameProfile");

View file

@ -19,8 +19,8 @@
import { disableStyle, enableStyle } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { findComponentByCodeLazy } from "@utils/react";
import definePlugin from "@utils/types";
import { findComponentByCodeLazy } from "@webpack";
import { StatusSettingsStores } from "@webpack/common";
import style from "./style.css?managed";

View file

@ -22,9 +22,8 @@ import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants.js";
import { classes } from "@utils/misc";
import { Queue } from "@utils/Queue";
import { findComponentByCodeLazy } from "@utils/react";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import {
Button,
ChannelStore,

View file

@ -10,8 +10,8 @@ import { classNameFactory } from "@api/Styles";
import { openImageModal, openUserProfile } from "@utils/discord";
import { classes } from "@utils/misc";
import { ModalRoot, ModalSize, openModal } from "@utils/modal";
import { findExportedComponentLazy, useAwaiter } from "@utils/react";
import { findByPropsLazy } from "@webpack";
import { useAwaiter } from "@utils/react";
import { findByPropsLazy, findExportedComponentLazy } from "@webpack";
import { FluxDispatcher, Forms, GuildChannelStore, GuildMemberStore, moment, Parser, PresenceStore, RelationshipStore, ScrollerThin, SnowflakeUtils, TabBar, Timestamp, useEffect, UserStore, UserUtils, useState, useStateFromStores } from "@webpack/common";
import { Guild, User } from "discord-types/general";

View file

@ -16,8 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { findComponentByCodeLazy } from "@utils/react";
import { findLazy } from "@webpack";
import { findComponentByCodeLazy, findLazy } from "@webpack";
import { i18n, useToken } from "@webpack/common";
const ColorMap = findLazy(m => m.colors?.INTERACTIVE_MUTED?.css);

View file

@ -24,9 +24,8 @@ import { Flex } from "@components/Flex";
import { CopyIcon, LinkIcon } from "@components/Icons";
import { Devs } from "@utils/constants";
import { copyWithToast } from "@utils/misc";
import { findComponentByCodeLazy } from "@utils/react";
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy, findByPropsLazy, findStoreLazy } from "@webpack";
import { findByCodeLazy, findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
import { Text, Tooltip, UserProfileStore } from "@webpack/common";
import { User } from "discord-types/general";

View file

@ -18,9 +18,8 @@
import { Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { findComponentByCodeLazy, findComponentLazy } from "@utils/react";
import { formatDuration } from "@utils/text";
import { findByPropsLazy } from "@webpack";
import { findByPropsLazy, findComponentByCodeLazy, findComponentLazy } from "@webpack";
import { EmojiStore, FluxDispatcher, GuildMemberStore, GuildStore, moment, Parser, PermissionsBits, PermissionStore, SnowflakeUtils, Text, Timestamp, Tooltip, useEffect, useState } from "@webpack/common";
import type { Channel } from "discord-types/general";

View file

@ -16,7 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { findComponentByCodeLazy, useTimer } from "@utils/react";
import { useTimer } from "@utils/react";
import { findComponentByCodeLazy } from "@webpack";
import { cl } from "./utils";

View file

@ -20,9 +20,9 @@ import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { sleep } from "@utils/misc";
import { Queue } from "@utils/Queue";
import { findComponentByCodeLazy, useForceUpdater } from "@utils/react";
import { useForceUpdater } from "@utils/react";
import definePlugin from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { ChannelStore, FluxDispatcher, React, RestAPI, Tooltip } from "@webpack/common";
import { CustomEmoji } from "@webpack/types";
import { Message, ReactionEmoji, User } from "discord-types/general";

View file

@ -16,7 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { FilterFn, filters, find, findByProps } from "@webpack";
import { React, useEffect, useMemo, useReducer, useState } from "@webpack/common";
import { makeLazy } from "./lazy";
@ -145,41 +144,6 @@ export function useTimer({ interval = 1000, deps = [] }: TimerOpts) {
return time;
}
/**
* Finds the component which includes all the given code. Checks for plain components, memos and forwardRefs
*/
export function findComponentByCode(...code: string[]) {
const filter = filters.byCode(...code);
return find(m => {
if (filter(m)) return true;
if (!m.$$typeof) return false;
if (m.type) return filter(m.type); // memos
if (m.render) return filter(m.render); // forwardRefs
return false;
}) ?? NoopComponent;
}
/**
* Finds the first component that matches the filter, lazily.
*/
export function findComponentLazy<T extends object = any>(filter: FilterFn) {
return LazyComponent<T>(() => find(filter));
}
/**
* Finds the first component that includes all the given code, lazily
*/
export function findComponentByCodeLazy<T extends object = any>(...code: string[]) {
return LazyComponent<T>(() => findComponentByCode(...code));
}
/**
* Finds the first component that is exported by the first prop name, lazily
*/
export function findExportedComponentLazy<T extends object = any>(...props: string[]) {
return LazyComponent<T>(() => findByProps(...props)?.[props[0]]);
}
/**
* A lazy component. The factory method is called on first render.
* @param factory Function returning a Component

View file

@ -18,6 +18,7 @@
import { proxyLazy } from "@utils/lazy";
import { Logger } from "@utils/Logger";
import { LazyComponent, NoopComponent } from "@utils/react";
import type { WebpackInstance } from "discord-types/other";
import { traceFunction } from "../debug/Tracer";
@ -392,6 +393,41 @@ export function findStoreLazy(name: string) {
return proxyLazy(() => findStore(name));
}
/**
* Finds the component which includes all the given code. Checks for plain components, memos and forwardRefs
*/
export function findComponentByCode(...code: string[]) {
const filter = filters.byCode(...code);
return find(m => {
if (filter(m)) return true;
if (!m.$$typeof) return false;
if (m.type) return filter(m.type); // memos
if (m.render) return filter(m.render); // forwardRefs
return false;
}) ?? NoopComponent;
}
/**
* Finds the first component that matches the filter, lazily.
*/
export function findComponentLazy<T extends object = any>(filter: FilterFn) {
return LazyComponent<T>(() => find(filter));
}
/**
* Finds the first component that includes all the given code, lazily
*/
export function findComponentByCodeLazy<T extends object = any>(...code: string[]) {
return LazyComponent<T>(() => findComponentByCode(...code));
}
/**
* Finds the first component that is exported by the first prop name, lazily
*/
export function findExportedComponentLazy<T extends object = any>(...props: string[]) {
return LazyComponent<T>(() => findByProps(...props)?.[props[0]]);
}
/**
* Wait for a module that matches the provided filter to be registered,
* then call the callback with the module as the first argument