From 21eed0a89b960d89f69f0997ea2b1c2ca1c09aed Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Wed, 29 Jan 2025 16:20:55 -0700 Subject: [PATCH] componentEditor: Message accessories (work check-in commit, I want to add text area stuff before releasing) --- .../src/componentEditor/index.ts | 8 ++++++++ .../componentEditor/webpackModules/messages.tsx | 15 +++++++++++++++ .../types/src/coreExtensions/componentEditor.ts | 17 +++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/packages/core-extensions/src/componentEditor/index.ts b/packages/core-extensions/src/componentEditor/index.ts index 2456c8b..6be3fcb 100644 --- a/packages/core-extensions/src/componentEditor/index.ts +++ b/packages/core-extensions/src/componentEditor/index.ts @@ -59,6 +59,14 @@ export const patches: Patch[] = [ `children:require("componentEditor_messages").default._patchUsername(${elements},arguments[0])` } ] + }, + { + find: '.provider&&"Discord"===', + replace: { + match: /(?<=\.container\),)children:(\[.+?this\.renderSuppressConfirmModal\(\),.+?\])}\)/, + replacement: (_, elements) => + `children:require("componentEditor_messages").default._patchAccessories(${elements},this.props)})` + } } ]; diff --git a/packages/core-extensions/src/componentEditor/webpackModules/messages.tsx b/packages/core-extensions/src/componentEditor/webpackModules/messages.tsx index b994bd9..fc125cb 100644 --- a/packages/core-extensions/src/componentEditor/webpackModules/messages.tsx +++ b/packages/core-extensions/src/componentEditor/webpackModules/messages.tsx @@ -12,6 +12,7 @@ import React from "@moonlight-mod/wp/react"; const username: Record = {}; const usernameBadges: Record = {}; const badges: Record = {}; +const accessories: Record> = {}; function addEntries( elements: React.ReactNode[], @@ -43,6 +44,13 @@ function addEntries( } } +function addComponents(elements: React.ReactNode[], components: Record>, props: any) { + for (const [id, Component] of Object.entries(components)) { + const component = ; + elements.push(component); + } +} + export const messages: Messages = { addToUsername(id, component, anchor, before = false) { username[id] = { @@ -65,6 +73,9 @@ export const messages: Messages = { before }; }, + addAccessory(id, component) { + accessories[id] = component; + }, _patchUsername(elements, props) { addEntries(elements, username, MessageUsernameIndicies, props); return elements; @@ -76,6 +87,10 @@ export const messages: Messages = { _patchBadges(elements, props) { addEntries(elements, badges, MessageBadgeIndicies, props); return elements; + }, + _patchAccessories(elements, props) { + addComponents(elements, accessories, props); + return elements; } }; diff --git a/packages/types/src/coreExtensions/componentEditor.ts b/packages/types/src/coreExtensions/componentEditor.ts index 1647d60..465dd07 100644 --- a/packages/types/src/coreExtensions/componentEditor.ts +++ b/packages/types/src/coreExtensions/componentEditor.ts @@ -121,14 +121,27 @@ export enum MessageBadgeIndicies { } export type Messages = { + /** + * Adds a component to the username of a message + */ addToUsername: (id: string, component: React.FC, anchor?: MessageUsernameAnchors, before?: boolean) => void; + /** + * Adds a component to the username badge area of a message (e.g. where role icons/new member badge is) + */ addUsernameBadge: ( id: string, component: React.FC, anchor?: MessageUsernameBadgeAnchors, before?: boolean ) => void; + /** + * Adds a component to the end of a message header (e.g. silent indicator) + */ addBadge: (id: string, component: React.FC, anchor?: MessageBadgeAnchors, before?: boolean) => void; + /** + * Adds a component to message accessories (e.g. embeds) + */ + addAccessory: (id: string, component: React.FC) => void; /** * @private */ @@ -141,5 +154,9 @@ export type Messages = { * @private */ _patchBadges: Patcher; + /** + * @private + */ + _patchAccessories: Patcher; }; //#endregion