-
-
Notifications
You must be signed in to change notification settings - Fork 4k
feat: components v2 in v14 #10781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: components v2 in v14 #10781
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6af449c
feat: components v2
Qjuh 8835fd6
types: remove random readonly
Qjuh c1070c2
fix: remove BaseComponent layer
Qjuh c332c18
fix: apply requested changes
Qjuh 7382463
docs: optional vs nullable
Qjuh 652019c
chore: bump discord-api-types in rest
Qjuh 3325693
Apply suggestions from code review
Qjuh f6a0f35
chore: lint
Qjuh d413e63
Update packages/discord.js/src/structures/interfaces/TextBasedChannel.js
Qjuh c2e66d9
refactor: util function
Qjuh 731af08
chore: typo
Jiralite ecad05c
fix: docs
Qjuh 5e4b467
fix: lint
Qjuh cc31f42
Update packages/discord.js/src/util/APITypes.js
Qjuh b8128c9
fix: lint
Qjuh 86fa110
fix: lint again!
Qjuh 8517762
chore: bump builders
Qjuh e8e23ac
Update packages/discord.js/src/structures/interfaces/TextBasedChannel.js
Qjuh 2b19d80
chore: suggestions
Qjuh 2864d67
chore: lint...
Qjuh 537db59
Update packages/discord.js/typings/index.test-d.ts
Qjuh 300d431
docs: missed a type
Qjuh 996e3d3
Merge branch 'v14' into mainlib-v14/v2-components
Qjuh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| 'use strict'; | ||
|
|
||
| const Component = require('./Component'); | ||
| const { createComponent } = require('../util/Components'); | ||
|
|
||
| /** | ||
| * Represents a container component | ||
| * @extends {Component} | ||
| */ | ||
| class ContainerComponent extends Component { | ||
| constructor({ components, ...data }) { | ||
| super(data); | ||
|
|
||
| /** | ||
| * The components in this container | ||
| * @type {Component[]} | ||
| * @readonly | ||
| */ | ||
| this.components = components.map(component => createComponent(component)); | ||
| } | ||
|
|
||
| /** | ||
| * The accent color of this container | ||
| * @type {?number} | ||
| * @readonly | ||
| */ | ||
| get accentColor() { | ||
| return this.data.accent_color ?? null; | ||
| } | ||
|
|
||
| /** | ||
| * The hex accent color of this container | ||
| * @type {?string} | ||
| * @readonly | ||
| */ | ||
| get hexAccentColor() { | ||
| return typeof this.data.accent_color === 'number' | ||
| ? `#${this.data.accent_color.toString(16).padStart(6, '0')}` | ||
| : (this.data.accent_color ?? null); | ||
| } | ||
|
|
||
| /** | ||
| * Whether this container is spoilered | ||
| * @type {boolean} | ||
| * @readonly | ||
| */ | ||
| get spoiler() { | ||
| return this.data.spoiler ?? false; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the API-compatible JSON for this component | ||
| * @returns {APIContainerComponent} | ||
| */ | ||
| toJSON() { | ||
| return { ...this.data, components: this.components.map(component => component.toJSON()) }; | ||
| } | ||
| } | ||
|
|
||
| module.exports = ContainerComponent; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| 'use strict'; | ||
|
|
||
| const Component = require('./Component'); | ||
| const UnfurledMediaItem = require('./UnfurledMediaItem'); | ||
|
|
||
| /** | ||
| * Represents a file component | ||
| * @extends {Component} | ||
| */ | ||
| class FileComponent extends Component { | ||
| constructor({ file, ...data }) { | ||
| super(data); | ||
|
|
||
| /** | ||
| * The media associated with this file | ||
| * @type {UnfurledMediaItem} | ||
| * @readonly | ||
| */ | ||
| this.file = new UnfurledMediaItem(file); | ||
| } | ||
|
|
||
| /** | ||
| * Whether this thumbnail is spoilered | ||
| * @type {boolean} | ||
| * @readonly | ||
| */ | ||
| get spoiler() { | ||
| return this.data.spoiler ?? false; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the API-compatible JSON for this component | ||
| * @returns {APIFileComponent} | ||
| */ | ||
| toJSON() { | ||
| return { ...this.data, file: this.file.toJSON() }; | ||
| } | ||
| } | ||
|
|
||
| module.exports = FileComponent; |
31 changes: 31 additions & 0 deletions
31
packages/discord.js/src/structures/MediaGalleryComponent.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| 'use strict'; | ||
|
|
||
| const Component = require('./Component'); | ||
| const MediaGalleryItem = require('./MediaGalleryItem'); | ||
|
|
||
| /** | ||
| * Represents a media gallery component | ||
| * @extends {Component} | ||
| */ | ||
| class MediaGalleryComponent extends Component { | ||
| constructor({ items, ...data }) { | ||
| super(data); | ||
|
|
||
| /** | ||
| * The items in this media gallery | ||
| * @type {MediaGalleryItem[]} | ||
| * @readonly | ||
| */ | ||
| this.items = items.map(item => new MediaGalleryItem(item)); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the API-compatible JSON for this component | ||
| * @returns {APIMediaGalleryComponent} | ||
| */ | ||
| toJSON() { | ||
| return { ...this.data, items: this.items.map(item => item.toJSON()) }; | ||
| } | ||
| } | ||
|
|
||
| module.exports = MediaGalleryComponent; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| 'use strict'; | ||
|
|
||
| const UnfurledMediaItem = require('./UnfurledMediaItem'); | ||
|
|
||
| /** | ||
| * Represents an item in a media gallery | ||
| */ | ||
| class MediaGalleryItem { | ||
| constructor({ media, ...data }) { | ||
| /** | ||
| * The API data associated with this component | ||
| * @type {APIMediaGalleryItem} | ||
| */ | ||
| this.data = data; | ||
|
|
||
| /** | ||
| * The media associated with this media gallery item | ||
| * @type {UnfurledMediaItem} | ||
| * @readonly | ||
| */ | ||
| this.media = new UnfurledMediaItem(media); | ||
| } | ||
|
|
||
| /** | ||
| * The description of this media gallery item | ||
| * @type {?string} | ||
| * @readonly | ||
| */ | ||
| get description() { | ||
| return this.data.description ?? null; | ||
| } | ||
|
|
||
| /** | ||
| * Whether this media gallery item is spoilered | ||
| * @type {boolean} | ||
| * @readonly | ||
| */ | ||
| get spoiler() { | ||
| return this.data.spoiler ?? false; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the API-compatible JSON for this component | ||
| * @returns {APIMediaGalleryItem} | ||
| */ | ||
| toJSON() { | ||
| return { ...this.data, media: this.media.toJSON() }; | ||
| } | ||
| } | ||
|
|
||
| module.exports = MediaGalleryItem; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.