1- /* eslint-disable no-use-before-define */
21'use strict' ;
32
4- // eslint-disable-next-line import-x/order
3+ const { lazy } = require ( '@discordjs/util' ) ;
54const { ComponentType } = require ( 'discord-api-types/v10' ) ;
65
6+ // Fixes circular dependencies.
7+ const getActionRow = lazy ( ( ) => require ( '../structures/ActionRow.js' ) . ActionRow ) ;
8+ const getButtonComponent = lazy ( ( ) => require ( '../structures/ButtonComponent.js' ) . ButtonComponent ) ;
9+ const getChannelSelectMenuComponent = lazy (
10+ ( ) => require ( '../structures/ChannelSelectMenuComponent.js' ) . ChannelSelectMenuComponent ,
11+ ) ;
12+ const getComponent = lazy ( ( ) => require ( '../structures/Component.js' ) . Component ) ;
13+ const getContainerComponent = lazy ( ( ) => require ( '../structures/ContainerComponent.js' ) . ContainerComponent ) ;
14+ const getFileComponent = lazy ( ( ) => require ( '../structures/FileComponent.js' ) . FileComponent ) ;
15+ const getLabelComponent = lazy ( ( ) => require ( '../structures/LabelComponent.js' ) . LabelComponent ) ;
16+ const getMediaGalleryComponent = lazy ( ( ) => require ( '../structures/MediaGalleryComponent.js' ) . MediaGalleryComponent ) ;
17+ const getMentionableSelectMenuComponent = lazy (
18+ ( ) => require ( '../structures/MentionableSelectMenuComponent.js' ) . MentionableSelectMenuComponent ,
19+ ) ;
20+ const getRoleSelectMenuComponent = lazy (
21+ ( ) => require ( '../structures/RoleSelectMenuComponent.js' ) . RoleSelectMenuComponent ,
22+ ) ;
23+ const getSectionComponent = lazy ( ( ) => require ( '../structures/SectionComponent.js' ) . SectionComponent ) ;
24+ const getSeparatorComponent = lazy ( ( ) => require ( '../structures/SeparatorComponent.js' ) . SeparatorComponent ) ;
25+ const getStringSelectMenuComponent = lazy (
26+ ( ) => require ( '../structures/StringSelectMenuComponent.js' ) . StringSelectMenuComponent ,
27+ ) ;
28+ const getTextDisplayComponent = lazy ( ( ) => require ( '../structures/TextDisplayComponent.js' ) . TextDisplayComponent ) ;
29+ const getTextInputComponent = lazy ( ( ) => require ( '../structures/TextInputComponent.js' ) . TextInputComponent ) ;
30+ const getThumbnailComponent = lazy ( ( ) => require ( '../structures/ThumbnailComponent.js' ) . ThumbnailComponent ) ;
31+ const getUserSelectMenuComponent = lazy (
32+ ( ) => require ( '../structures/UserSelectMenuComponent.js' ) . UserSelectMenuComponent ,
33+ ) ;
34+
735/**
836 * @typedef {Object } BaseComponentData
937 * @property {number } [id] the id of this component
@@ -192,6 +220,25 @@ const { ComponentType } = require('discord-api-types/v10');
192220 * SectionComponent|SeparatorComponent|TextDisplayComponent} MessageTopLevelComponent
193221 */
194222
223+ const ComponentTypeToClass = {
224+ [ ComponentType . ActionRow ] : getActionRow ,
225+ [ ComponentType . Button ] : getButtonComponent ,
226+ [ ComponentType . StringSelect ] : getStringSelectMenuComponent ,
227+ [ ComponentType . TextInput ] : getTextInputComponent ,
228+ [ ComponentType . UserSelect ] : getUserSelectMenuComponent ,
229+ [ ComponentType . RoleSelect ] : getRoleSelectMenuComponent ,
230+ [ ComponentType . MentionableSelect ] : getMentionableSelectMenuComponent ,
231+ [ ComponentType . ChannelSelect ] : getChannelSelectMenuComponent ,
232+ [ ComponentType . Container ] : getContainerComponent ,
233+ [ ComponentType . TextDisplay ] : getTextDisplayComponent ,
234+ [ ComponentType . File ] : getFileComponent ,
235+ [ ComponentType . MediaGallery ] : getMediaGalleryComponent ,
236+ [ ComponentType . Section ] : getSectionComponent ,
237+ [ ComponentType . Separator ] : getSeparatorComponent ,
238+ [ ComponentType . Thumbnail ] : getThumbnailComponent ,
239+ [ ComponentType . Label ] : getLabelComponent ,
240+ } ;
241+
195242/**
196243 * Transforms API data into a component
197244 *
@@ -200,7 +247,7 @@ const { ComponentType } = require('discord-api-types/v10');
200247 * @ignore
201248 */
202249function createComponent ( data ) {
203- return data instanceof Component ? data : new ( ComponentTypeToClass [ data . type ] ?? Component ) ( data ) ;
250+ return data instanceof getComponent ( ) ? data : new ( ComponentTypeToClass [ data . type ] ?. ( ) ?? getComponent ( ) ) ( data ) ;
204251}
205252
206253/**
@@ -241,40 +288,3 @@ function findComponentByCustomId(components, customId) {
241288
242289exports . createComponent = createComponent ;
243290exports . findComponentByCustomId = findComponentByCustomId ;
244-
245- const { ActionRow } = require ( '../structures/ActionRow.js' ) ;
246- const { ButtonComponent } = require ( '../structures/ButtonComponent.js' ) ;
247- const { ChannelSelectMenuComponent } = require ( '../structures/ChannelSelectMenuComponent.js' ) ;
248- const { Component } = require ( '../structures/Component.js' ) ;
249- const { ContainerComponent } = require ( '../structures/ContainerComponent.js' ) ;
250- const { FileComponent } = require ( '../structures/FileComponent.js' ) ;
251- const { LabelComponent } = require ( '../structures/LabelComponent.js' ) ;
252- const { MediaGalleryComponent } = require ( '../structures/MediaGalleryComponent.js' ) ;
253- const { MentionableSelectMenuComponent } = require ( '../structures/MentionableSelectMenuComponent.js' ) ;
254- const { RoleSelectMenuComponent } = require ( '../structures/RoleSelectMenuComponent.js' ) ;
255- const { SectionComponent } = require ( '../structures/SectionComponent.js' ) ;
256- const { SeparatorComponent } = require ( '../structures/SeparatorComponent.js' ) ;
257- const { StringSelectMenuComponent } = require ( '../structures/StringSelectMenuComponent.js' ) ;
258- const { TextDisplayComponent } = require ( '../structures/TextDisplayComponent.js' ) ;
259- const { TextInputComponent } = require ( '../structures/TextInputComponent.js' ) ;
260- const { ThumbnailComponent } = require ( '../structures/ThumbnailComponent.js' ) ;
261- const { UserSelectMenuComponent } = require ( '../structures/UserSelectMenuComponent.js' ) ;
262-
263- const ComponentTypeToClass = {
264- [ ComponentType . ActionRow ] : ActionRow ,
265- [ ComponentType . Button ] : ButtonComponent ,
266- [ ComponentType . StringSelect ] : StringSelectMenuComponent ,
267- [ ComponentType . TextInput ] : TextInputComponent ,
268- [ ComponentType . UserSelect ] : UserSelectMenuComponent ,
269- [ ComponentType . RoleSelect ] : RoleSelectMenuComponent ,
270- [ ComponentType . MentionableSelect ] : MentionableSelectMenuComponent ,
271- [ ComponentType . ChannelSelect ] : ChannelSelectMenuComponent ,
272- [ ComponentType . Container ] : ContainerComponent ,
273- [ ComponentType . TextDisplay ] : TextDisplayComponent ,
274- [ ComponentType . File ] : FileComponent ,
275- [ ComponentType . MediaGallery ] : MediaGalleryComponent ,
276- [ ComponentType . Section ] : SectionComponent ,
277- [ ComponentType . Separator ] : SeparatorComponent ,
278- [ ComponentType . Thumbnail ] : ThumbnailComponent ,
279- [ ComponentType . Label ] : LabelComponent ,
280- } ;
0 commit comments