@ovencord/builders 1.11.1 → 1.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@ovencord/builders",
4
- "version": "1.11.1",
4
+ "version": "1.11.2",
5
5
  "description": "A set of builders that you can use when creating your bot",
6
6
  "scripts": {
7
7
  "test": "bun test",
@@ -14,6 +14,8 @@ import {
14
14
  SecondaryButtonBuilder,
15
15
  SuccessButtonBuilder,
16
16
  } from './button/CustomIdButton.js';
17
+ import { ButtonBuilder } from './button/ButtonBuilder.js';
18
+ export { ButtonBuilder };
17
19
  import { LinkButtonBuilder } from './button/LinkButton.js';
18
20
  import { PremiumButtonBuilder } from './button/PremiumButton.js';
19
21
  import { FileUploadBuilder } from './fileUpload/FileUpload.js';
@@ -61,16 +63,7 @@ export type ModalComponentBuilder =
61
63
  | LabelBuilder
62
64
  | ModalActionRowComponentBuilder;
63
65
 
64
- /**
65
- * Any button builder
66
- */
67
- export type ButtonBuilder =
68
- | DangerButtonBuilder
69
- | LinkButtonBuilder
70
- | PremiumButtonBuilder
71
- | PrimaryButtonBuilder
72
- | SecondaryButtonBuilder
73
- | SuccessButtonBuilder;
66
+ // Any button builder is already covered by the ButtonBuilder class
74
67
 
75
68
  /**
76
69
  * The builders that may be used within an action row for messages.
@@ -0,0 +1,59 @@
1
+ import { ButtonStyle, ComponentType, type APIButtonComponent } from 'discord-api-types/v10';
2
+ import { Mixin } from 'ts-mixer';
3
+ import { BaseButtonBuilder } from './Button.js';
4
+ import { EmojiOrLabelButtonMixin } from './mixins/EmojiOrLabelButtonMixin.js';
5
+
6
+ /**
7
+ * A builder that creates API-compatible JSON data for buttons.
8
+ *
9
+ * @mixes {@link BaseButtonBuilder}\<{@link discord-api-types/v10#(APIButtonComponent:interface)}\>
10
+ * @mixes {@link EmojiOrLabelButtonMixin}
11
+ */
12
+ export interface ButtonBuilder extends BaseButtonBuilder<APIButtonComponent>, EmojiOrLabelButtonMixin {}
13
+
14
+ export class ButtonBuilder extends Mixin(BaseButtonBuilder<APIButtonComponent>, EmojiOrLabelButtonMixin) {
15
+ /**
16
+ * @internal
17
+ */
18
+ protected override readonly data: Partial<APIButtonComponent>;
19
+
20
+ /**
21
+ * Creates a new button builder.
22
+ *
23
+ * @param data - The API data to create this button with
24
+ */
25
+ public constructor(data: Partial<APIButtonComponent> = {}) {
26
+ super();
27
+ this.data = { ...structuredClone(data), type: ComponentType.Button };
28
+ }
29
+
30
+ /**
31
+ * Sets the custom id for this button.
32
+ *
33
+ * @param customId - The custom id to use
34
+ */
35
+ public setCustomId(customId: string) {
36
+ this.data.custom_id = customId;
37
+ return this;
38
+ }
39
+
40
+ /**
41
+ * Sets the style for this button.
42
+ *
43
+ * @param style - The style to use
44
+ */
45
+ public setStyle(style: ButtonStyle) {
46
+ this.data.style = style;
47
+ return this;
48
+ }
49
+
50
+ /**
51
+ * Sets the URL for this button.
52
+ *
53
+ * @param url - The URL to use
54
+ */
55
+ public setURL(url: string) {
56
+ this.data.url = url;
57
+ return this;
58
+ }
59
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './components/button/mixins/EmojiOrLabelButtonMixin.js';
2
2
  export * from './components/button/Button.js';
3
+ export * from './components/button/ButtonBuilder.js';
3
4
  export * from './components/button/CustomIdButton.js';
4
5
  export * from './components/button/LinkButton.js';
5
6
  export * from './components/button/PremiumButton.js';