Compare commits

...

10 Commits

Author SHA1 Message Date
Vendicated
eb190b660e Bump to v1.0.8 2023-02-28 01:50:17 +01:00
Lewis Crichton
d6f9068695 feat: SearchableSelect (#518)
Co-authored-by: Ven <vendicated@riseup.net>
2023-02-28 00:48:58 +01:00
Nico
cb507babaa fix: vcDoubleClick and revealAllSpoilers patch (#517)
Co-authored-by: Ven <vendicated@riseup.net>
2023-02-28 00:41:14 +01:00
Vendicated
235d114193 Improve ConsoleShortcuts plugin 2023-02-28 00:38:28 +01:00
Vendicated
9aba70dcb1 Fix MenuItemDeobfuscator 2023-02-28 00:17:39 +01:00
Vendicated
0b61d29c31 Fix TypingTweaks 2023-02-28 00:17:28 +01:00
megumin
335a13a38a fix tooltip component check (#541) 2023-02-27 21:19:01 +00:00
Vendicated
128ee41252 ErrorBoundary: Do not use any Discord components to be more robust 2023-02-25 19:10:01 +01:00
Vendicated
ccca41a168 Bump to v1.0.7 2023-02-24 06:08:45 +01:00
Vendicated
af4c7d8a90 Fix Cards (they look ugly now, wtf Discord) 2023-02-24 05:48:37 +01:00
13 changed files with 122 additions and 52 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "vencord", "name": "vencord",
"private": "true", "private": "true",
"version": "1.0.6", "version": "1.0.8",
"description": "The cutest Discord client mod", "description": "The cutest Discord client mod",
"keywords": [], "keywords": [],
"homepage": "https://github.com/Vendicated/Vencord#readme", "homepage": "https://github.com/Vendicated/Vencord#readme",

View File

@ -17,8 +17,9 @@
*/ */
import Logger from "@utils/Logger"; import Logger from "@utils/Logger";
import { Margins } from "@utils/margins";
import { LazyComponent } from "@utils/misc"; import { LazyComponent } from "@utils/misc";
import { Margins, React } from "@webpack/common"; import { React } from "@webpack/common";
import { ErrorCard } from "./ErrorCard"; import { ErrorCard } from "./ErrorCard";
@ -84,15 +85,13 @@ const ErrorBoundary = LazyComponent(() => {
const msg = this.props.message || "An error occurred while rendering this Component. More info can be found below and in your console."; const msg = this.props.message || "An error occurred while rendering this Component. More info can be found below and in your console.";
return ( return (
<ErrorCard style={{ <ErrorCard style={{ overflow: "hidden" }}>
overflow: "hidden",
}}>
<h1>Oh no!</h1> <h1>Oh no!</h1>
<p>{msg}</p> <p>{msg}</p>
<code> <code>
{this.state.message} {this.state.message}
{!!this.state.stack && ( {!!this.state.stack && (
<pre className={Margins.marginTop8}> <pre className={Margins.top8}>
{this.state.stack} {this.state.stack}
</pre> </pre>
)} )}

View File

@ -0,0 +1,7 @@
.vc-error-card {
padding: 2em;
background-color: #e7828430;
border: 1px solid #e78284;
border-radius: 5px;
color: var(--text-normal, white);
}

View File

@ -16,24 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { Card } from "@webpack/common"; import "./ErrorCard.css";
interface Props { import { classes } from "@utils/misc";
style?: React.CSSProperties; import type { HTMLProps } from "react";
className?: string;
} export function ErrorCard(props: React.PropsWithChildren<HTMLProps<HTMLDivElement>>) {
export function ErrorCard(props: React.PropsWithChildren<Props>) {
return ( return (
<Card className={props.className} style={ <div {...props} className={classes(props.className, "vc-error-card")}>
{
padding: "2em",
backgroundColor: "#e7828430",
borderColor: "#e78284",
color: "var(--text-normal)",
...props.style
}
}>
{props.children} {props.children}
</Card> </div>
); );
} }

View File

@ -43,7 +43,7 @@ export default definePlugin({
{ {
find: '"Menu API', find: '"Menu API',
replacement: { replacement: {
match: /function.{0,80}type===(.{1,3})\..{1,3}\).{0,50}navigable:.+?Menu API/s, match: /function.{0,80}type===(\i)\).{0,50}navigable:.+?Menu API/s,
replace: (m, mod) => { replace: (m, mod) => {
let nicenNames = ""; let nicenNames = "";
const redefines = [] as string[]; const redefines = [] as string[];

View File

@ -18,6 +18,9 @@
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import * as Webpack from "@webpack";
import { extract, filters, findAll, search } from "@webpack";
import { React } from "@webpack/common";
const WEB_ONLY = (f: string) => () => { const WEB_ONLY = (f: string) => () => {
throw new Error(`'${f}' is Discord Desktop only.`); throw new Error(`'${f}' is Discord Desktop only.`);
@ -29,19 +32,48 @@ export default definePlugin({
authors: [Devs.Ven], authors: [Devs.Ven],
getShortcuts() { getShortcuts() {
function newFindWrapper(filterFactory: (props: any) => Webpack.FilterFn) {
const cache = new Map<string, any>();
return function (filterProps: any) {
const cacheKey = String(filterProps);
if (cache.has(cacheKey)) return cache.get(cacheKey);
const matches = findAll(filterFactory(filterProps));
const result = (() => {
switch (matches.length) {
case 0: return null;
case 1: return matches[0];
default:
const uniqueMatches = [...new Set(matches)];
if (uniqueMatches.length > 1)
console.warn(`Warning: This filter matches ${matches.length} modules. Make it more specific!\n`, uniqueMatches);
return matches[0];
}
})();
if (result && cacheKey) cache.set(cacheKey, result);
return result;
};
}
return { return {
toClip: IS_WEB ? WEB_ONLY("toClip") : window.DiscordNative.clipboard.copy, wp: Webpack,
fromClip: IS_WEB ? WEB_ONLY("fromClip") : window.DiscordNative.clipboard.read, wpc: Webpack.wreq.c,
wp: Vencord.Webpack, wreq: Webpack.wreq,
wpc: Vencord.Webpack.wreq.c, wpsearch: search,
wreq: Vencord.Webpack.wreq, wpex: extract,
wpsearch: Vencord.Webpack.search,
wpex: Vencord.Webpack.extract,
wpexs: (code: string) => Vencord.Webpack.extract(Vencord.Webpack.findModuleId(code)!), wpexs: (code: string) => Vencord.Webpack.extract(Vencord.Webpack.findModuleId(code)!),
findByProps: Vencord.Webpack.findByProps, find: newFindWrapper(f => f),
find: Vencord.Webpack.find, findAll,
Plugins: Vencord.Plugins, findByProps: newFindWrapper(filters.byProps),
React: Vencord.Webpack.Common.React, findAllByProps: (...props: string[]) => findAll(filters.byProps(...props)),
findByCode: newFindWrapper(filters.byCode),
findAllByCode: (code: string) => findAll(filters.byCode(code)),
PluginsApi: Vencord.Plugins,
plugins: Vencord.Plugins.plugins,
React,
Settings: Vencord.Settings, Settings: Vencord.Settings,
Api: Vencord.Api, Api: Vencord.Api,
reload: () => location.reload(), reload: () => location.reload(),

View File

@ -30,10 +30,10 @@ export default definePlugin({
patches: [ patches: [
{ {
find: ".revealSpoiler=function", find: ".removeObscurity=function",
replacement: { replacement: {
match: /\.revealSpoiler=function\((.{1,2})\){/, match: /\.removeObscurity=function\((\i)\){/,
replace: ".revealSpoiler=function($1){$self.reveal($1);" replace: ".removeObscurity=function($1){$self.reveal($1);"
} }
} }
], ],

View File

@ -24,7 +24,7 @@ import { findByCodeLazy } from "@webpack";
import { GuildMemberStore, React, RelationshipStore } from "@webpack/common"; import { GuildMemberStore, React, RelationshipStore } from "@webpack/common";
import { User } from "discord-types/general"; import { User } from "discord-types/general";
const Avatar = findByCodeLazy(".Positions.TOP,spacing:"); const Avatar = findByCodeLazy('"top",spacing:');
const settings = definePluginSettings({ const settings = definePluginSettings({
showAvatars: { showAvatars: {

View File

@ -48,7 +48,7 @@ export default definePlugin({
}, },
{ {
// channel mentions // channel mentions
find: ".EMOJI_IN_MESSAGE_HOVER", find: ".shouldCloseDefaultModals",
replacement: { replacement: {
match: /onClick:(\i)(?=,.{0,30}className:"channelMention")/, match: /onClick:(\i)(?=,.{0,30}className:"channelMention")/,
replace: "onClick:(_vcEv)=>(_vcEv.detail>=2||_vcEv.target.className.includes('MentionText'))&&($1)()", replace: "onClick:(_vcEv)=>(_vcEv.detail>=2||_vcEv.target.className.includes('MentionText'))&&($1)()",

View File

@ -141,8 +141,8 @@ export function humanFriendlyJoin(elements: any[], mapper: (e: any) => string =
* Calls .join(" ") on the arguments * Calls .join(" ") on the arguments
* classes("one", "two") => "one two" * classes("one", "two") => "one two"
*/ */
export function classes(...classes: string[]) { export function classes(...classes: Array<string | null | undefined>) {
return classes.filter(c => typeof c === "string").join(" "); return classes.filter(Boolean).join(" ");
} }
/** /**

View File

@ -32,10 +32,10 @@ export const Forms = {
FormText: waitForComponent<t.FormText>("FormText", m => m.Types?.INPUT_PLACEHOLDER), FormText: waitForComponent<t.FormText>("FormText", m => m.Types?.INPUT_PLACEHOLDER),
}; };
export const Card = waitForComponent<t.Card>("Card", m => m.Types?.PRIMARY === "cardPrimary"); export const Card = waitForComponent<t.Card>("Card", m => m.Types?.PRIMARY && m.defaultProps);
export const Button = waitForComponent<t.Button>("Button", ["Hovers", "Looks", "Sizes"]); export const Button = waitForComponent<t.Button>("Button", ["Hovers", "Looks", "Sizes"]);
export const Switch = waitForComponent<t.Switch>("Switch", filters.byCode("tooltipNote", "ringTarget")); export const Switch = waitForComponent<t.Switch>("Switch", filters.byCode("tooltipNote", "ringTarget"));
export const Tooltip = waitForComponent<t.Tooltip>("Tooltip", ["Positions", "Colors"]); export const Tooltip = waitForComponent<t.Tooltip>("Tooltip", filters.byCode("shouldShowTooltip:!1", "clickableOnMobile||"));
export const Timestamp = waitForComponent<t.Timestamp>("Timestamp", filters.byCode(".Messages.MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL.format")); export const Timestamp = waitForComponent<t.Timestamp>("Timestamp", filters.byCode(".Messages.MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL.format"));
export const TextInput = waitForComponent<t.TextInput>("TextInput", ["defaultProps", "Sizes", "contextType"]); export const TextInput = waitForComponent<t.TextInput>("TextInput", ["defaultProps", "Sizes", "contextType"]);
export const TextArea = waitForComponent<t.TextArea>("TextArea", filters.byCode("handleSetRef", "textArea")); export const TextArea = waitForComponent<t.TextArea>("TextArea", filters.byCode("handleSetRef", "textArea"));
@ -45,6 +45,10 @@ export const Text = waitForComponent<t.Text>("Text", m => {
return (s.length < 1500 && s.includes("data-text-variant") && s.includes("always-white")); return (s.length < 1500 && s.includes("data-text-variant") && s.includes("always-white"));
}); });
export const Select = waitForComponent<t.Select>("Select", filters.byCode("optionClassName", "popoutPosition", "autoFocus", "maxVisibleItems")); export const Select = waitForComponent<t.Select>("Select", filters.byCode("optionClassName", "popoutPosition", "autoFocus", "maxVisibleItems"));
const searchableSelectFilter = filters.byCode("autoFocus", ".Messages.SELECT");
export const SearchableSelect = waitForComponent<t.SearchableSelect>("SearchableSelect", m =>
m.render && searchableSelectFilter(m.render)
);
export const Slider = waitForComponent<t.Slider>("Slider", filters.byCode("closestMarkerIndex", "stickToMarkers")); export const Slider = waitForComponent<t.Slider>("Slider", filters.byCode("closestMarkerIndex", "stickToMarkers"));
export const Flex = waitForComponent<t.Flex>("Flex", ["Justify", "Align", "Wrap"]); export const Flex = waitForComponent<t.Flex>("Flex", ["Justify", "Align", "Wrap"]);

View File

@ -90,16 +90,17 @@ export type Tooltip = ComponentType<{
/** Tooltip.Colors.BLACK */ /** Tooltip.Colors.BLACK */
color?: string; color?: string;
/** Tooltip.Positions.TOP */ /** TooltipPositions.TOP */
position?: string; position?: string;
tooltipClassName?: string; tooltipClassName?: string;
tooltipContentClassName?: string; tooltipContentClassName?: string;
}> & { }> & {
Positions: Record<"BOTTOM" | "CENTER" | "LEFT" | "RIGHT" | "TOP" | "WINDOW_CENTER", string>;
Colors: Record<"BLACK" | "BRAND" | "CUSTOM" | "GREEN" | "GREY" | "PRIMARY" | "RED" | "YELLOW", string>; Colors: Record<"BLACK" | "BRAND" | "CUSTOM" | "GREEN" | "GREY" | "PRIMARY" | "RED" | "YELLOW", string>;
}; };
export type TooltipPositions = Record<"BOTTOM" | "CENTER" | "LEFT" | "RIGHT" | "TOP" | "WINDOW_CENTER", string>;
export type Card = ComponentType<PropsWithChildren<HTMLProps<HTMLDivElement> & { export type Card = ComponentType<PropsWithChildren<HTMLProps<HTMLDivElement> & {
editable?: boolean; editable?: boolean;
outline?: boolean; outline?: boolean;
@ -234,6 +235,49 @@ export type Select = ComponentType<PropsWithChildren<{
"aria-labelledby"?: boolean; "aria-labelledby"?: boolean;
}>>; }>>;
export type SearchableSelect = ComponentType<PropsWithChildren<{
placeholder?: string;
options: ReadonlyArray<SelectOption>; // TODO
value?: SelectOption;
/**
* - 0 ~ Filled
* - 1 ~ Custom
*/
look?: 0 | 1;
className?: string;
popoutClassName?: string;
wrapperClassName?: string;
popoutPosition?: "top" | "left" | "right" | "bottom" | "center" | "window_center";
optionClassName?: string;
autoFocus?: boolean;
isDisabled?: boolean;
clearable?: boolean;
closeOnSelect?: boolean;
clearOnSelect?: boolean;
multi?: boolean;
onChange(value: any): void;
onSearchChange?(value: string): void;
onClose?(): void;
onOpen?(): void;
onBlur?(): void;
renderOptionPrefix?(option: SelectOption): ReactNode;
renderOptionSuffix?(option: SelectOption): ReactNode;
filter?(option: SelectOption[], query: string): SelectOption[];
centerCaret?: boolean;
debounceTime?: number;
maxVisibleItems?: number;
popoutWidth?: number;
"aria-labelledby"?: boolean;
}>>;
export type Slider = ComponentType<PropsWithChildren<{ export type Slider = ComponentType<PropsWithChildren<{
initialValue: number; initialValue: number;
defaultValue?: number; defaultValue?: number;

View File

@ -307,13 +307,6 @@ export function findByPropsLazy(...props: string[]) {
return findLazy(filters.byProps(...props)); return findLazy(filters.byProps(...props));
} }
/**
* Find all modules that have the specified properties
*/
export function findAllByProps(...props: string[]) {
return findAll(filters.byProps(...props));
}
/** /**
* Find a function by its code * Find a function by its code
*/ */