gralonium 0.4.0 → 0.5.0

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.
Files changed (40) hide show
  1. package/lib/classes/Client.d.ts +13 -3
  2. package/lib/classes/Client.js +23 -1
  3. package/lib/classes/Context.d.ts +2 -0
  4. package/lib/classes/Context.js +94 -21
  5. package/lib/classes/Cooldowns.d.ts +2 -0
  6. package/lib/classes/Cooldowns.js +28 -0
  7. package/lib/classes/Loader.d.ts +12 -3
  8. package/lib/classes/Loader.js +141 -19
  9. package/lib/classes/Plugins.js +3 -2
  10. package/lib/classes/Utils.d.ts +1 -1
  11. package/lib/classes/Utils.js +110 -20
  12. package/lib/classes/builders/CommandBuilder.d.ts +14 -0
  13. package/lib/classes/builders/CommandBuilder.js +50 -2
  14. package/lib/classes/builders/ComponentsV2Builder.d.ts +51 -3
  15. package/lib/classes/builders/ComponentsV2Builder.js +394 -72
  16. package/lib/classes/builders/GroupBuilder.d.ts +11 -0
  17. package/lib/classes/builders/GroupBuilder.js +21 -1
  18. package/lib/classes/builders/InteractionBuilder.d.ts +47 -0
  19. package/lib/classes/builders/InteractionBuilder.js +113 -2
  20. package/lib/classes/builders/ParamsBuilder.d.ts +118 -76
  21. package/lib/classes/builders/ParamsBuilder.js +167 -1
  22. package/lib/classes/builders/components/StyleMapper.d.ts +13 -1
  23. package/lib/classes/builders/components/StyleMapper.js +33 -8
  24. package/lib/classes/builders/components/helpers.d.ts +3 -0
  25. package/lib/classes/builders/components/helpers.js +56 -3
  26. package/lib/classes/builders/components/linter.d.ts +61 -0
  27. package/lib/classes/builders/components/linter.js +252 -0
  28. package/lib/classes/builders/components/overflow.d.ts +151 -0
  29. package/lib/classes/builders/components/overflow.js +534 -0
  30. package/lib/classes/views/V2Adaptive.d.ts +103 -0
  31. package/lib/classes/views/V2Adaptive.js +502 -0
  32. package/lib/classes/views/V2PersistentRouter.d.ts +124 -0
  33. package/lib/classes/views/V2PersistentRouter.js +511 -0
  34. package/lib/classes/views/V2View.d.ts +1 -0
  35. package/lib/classes/views/V2View.js +53 -15
  36. package/lib/experiments.d.ts +2 -0
  37. package/lib/experiments.js +2 -0
  38. package/lib/main.d.ts +4 -0
  39. package/lib/main.js +4 -0
  40. package/package.json +1 -1
@@ -1,13 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SelectMenuProxy = exports.ComponentsV2Builder = void 0;
3
+ exports.MenuActionItemStyle =
4
+ exports.MenuActionItemBuilder =
5
+ exports.OverflowMenuGroupBuilder =
6
+ exports.OverflowMenuBuilder =
7
+ exports.OverflowMenuProxy =
8
+ exports.SelectMenuProxy =
9
+ exports.ComponentsV2Builder =
10
+ void 0;
4
11
 
5
12
  const path_1 = require("path");
6
13
  const discord_js_1 = require("discord.js");
7
14
  const helpers_js_1 = require("./components/helpers.js");
15
+ const linter_js_1 = require("./components/linter.js");
16
+ const overflow_js_1 = require("./components/overflow.js");
8
17
  const StyleMapper_js_1 = require("./components/StyleMapper.js");
9
18
  const text_js_1 = require("./components/text.js");
10
19
  const templates = require("./components/templates.js");
20
+ const V2Adaptive_js_1 = require("../views/V2Adaptive.js");
21
+
22
+ exports.OverflowMenuProxy = overflow_js_1.OverflowMenuProxy;
23
+ exports.OverflowMenuBuilder = overflow_js_1.OverflowMenuBuilder;
24
+ exports.OverflowMenuGroupBuilder = overflow_js_1.OverflowMenuGroupBuilder;
25
+ exports.MenuActionItemBuilder = overflow_js_1.MenuActionItemBuilder;
26
+ exports.MenuActionItemStyle = overflow_js_1.MenuActionItemStyle;
11
27
 
12
28
  const SELECT_TYPE_MAP = {
13
29
  string: "string",
@@ -171,6 +187,8 @@ class ComponentsV2Builder {
171
187
  static text = text_js_1.V2Text;
172
188
  static clipText = helpers_js_1.clipText;
173
189
  static resolveColor = helpers_js_1.resolveAccentColor;
190
+ static setDefaultButtonStyle = StyleMapper_js_1.setDefaultButtonStyle;
191
+ static getDefaultButtonStyle = StyleMapper_js_1.getDefaultButtonStyle;
174
192
  static parseEmoji = helpers_js_1.parseEmoji;
175
193
  static isValidMediaUrl = helpers_js_1.isValidMediaUrl;
176
194
  static isValidLinkUrl = helpers_js_1.isValidLinkUrl;
@@ -178,6 +196,11 @@ class ComponentsV2Builder {
178
196
  static disableMessageComponents = helpers_js_1.disableMessageComponents;
179
197
  static countTextLength = helpers_js_1.countTextLength;
180
198
  static countComponents = helpers_js_1.countComponents;
199
+ static lint = linter_js_1.lintComponents;
200
+ static OverflowMenuBuilder = overflow_js_1.OverflowMenuBuilder;
201
+ static OverflowMenuGroupBuilder = overflow_js_1.OverflowMenuGroupBuilder;
202
+ static MenuActionItemBuilder = overflow_js_1.MenuActionItemBuilder;
203
+ static MenuActionItemStyle = overflow_js_1.MenuActionItemStyle;
181
204
 
182
205
  static isBuilder(value) {
183
206
  return Boolean(
@@ -205,11 +228,38 @@ class ComponentsV2Builder {
205
228
  return {
206
229
  kind: "container",
207
230
  builder: container,
231
+ items: [],
208
232
  hasContent: false,
233
+ hasOverflow: false,
209
234
  attached: false,
210
235
  };
211
236
  }
212
237
 
238
+ #addComponentToContainer(c, kind, component) {
239
+ switch (kind) {
240
+ case "text":
241
+ c.addTextDisplayComponents(component);
242
+ break;
243
+ case "separator":
244
+ c.addSeparatorComponents(component);
245
+ break;
246
+ case "section":
247
+ c.addSectionComponents(component);
248
+ break;
249
+ case "gallery":
250
+ c.addMediaGalleryComponents(component);
251
+ break;
252
+ case "file":
253
+ c.addFileComponents(component);
254
+ break;
255
+ case "actionRow":
256
+ c.addActionRowComponents(component);
257
+ break;
258
+ default:
259
+ throw new TypeError(`[ComponentsV2Builder] Unsupported component kind: ${String(kind)}`);
260
+ }
261
+ }
262
+
213
263
  #ensureContainerAttached(entry) {
214
264
  if (!entry.attached) {
215
265
  this.#topLevel.push(entry);
@@ -232,7 +282,11 @@ class ComponentsV2Builder {
232
282
 
233
283
  #appendDirect(component, kind, placement = this.#placement) {
234
284
  if (placement === "outside") {
235
- this.#topLevel.push({ kind: "outside", component });
285
+ if (kind === "overflowSection") {
286
+ this.#topLevel.push({ kind: "outsideOverflowSection", descriptor: component });
287
+ } else {
288
+ this.#topLevel.push({ kind: "outside", component });
289
+ }
236
290
  this.#lastKindByTarget.outside = kind;
237
291
  return;
238
292
  }
@@ -241,29 +295,17 @@ class ComponentsV2Builder {
241
295
  this.#ensureContainerAttached(entry);
242
296
  entry.hasContent = true;
243
297
 
244
- const c = entry.builder;
245
- switch (kind) {
246
- case "text":
247
- c.addTextDisplayComponents(component);
248
- break;
249
- case "separator":
250
- c.addSeparatorComponents(component);
251
- break;
252
- case "section":
253
- c.addSectionComponents(component);
254
- break;
255
- case "gallery":
256
- c.addMediaGalleryComponents(component);
257
- break;
258
- case "file":
259
- c.addFileComponents(component);
260
- break;
261
- case "actionRow":
262
- c.addActionRowComponents(component);
263
- break;
264
- default:
265
- throw new TypeError(`[ComponentsV2Builder] Unsupported component kind: ${String(kind)}`);
298
+ if (kind === "overflowSection") {
299
+ entry.hasOverflow = true;
300
+ entry.items.push({ kind: "overflowSection", descriptor: component });
301
+ this.#lastKindByTarget.inside = kind;
302
+ return;
303
+ }
304
+
305
+ if (Array.isArray(entry.items)) {
306
+ entry.items.push({ kind, component });
266
307
  }
308
+ this.#addComponentToContainer(entry.builder, kind, component);
267
309
  this.#lastKindByTarget.inside = kind;
268
310
  }
269
311
 
@@ -306,7 +348,7 @@ class ComponentsV2Builder {
306
348
  ? StyleMapper_js_1.mapButtonStyle(cfg.style)
307
349
  : cfg.url
308
350
  ? discord_js_1.ButtonStyle.Link
309
- : discord_js_1.ButtonStyle.Primary;
351
+ : StyleMapper_js_1.getDefaultButtonStyle();
310
352
 
311
353
  button.setStyle(resolvedStyle);
312
354
 
@@ -593,19 +635,57 @@ class ComponentsV2Builder {
593
635
  });
594
636
  }
595
637
 
638
+ #normalizeSectionTextBuilders(texts, options = {}) {
639
+ const textBuilders = [];
640
+ if (Array.isArray(texts) && texts.some((item) => item instanceof discord_js_1.TextDisplayBuilder)) {
641
+ for (const item of texts) {
642
+ if (!item) continue;
643
+ if (item instanceof discord_js_1.TextDisplayBuilder) {
644
+ textBuilders.push(item);
645
+ } else {
646
+ const str = String(item).trim();
647
+ if (str) textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(str));
648
+ }
649
+ }
650
+ } else {
651
+ const normalized = this.#normalizeTextInput(texts, options);
652
+ if (!helpers_js_1.validateTextContent(normalized, options)) {
653
+ return null;
654
+ }
655
+ const finalText = options.maxLength ? helpers_js_1.clipText(normalized, options.maxLength) : String(normalized);
656
+ textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(finalText));
657
+ }
658
+
659
+ if (textBuilders.length === 0) {
660
+ if (options.ignoreEmpty) return null;
661
+ throw new Error("[ComponentsV2Builder] Section requires at least one non-empty text display.");
662
+ }
663
+
664
+ if (textBuilders.length > 3) {
665
+ const merged = textBuilders.map((tb) => tb.data?.content || "").filter(Boolean).join("\n");
666
+ textBuilders.length = 0;
667
+ textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(merged));
668
+ }
669
+
670
+ return textBuilders;
671
+ }
672
+
596
673
  /**
597
- * Adds a Section (1-3 TextDisplay components paired with a Thumbnail or Button accessory).
674
+ * Adds a Section (1-3 TextDisplay components paired with a Thumbnail, Button, or OverflowMenu accessory).
598
675
  * Falls back to `addText` automatically when no valid accessory is supplied (unless `fallbackToText: false`).
599
676
  */
600
677
  addSection(texts, accessoryOrOptions = {}) {
601
678
  let options = {};
602
679
  let thumbnailAccessory = null;
603
680
  let buttonAccessory = null;
681
+ let overflowBuilder = null;
604
682
 
605
683
  if (accessoryOrOptions instanceof discord_js_1.ThumbnailBuilder) {
606
684
  thumbnailAccessory = accessoryOrOptions;
607
685
  } else if (accessoryOrOptions instanceof discord_js_1.ButtonBuilder) {
608
686
  buttonAccessory = accessoryOrOptions;
687
+ } else if (accessoryOrOptions instanceof overflow_js_1.OverflowMenuBuilder) {
688
+ overflowBuilder = accessoryOrOptions;
609
689
  } else if (accessoryOrOptions && typeof accessoryOrOptions === "object") {
610
690
  options = accessoryOrOptions;
611
691
  if (options.thumbnail instanceof discord_js_1.ThumbnailBuilder) {
@@ -624,31 +704,45 @@ class ComponentsV2Builder {
624
704
  if (!thumbnailAccessory && options.button) {
625
705
  buttonAccessory = this.#createButton(options.button);
626
706
  }
627
- }
628
707
 
629
- const textBuilders = [];
630
- if (Array.isArray(texts) && texts.some((item) => item instanceof discord_js_1.TextDisplayBuilder)) {
631
- for (const item of texts) {
632
- if (!item) continue;
633
- if (item instanceof discord_js_1.TextDisplayBuilder) {
634
- textBuilders.push(item);
635
- } else {
636
- const str = String(item).trim();
637
- if (str) textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(str));
708
+ if (options.overflow !== undefined && options.overflow !== null) {
709
+ if (options.overflow instanceof overflow_js_1.OverflowMenuBuilder) {
710
+ overflowBuilder = options.overflow;
711
+ } else if (typeof options.overflow === "function") {
712
+ const menu = new overflow_js_1.OverflowMenuBuilder({
713
+ placeholder: options.overflowPlaceholder ?? options.placeholder,
714
+ });
715
+ const proxy = new overflow_js_1.OverflowMenuProxy(this, menu);
716
+ const returned = options.overflow(proxy);
717
+ overflowBuilder =
718
+ returned instanceof overflow_js_1.OverflowMenuBuilder
719
+ ? returned
720
+ : typeof returned?.toBuilder === "function"
721
+ ? returned.toBuilder()
722
+ : menu;
723
+ } else if (typeof options.overflow === "object") {
724
+ overflowBuilder = new overflow_js_1.OverflowMenuBuilder({
725
+ placeholder: options.overflowPlaceholder ?? options.placeholder,
726
+ ...options.overflow,
727
+ });
638
728
  }
639
729
  }
640
- } else {
641
- const normalized = this.#normalizeTextInput(texts, options);
642
- if (!helpers_js_1.validateTextContent(normalized, options)) {
643
- return this;
644
- }
645
- const finalText = options.maxLength ? helpers_js_1.clipText(normalized, options.maxLength) : String(normalized);
646
- textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(finalText));
647
730
  }
648
731
 
649
- if (textBuilders.length === 0) {
650
- if (options.ignoreEmpty) return this;
651
- throw new Error("[ComponentsV2Builder] Section requires at least one non-empty text display.");
732
+ const textBuilders = this.#normalizeSectionTextBuilders(texts, options);
733
+ if (!textBuilders) return this;
734
+
735
+ if (overflowBuilder) {
736
+ const descriptor = {
737
+ textBuilders,
738
+ overflowBuilder,
739
+ fallbackConfig: options.overflowFallback === undefined ? "select" : options.overflowFallback,
740
+ fallbackPlaceholder: options.overflowPlaceholder ?? options.placeholder,
741
+ thumbnailAccessory,
742
+ buttonAccessory,
743
+ };
744
+ this.#appendComponent(descriptor, "overflowSection");
745
+ return this;
652
746
  }
653
747
 
654
748
  if (!thumbnailAccessory && !buttonAccessory) {
@@ -658,13 +752,7 @@ class ComponentsV2Builder {
658
752
  }
659
753
  return this;
660
754
  }
661
- throw new Error("[ComponentsV2Builder] Section requires a valid thumbnail URL or button accessory.");
662
- }
663
-
664
- if (textBuilders.length > 3) {
665
- const merged = textBuilders.map((tb) => tb.data?.content || "").filter(Boolean).join("\n");
666
- textBuilders.length = 0;
667
- textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(merged));
755
+ throw new Error("[ComponentsV2Builder] Section requires a valid thumbnail URL, button, or overflow accessory.");
668
756
  }
669
757
 
670
758
  const section = new discord_js_1.SectionBuilder().addTextDisplayComponents(...textBuilders);
@@ -678,6 +766,35 @@ class ComponentsV2Builder {
678
766
  return this;
679
767
  }
680
768
 
769
+ /**
770
+ * Starts a fluent Section paired with an OverflowMenu (`type: 25`), returning an `OverflowMenuProxy`
771
+ * whose `.end()` returns back to this `ComponentsV2Builder`.
772
+ */
773
+ addOverflowSection(texts, options = {}) {
774
+ const textBuilders = this.#normalizeSectionTextBuilders(texts, options);
775
+ const menu = new overflow_js_1.OverflowMenuBuilder({
776
+ customId: options.customId,
777
+ disabled: options.disabled,
778
+ placeholder: options.overflowPlaceholder ?? options.placeholder,
779
+ });
780
+
781
+ if (textBuilders) {
782
+ this.#appendComponent(
783
+ {
784
+ textBuilders,
785
+ overflowBuilder: menu,
786
+ fallbackConfig: options.overflowFallback === undefined ? "select" : options.overflowFallback,
787
+ fallbackPlaceholder: options.overflowPlaceholder ?? options.placeholder,
788
+ thumbnailAccessory: null,
789
+ buttonAccessory: null,
790
+ },
791
+ "overflowSection"
792
+ );
793
+ }
794
+
795
+ return new overflow_js_1.OverflowMenuProxy(this, menu);
796
+ }
797
+
681
798
  /**
682
799
  * Adds a MediaGallery component (`http://`, `https://`, or `attachment://` URLs).
683
800
  */
@@ -1049,37 +1166,187 @@ class ComponentsV2Builder {
1049
1166
  return [...this.#files];
1050
1167
  }
1051
1168
 
1052
- #snapshotComponents() {
1053
- const out = [];
1169
+ get hasOverflowMenu() {
1054
1170
  for (const entry of this.#topLevel) {
1055
- if (entry.kind === "container") {
1056
- if (entry.hasContent) out.push(entry.builder);
1057
- } else {
1058
- out.push(entry.component);
1171
+ if (entry.kind === "outsideOverflowSection") return true;
1172
+ if (entry.kind === "container" && entry.hasOverflow) return true;
1173
+ }
1174
+ return false;
1175
+ }
1176
+
1177
+ #canAnyOverflowFallback() {
1178
+ for (const entry of this.#topLevel) {
1179
+ if (entry.kind === "outsideOverflowSection") {
1180
+ if (entry.descriptor.fallbackConfig !== false && entry.descriptor.fallbackConfig !== "none") {
1181
+ return true;
1182
+ }
1183
+ }
1184
+ if (entry.kind === "container" && entry.hasOverflow && Array.isArray(entry.items)) {
1185
+ for (const item of entry.items) {
1186
+ if (
1187
+ item.kind === "overflowSection" &&
1188
+ item.descriptor.fallbackConfig !== false &&
1189
+ item.descriptor.fallbackConfig !== "none"
1190
+ ) {
1191
+ return true;
1192
+ }
1193
+ }
1059
1194
  }
1060
1195
  }
1061
- if (this.#currentRow && this.#currentRow.components?.length) {
1062
- out.push(this.#currentRow);
1196
+ return false;
1197
+ }
1198
+
1199
+ #resolveUseFallback(buildOptions = {}) {
1200
+ if (buildOptions.forceNativeOverflow) return false;
1201
+ if (buildOptions.forceOverflowFallback) return true;
1202
+ return !V2Adaptive_js_1.V2Adaptive.isOverflowAvailable();
1203
+ }
1204
+
1205
+ #buildOverflowSectionFallback(descriptor, validate = true) {
1206
+ const out = [];
1207
+ if (descriptor.thumbnailAccessory || descriptor.buttonAccessory) {
1208
+ const section = new discord_js_1.SectionBuilder().addTextDisplayComponents(...descriptor.textBuilders);
1209
+ if (descriptor.thumbnailAccessory) {
1210
+ section.setThumbnailAccessory(descriptor.thumbnailAccessory);
1211
+ } else if (descriptor.buttonAccessory) {
1212
+ section.setButtonAccessory(descriptor.buttonAccessory);
1213
+ }
1214
+ out.push({ kind: "section", component: section });
1215
+ } else {
1216
+ for (const tb of descriptor.textBuilders) {
1217
+ out.push({ kind: "text", component: tb });
1218
+ }
1219
+ }
1220
+
1221
+ if (descriptor.fallbackConfig !== false && descriptor.fallbackConfig !== "none") {
1222
+ const cfg =
1223
+ typeof descriptor.fallbackConfig === "object"
1224
+ ? descriptor.fallbackConfig
1225
+ : { mode: typeof descriptor.fallbackConfig === "string" ? descriptor.fallbackConfig : "select" };
1226
+ const rows = descriptor.overflowBuilder.toFallbackComponents({
1227
+ placeholder: descriptor.fallbackPlaceholder,
1228
+ validate,
1229
+ ...cfg,
1230
+ });
1231
+ for (const row of rows) {
1232
+ out.push({ kind: "actionRow", component: row });
1233
+ }
1063
1234
  }
1064
1235
  return out;
1065
1236
  }
1066
1237
 
1067
- /**
1068
- * Builds and returns the array of top-level discord.js V2 component builders.
1069
- */
1070
- build() {
1071
- this.#flushPendingRow();
1238
+ #buildOverflowSectionNative(descriptor, validate = true) {
1239
+ return {
1240
+ type: discord_js_1.ComponentType?.Section ?? 9,
1241
+ components: descriptor.textBuilders.map((tb) => tb.toJSON()),
1242
+ accessory: descriptor.overflowBuilder.toJSON({ validate }),
1243
+ };
1244
+ }
1245
+
1246
+ #buildComponentsInternal(buildOptions = {}, includePendingRow = false) {
1247
+ const useFallback = this.#resolveUseFallback(buildOptions);
1248
+ const validate = buildOptions.validate !== false;
1072
1249
  const result = [];
1250
+
1073
1251
  for (const entry of this.#topLevel) {
1074
1252
  if (entry.kind === "container") {
1075
- if (entry.hasContent) {
1253
+ if (!entry.hasContent) continue;
1254
+
1255
+ if (!entry.hasOverflow || !Array.isArray(entry.items)) {
1076
1256
  result.push(entry.builder);
1257
+ continue;
1077
1258
  }
1078
- } else {
1079
- result.push(entry.component);
1259
+
1260
+ if (useFallback) {
1261
+ const fallbackContainer = new discord_js_1.ContainerBuilder();
1262
+ if (entry.builder.data?.accent_color !== undefined && entry.builder.data?.accent_color !== null) {
1263
+ fallbackContainer.setAccentColor(entry.builder.data.accent_color);
1264
+ }
1265
+ if (entry.builder.data?.spoiler !== undefined) {
1266
+ fallbackContainer.setSpoiler(Boolean(entry.builder.data.spoiler));
1267
+ }
1268
+ for (const item of entry.items) {
1269
+ if (item.kind === "overflowSection") {
1270
+ for (const expanded of this.#buildOverflowSectionFallback(item.descriptor, validate)) {
1271
+ this.#addComponentToContainer(fallbackContainer, expanded.kind, expanded.component);
1272
+ }
1273
+ } else {
1274
+ this.#addComponentToContainer(fallbackContainer, item.kind, item.component);
1275
+ }
1276
+ }
1277
+ result.push(fallbackContainer);
1278
+ continue;
1279
+ }
1280
+
1281
+ const serializedChildren = [];
1282
+ for (const item of entry.items) {
1283
+ if (item.kind === "overflowSection") {
1284
+ serializedChildren.push(this.#buildOverflowSectionNative(item.descriptor, validate));
1285
+ } else {
1286
+ serializedChildren.push(
1287
+ typeof item.component?.toJSON === "function" ? item.component.toJSON() : item.component
1288
+ );
1289
+ }
1290
+ }
1291
+
1292
+ const rawContainer = {
1293
+ type: discord_js_1.ComponentType?.Container ?? 17,
1294
+ ...(entry.builder.data?.accent_color !== undefined && entry.builder.data?.accent_color !== null
1295
+ ? { accent_color: entry.builder.data.accent_color }
1296
+ : {}),
1297
+ ...(entry.builder.data?.spoiler !== undefined ? { spoiler: Boolean(entry.builder.data.spoiler) } : {}),
1298
+ components: serializedChildren,
1299
+ };
1300
+ result.push({
1301
+ ...rawContainer,
1302
+ data: rawContainer,
1303
+ toJSON() {
1304
+ return rawContainer;
1305
+ },
1306
+ });
1307
+ continue;
1308
+ }
1309
+
1310
+ if (entry.kind === "outsideOverflowSection") {
1311
+ if (useFallback) {
1312
+ for (const expanded of this.#buildOverflowSectionFallback(entry.descriptor, validate)) {
1313
+ result.push(expanded.component);
1314
+ }
1315
+ } else {
1316
+ const nativeSection = this.#buildOverflowSectionNative(entry.descriptor, validate);
1317
+ result.push({
1318
+ ...nativeSection,
1319
+ data: nativeSection,
1320
+ toJSON() {
1321
+ return nativeSection;
1322
+ },
1323
+ });
1324
+ }
1325
+ continue;
1080
1326
  }
1327
+
1328
+ result.push(entry.component);
1081
1329
  }
1082
1330
 
1331
+ if (includePendingRow && this.#currentRow && this.#currentRow.components?.length) {
1332
+ result.push(this.#currentRow);
1333
+ }
1334
+
1335
+ return result;
1336
+ }
1337
+
1338
+ #snapshotComponents() {
1339
+ return this.#buildComponentsInternal({ validate: false }, true);
1340
+ }
1341
+
1342
+ /**
1343
+ * Builds and returns the array of top-level discord.js V2 component builders (or raw V2 wrappers
1344
+ * when native OverflowMenu `type: 25` sections are present).
1345
+ */
1346
+ build(options = {}) {
1347
+ this.#flushPendingRow();
1348
+ const result = this.#buildComponentsInternal(options, false);
1349
+
1083
1350
  if (result.length === 0 && this.#topLevel.length === 0) {
1084
1351
  return [this.#activeContainerEntry.builder];
1085
1352
  }
@@ -1090,8 +1357,16 @@ class ComponentsV2Builder {
1090
1357
  /**
1091
1358
  * Serializes the built top-level components into plain JSON objects.
1092
1359
  */
1093
- toJSON() {
1094
- return this.build().map((comp) => (typeof comp?.toJSON === "function" ? comp.toJSON() : comp));
1360
+ toJSON(options = {}) {
1361
+ return this.build(options).map((comp) => (typeof comp?.toJSON === "function" ? comp.toJSON() : comp));
1362
+ }
1363
+
1364
+ /**
1365
+ * Runs static V2 diagnostics (component/text limits, duplicate or oversized custom_ids,
1366
+ * overflow hygiene, and Game Mode animated-emoji checks).
1367
+ */
1368
+ lint(options = {}) {
1369
+ return linter_js_1.lintComponents(this, options);
1095
1370
  }
1096
1371
 
1097
1372
  /**
@@ -1099,7 +1374,12 @@ class ComponentsV2Builder {
1099
1374
  * optional ephemeral/notification flags, attached files, and safe `allowedMentions`.
1100
1375
  */
1101
1376
  toPayload(options = {}) {
1102
- const components = this.build();
1377
+ const useFallback = this.#resolveUseFallback(options);
1378
+ const components = this.build({
1379
+ ...options,
1380
+ forceOverflowFallback: useFallback,
1381
+ forceNativeOverflow: !useFallback,
1382
+ });
1103
1383
  let flags = discord_js_1.MessageFlags.IsComponentsV2;
1104
1384
 
1105
1385
  if (options.ephemeral) {
@@ -1131,9 +1411,51 @@ class ComponentsV2Builder {
1131
1411
  payload.allowedMentions = { parse: [], repliedUser: false };
1132
1412
  }
1133
1413
 
1414
+ if (this.hasOverflowMenu) {
1415
+ V2Adaptive_js_1.V2Adaptive.attachOverflowSource(payload, {
1416
+ builder: this,
1417
+ options,
1418
+ usedNativeOverflow: !useFallback,
1419
+ canFallback: this.#canAnyOverflowFallback(),
1420
+ });
1421
+ }
1422
+
1134
1423
  return payload;
1135
1424
  }
1136
1425
 
1426
+ /**
1427
+ * Sends this builder through a Context, TextBasedChannel, Interaction, or custom sender function
1428
+ * with automatic `V2Adaptive` fallback when Discord rejects native `type: 25` (`50035`).
1429
+ */
1430
+ async send(target, options = {}) {
1431
+ return V2Adaptive_js_1.V2Adaptive.send(target, this, options);
1432
+ }
1433
+
1434
+ /**
1435
+ * Edits an existing Message or Interaction reply using `V2Adaptive` fallback protection.
1436
+ */
1437
+ async edit(target, options = {}) {
1438
+ if (!target || typeof target !== "object") {
1439
+ throw new TypeError("[ComponentsV2Builder] edit() requires a Message or Interaction target.");
1440
+ }
1441
+ return V2Adaptive_js_1.V2Adaptive.executeWithFallback(
1442
+ this,
1443
+ (payload) => {
1444
+ if (typeof target.editReply === "function" && (target.deferred || target.replied)) {
1445
+ return target.editReply(payload);
1446
+ }
1447
+ if (typeof target.update === "function" && !target.replied && !target.deferred) {
1448
+ return target.update(payload);
1449
+ }
1450
+ if (typeof target.edit === "function") {
1451
+ return target.edit(payload);
1452
+ }
1453
+ throw new TypeError("[ComponentsV2Builder] Target does not support edit(), editReply(), or update().");
1454
+ },
1455
+ options
1456
+ );
1457
+ }
1458
+
1137
1459
  // =========================================================================
1138
1460
  // Agnostic & legacy static template factories
1139
1461
  // =========================================================================
@@ -1,4 +1,5 @@
1
1
  import type { ApplicationIntegrationType, InteractionContextType } from "discord.js";
2
+ import type { LocalizationMap } from "./CommandBuilder.js";
2
3
  import { Command, Types } from "../Loader.js";
3
4
 
4
5
  type GroupBuilderOptions = {
@@ -14,6 +15,10 @@ type GroupBuilderOptions = {
14
15
  guards?: Array<(ctx: any) => boolean | Promise<boolean>>;
15
16
  integrationTypes?: Array<ApplicationIntegrationType | number>;
16
17
  contexts?: Array<InteractionContextType | number>;
18
+ nameLocalizations?: LocalizationMap;
19
+ name_localizations?: LocalizationMap;
20
+ descriptionLocalizations?: LocalizationMap;
21
+ description_localizations?: LocalizationMap;
17
22
  };
18
23
 
19
24
  export declare class GroupBuilder {
@@ -30,6 +35,8 @@ export declare class GroupBuilder {
30
35
  guards: Array<(ctx: any) => boolean | Promise<boolean>>;
31
36
  integrationTypes?: Array<ApplicationIntegrationType | number>;
32
37
  contexts?: Array<InteractionContextType | number>;
38
+ nameLocalizations?: LocalizationMap;
39
+ descriptionLocalizations?: LocalizationMap;
33
40
  constructor(ops?: GroupBuilderOptions);
34
41
  setName(name: string): GroupBuilder;
35
42
  setDescription(description: string): GroupBuilder;
@@ -41,12 +48,16 @@ export declare class GroupBuilder {
41
48
  allowSlash(allow: boolean): GroupBuilder;
42
49
  setIntegrationTypes(...types: Array<ApplicationIntegrationType | number | Array<ApplicationIntegrationType | number>>): GroupBuilder;
43
50
  setContexts(...contexts: Array<InteractionContextType | number | Array<InteractionContextType | number>>): GroupBuilder;
51
+ setNameLocalizations(locales?: LocalizationMap | null): GroupBuilder;
52
+ setDescriptionLocalizations(locales?: LocalizationMap | null): GroupBuilder;
44
53
  toJSON(): {
45
54
  name: string;
46
55
  description: string;
47
56
  options: any[];
48
57
  default_member_permissions: string | null | undefined;
49
58
  dm_permission: boolean | undefined;
59
+ name_localizations?: LocalizationMap;
60
+ description_localizations?: LocalizationMap;
50
61
  integration_types?: Array<ApplicationIntegrationType | number>;
51
62
  contexts?: Array<InteractionContextType | number>;
52
63
  };