mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-20 06:30:35 +00:00
Merge fddccea8b8
into b875ebf92d
This commit is contained in:
commit
7eee018887
4 changed files with 102 additions and 1 deletions
61
src/api/ExpressionPickerTabs.tsx
Normal file
61
src/api/ExpressionPickerTabs.tsx
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
|
import { Channel } from "discord-types/general";
|
||||||
|
|
||||||
|
export interface ExpressionPickerButtonProps {
|
||||||
|
id?: string;
|
||||||
|
"aria-controls": string;
|
||||||
|
"aria-selected": boolean;
|
||||||
|
isActive: boolean;
|
||||||
|
viewType: string;
|
||||||
|
children: string | JSX.Element;
|
||||||
|
autoFocus?: boolean;
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExpressionPickerPanelProps {
|
||||||
|
selectedTab: string;
|
||||||
|
channel: Channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ExpressionPickerButtonComponent = (props: ExpressionPickerButtonProps) => JSX.Element | null;
|
||||||
|
export type ExpressionPickerPanelComponent = (props: ExpressionPickerPanelProps) => JSX.Element | null;
|
||||||
|
|
||||||
|
|
||||||
|
export interface ExpressionPickerTabItem {
|
||||||
|
tab: string,
|
||||||
|
Component: ExpressionPickerPanelComponent;
|
||||||
|
autoFocus?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ExpressionPickerComponents = new Map<string, ExpressionPickerTabItem>();
|
||||||
|
|
||||||
|
|
||||||
|
export const addExpressionPickerTabButton = (id: string, tab: string, PanelComponent: ExpressionPickerPanelComponent, autoFocus?: boolean) => ExpressionPickerComponents.set(id, { tab: tab, Component: PanelComponent, autoFocus: autoFocus });
|
||||||
|
export const removeExpressionPickerTabButton = (id: string) => ExpressionPickerComponents.delete(id);
|
||||||
|
|
||||||
|
|
||||||
|
export function* RenderTabButtons(ExpressionPickerButtonComponent: ExpressionPickerButtonComponent, selectedTab: string) {
|
||||||
|
for (const [id, { tab }] of ExpressionPickerComponents) {
|
||||||
|
yield (<ErrorBoundary><ExpressionPickerButtonComponent
|
||||||
|
id={id + "-picker-tab"}
|
||||||
|
aria-controls={id + "-picker-tab-panel"}
|
||||||
|
aria-selected={id === selectedTab}
|
||||||
|
viewType={id}
|
||||||
|
isActive={id === selectedTab}
|
||||||
|
>{tab}</ExpressionPickerButtonComponent></ErrorBoundary>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function* TabPanels(selectedTab: string, channel: Channel) {
|
||||||
|
for (const [id, { Component }] of ExpressionPickerComponents) {
|
||||||
|
if (id !== selectedTab) { continue; }
|
||||||
|
const PanelComponent: ExpressionPickerPanelComponent = Component;
|
||||||
|
yield (<ErrorBoundary><PanelComponent selectedTab={selectedTab} channel={channel} /></ErrorBoundary>);
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ import * as $ChatButtons from "./ChatButtons";
|
||||||
import * as $Commands from "./Commands";
|
import * as $Commands from "./Commands";
|
||||||
import * as $ContextMenu from "./ContextMenu";
|
import * as $ContextMenu from "./ContextMenu";
|
||||||
import * as $DataStore from "./DataStore";
|
import * as $DataStore from "./DataStore";
|
||||||
|
import * as $ExpressionPickerTabs from "./ExpressionPickerTabs";
|
||||||
import * as $MemberListDecorators from "./MemberListDecorators";
|
import * as $MemberListDecorators from "./MemberListDecorators";
|
||||||
import * as $MessageAccessories from "./MessageAccessories";
|
import * as $MessageAccessories from "./MessageAccessories";
|
||||||
import * as $MessageDecorations from "./MessageDecorations";
|
import * as $MessageDecorations from "./MessageDecorations";
|
||||||
|
@ -119,6 +120,11 @@ export const ChatButtons = $ChatButtons;
|
||||||
export const MessageUpdater = $MessageUpdater;
|
export const MessageUpdater = $MessageUpdater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An API allowing you to get an user setting
|
* An API allowing you to add panels to the expression picker
|
||||||
|
*/
|
||||||
|
export const ExpressionPickerTabs = $ExpressionPickerTabs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An API allowing you to get an user setting
|
||||||
*/
|
*/
|
||||||
export const UserSettings = $UserSettings;
|
export const UserSettings = $UserSettings;
|
||||||
|
|
30
src/plugins/_api/expressionPickerTabs.ts
Normal file
30
src/plugins/_api/expressionPickerTabs.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Devs } from "@utils/constants";
|
||||||
|
import definePlugin from "@utils/types";
|
||||||
|
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
name: "ExpressionPickerTabsAPI",
|
||||||
|
description: "an API to add panels to the expression picker",
|
||||||
|
authors: [Devs.iamme],
|
||||||
|
patches: [
|
||||||
|
{
|
||||||
|
find: ".EXPRESSION_PICKER_CATEGORIES_A11Y_LABEL",
|
||||||
|
replacement: [
|
||||||
|
{
|
||||||
|
match: /\.jsx\)\((\i),\{id:\i\.E\i,.+?,"aria-selected":(\i)===\i\.\i\.EMOJI.+?,viewType:(\i).+?\}\)/,
|
||||||
|
replace: "$&,...Vencord.Api.ExpressionPickerTabs.RenderTabButtons($1, $2)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match: /null,(\i)===\i\.\i\.EMOJI\?.{0,55}channel:(\i),.+?\):null/,
|
||||||
|
replace: "$&,...Vencord.Api.ExpressionPickerTabs.TabPanels($1, $2)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
|
@ -475,6 +475,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
||||||
name: "Sqaaakoi",
|
name: "Sqaaakoi",
|
||||||
id: 259558259491340288n
|
id: 259558259491340288n
|
||||||
},
|
},
|
||||||
|
iamme: {
|
||||||
|
name: "i am me",
|
||||||
|
id: 984392761929256980n
|
||||||
|
},
|
||||||
Byron: {
|
Byron: {
|
||||||
name: "byeoon",
|
name: "byeoon",
|
||||||
id: 1167275288036655133n
|
id: 1167275288036655133n
|
||||||
|
|
Loading…
Reference in a new issue