From 955232f4d617079e81b2cefb4479197bfc580fc8 Mon Sep 17 00:00:00 2001 From: programminglaboratorys Date: Fri, 26 Apr 2024 14:46:13 +0300 Subject: [PATCH] adding the api --- src/api/Tablist.tsx | 67 +++++++++++++++++++++++++++++++++++++ src/api/index.ts | 6 ++++ src/plugins/_api/tablist.ts | 24 +++++++++++++ src/utils/constants.ts | 4 +++ 4 files changed, 101 insertions(+) create mode 100644 src/api/Tablist.tsx create mode 100644 src/plugins/_api/tablist.ts diff --git a/src/api/Tablist.tsx b/src/api/Tablist.tsx new file mode 100644 index 000000000..db21cb9b0 --- /dev/null +++ b/src/api/Tablist.tsx @@ -0,0 +1,67 @@ +import { Channel } from "discord-types/general"; +//import { Logger } from "@utils/Logger"; + +//const logger = new Logger("Tablist"); useless + +export interface ExpressionMate { + CHAT_INPUT_BUTTON_CLASSNAME: string; + expressionPickerViewType: object; + expressionPickerWidths: { MIN: "min", MAX: "max"; }; + MIN_EXPRESSION_PICKER_WIDTH: number; // what's really matter here +} + +export interface TablistButtonProps { + id?: string; + "aria-controls": string; + "aria-selected": boolean; + isActive: boolean; + viewType: string; + children: string | JSX.Element; + autoFocus?: boolean; + [key: string]: any; +} + +export interface TablistPanelProps { + selectedTab: string; + channel: Channel; + expressionMate: ExpressionMate; +} + +export type TablistButtonComponent = (props: TablistButtonProps) => JSX.Element | null; +export type TablistPanelComponent = (props: TablistPanelProps) => JSX.Element | null; + + +export interface TablistItem { + tab: string, + Component: TablistPanelComponent; + autoFocus?: boolean; +} + +const TablistComponents = new Map(); + + +export const addTablistButton = (id: string, tab: string, PanelComponent: TablistPanelComponent, autoFocus?: boolean) => TablistComponents.set(id, { tab: tab, Component: PanelComponent, autoFocus: autoFocus }); +export const removeTablistButton = (id: string) => TablistComponents.delete(id); + + +export function* RenderButtons(TablistButtonComponent: TablistButtonComponent, selectedTab: string, expressionMate: ExpressionMate) { + for (const tab in TablistComponents) { + yield ({TablistComponents[tab].tab} + ); + } +} + +export function* TabPanels(selectedTab: string, expressionMate: ExpressionMate, channel: Channel) { + for (const tab in TablistComponents) { + if (tab !== selectedTab) { continue; } + let PanelComponent: TablistPanelComponent = TablistComponents[tab].Component; + yield (); + } +} diff --git a/src/api/index.ts b/src/api/index.ts index 5dca63105..b9e022fcc 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -31,6 +31,7 @@ import * as $Notifications from "./Notifications"; import * as $ServerList from "./ServerList"; import * as $Settings from "./Settings"; import * as $Styles from "./Styles"; +import * as $Tablist from "./Tablist"; /** * An API allowing you to listen to Message Clicks or run your own logic @@ -110,3 +111,8 @@ export const ContextMenu = $ContextMenu; * An API allowing you to add buttons to the chat input */ export const ChatButtons = $ChatButtons; + +/** + * An API allowing you to add panels to the expression picker + */ +export const Tablist = $Tablist; diff --git a/src/plugins/_api/tablist.ts b/src/plugins/_api/tablist.ts new file mode 100644 index 000000000..2a1181e9a --- /dev/null +++ b/src/plugins/_api/tablist.ts @@ -0,0 +1,24 @@ +import definePlugin from "@utils/types"; +import { Devs } from "@utils/constants"; + + +export default definePlugin({ + name: "TablistApi", + description: "API to add panels to the expression picker", + authors: [Devs.iamme], + patches: [ + { + find: ".EXPRESSION_PICKER_CATEGORIES_A11Y_LABEL", + replacement: [ + { + match: /\.jsx)\((\i),\{id:\i\.\i,.+?,"aria-selected":(\i)===.+?,viewType:(\i).+?\}\)/,//\] + replace: "$&,...Vencord.Api.Tablist.RenderButtons($1, $2, $3)" + }, + { + match: /null,(\i)===(\i)\.ExpressionPickerViewType\.EMOJI\?.{0,55}channel:(\i),.+?\):null/, + replace: "$&,...Vencord.Api.Tablist.TabPanels($1, $2, $3)" + } + ] + } + ] +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 8ab0bffb3..0e8e16743 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -438,6 +438,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "Sqaaakoi", id: 259558259491340288n }, + iamme: { + name: "i am me", + id: 984392761929256980n + }, Byron: { name: "byeoon", id: 1167275288036655133n