Merge remote-tracking branch 'upstream/dev'

This commit is contained in:
thororen1234 2024-05-20 15:39:21 -04:00
commit 9d0550bf79
43 changed files with 644 additions and 248 deletions

View file

@ -16,10 +16,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import "./ExpandableHeader.css";
import { classNameFactory } from "@api/Styles";
import { Text, Tooltip, useState } from "@webpack/common";
export const cl = classNameFactory("vc-expandableheader-");
import "./ExpandableHeader.css";
const cl = classNameFactory("vc-expandableheader-");
export interface ExpandableHeaderProps {
onMoreClick?: () => void;
@ -31,7 +33,7 @@ export interface ExpandableHeaderProps {
buttons?: React.ReactNode[];
}
export default function ExpandableHeader({ children, onMoreClick, buttons, moreTooltipText, defaultState = false, onDropDownClick, headerText }: ExpandableHeaderProps) {
export function ExpandableHeader({ children, onMoreClick, buttons, moreTooltipText, defaultState = false, onDropDownClick, headerText }: ExpandableHeaderProps) {
const [showContent, setShowContent] = useState(defaultState);
return (

View file

@ -16,7 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { CheckedTextInput } from "@components/CheckedTextInput";
import { CodeBlock } from "@components/CodeBlock";
import { debounce } from "@shared/debounce";
import { Margins } from "@utils/margins";
@ -47,7 +46,7 @@ const findCandidates = debounce(function ({ find, setModule, setError }) {
interface ReplacementComponentProps {
module: [id: number, factory: Function];
match: string | RegExp;
match: string;
replacement: string | ReplaceFn;
setReplacementError(error: any): void;
}
@ -58,7 +57,13 @@ function ReplacementComponent({ module, match, replacement, setReplacementError
const [patchedCode, matchResult, diff] = React.useMemo(() => {
const src: string = fact.toString().replaceAll("\n", "");
const canonicalMatch = canonicalizeMatch(match);
try {
new RegExp(match);
} catch (e) {
return ["", [], []];
}
const canonicalMatch = canonicalizeMatch(new RegExp(match));
try {
const canonicalReplace = canonicalizeReplace(replacement, "YourPlugin");
var patched = src.replace(canonicalMatch, canonicalReplace as string);
@ -286,6 +291,7 @@ function PatchHelper() {
const [module, setModule] = React.useState<[number, Function]>();
const [findError, setFindError] = React.useState<string>();
const [matchError, setMatchError] = React.useState<string>();
const code = React.useMemo(() => {
return `
@ -300,20 +306,16 @@ function PatchHelper() {
}, [parsedFind, match, replacement]);
function onFindChange(v: string) {
setFindError(void 0);
setFind(v);
}
function onFindBlur() {
try {
let parsedFind = find as string | RegExp;
if (/^\/.+?\/$/.test(find)) parsedFind = new RegExp(find.slice(1, -1));
let parsedFind = v as string | RegExp;
if (/^\/.+?\/$/.test(v)) parsedFind = new RegExp(v.slice(1, -1));
setFindError(void 0);
setFind(find);
setParsedFind(parsedFind);
if (find.length) {
if (v.length) {
findCandidates({ find: parsedFind, setModule, setError: setFindError });
}
} catch (e: any) {
@ -322,12 +324,13 @@ function PatchHelper() {
}
function onMatchChange(v: string) {
setMatch(v);
try {
new RegExp(v);
setFindError(void 0);
setMatch(v);
setMatchError(void 0);
} catch (e: any) {
setFindError((e as Error).message);
setMatchError((e as Error).message);
}
}
@ -346,21 +349,15 @@ function PatchHelper() {
type="text"
value={find}
onChange={onFindChange}
onBlur={onFindBlur}
error={findError}
/>
<Forms.FormTitle className={Margins.top8}>match</Forms.FormTitle>
<CheckedTextInput
<TextInput
type="text"
value={match}
onChange={onMatchChange}
validate={v => {
try {
return (new RegExp(v), true);
} catch (e) {
return (e as Error).message;
}
}}
error={matchError}
/>
<div className={Margins.top8} />
@ -374,7 +371,7 @@ function PatchHelper() {
{module && (
<ReplacementComponent
module={module}
match={new RegExp(match)}
match={match}
replacement={replacement}
setReplacementError={setReplacementError}
/>

18
src/components/index.ts Normal file
View file

@ -0,0 +1,18 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
export * from "./Badge";
export * from "./CheckedTextInput";
export * from "./CodeBlock";
export * from "./DonateButton";
export { default as ErrorBoundary } from "./ErrorBoundary";
export * from "./ErrorCard";
export * from "./ExpandableHeader";
export * from "./Flex";
export * from "./Heart";
export * from "./Icons";
export * from "./Link";
export * from "./Switch";