componentEditor: Message accessories
(work check-in commit, I want to add text area stuff before releasing)
Cynthia Foxwell 1 month ago 3 files (+40, -0)
@@ -59,6 +59,14 @@ replacement: (_, elements) =>`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)})`+ }}];
@@ -12,6 +12,7 @@const username: Record<string, MessageUsername> = {};const usernameBadges: Record<string, MessageUsernameBadge> = {};const badges: Record<string, MessageBadge> = {};+const accessories: Record<string, React.FC<any>> = {};function addEntries(elements: React.ReactNode[],@@ -40,6 +41,13 @@ } else {const index = elements.indexOf(originalElements[indicies[entry.anchor]!]);elements.splice(index! + (entry.before ? 0 : 1), 0, component);}+ }+}++function addComponents(elements: React.ReactNode[], components: Record<string, React.FC<any>>, props: any) {+ for (const [id, Component] of Object.entries(components)) {+ const component = <Component {...props} key={id} />;+ elements.push(component);}}@@ -65,6 +73,9 @@ anchor,before};},+ addAccessory(id, component) {+ accessories[id] = component;+ },_patchUsername(elements, props) {addEntries(elements, username, MessageUsernameIndicies, props);return elements;@@ -75,6 +86,10 @@ return elements;},_patchBadges(elements, props) {addEntries(elements, badges, MessageBadgeIndicies, props);+ return elements;+ },+ _patchAccessories(elements, props) {+ addComponents(elements, accessories, props);return elements;}};
@@ -121,15 +121,28 @@ potion}export type Messages = {+ /**+ * Adds a component to the username of a message+ */addToUsername: (id: string, component: React.FC<any>, 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<any>,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<any>, anchor?: MessageBadgeAnchors, before?: boolean) => void;/**+ * Adds a component to message accessories (e.g. embeds)+ */+ addAccessory: (id: string, component: React.FC<any>) => void;+ /*** @private*/_patchUsername: Patcher<any>;@@ -141,5 +154,9 @@ /*** @private*/_patchBadges: Patcher<any>;+ /**+ * @private+ */+ _patchAccessories: Patcher<any>;};//#endregion