gralonium 0.4.1 → 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.
- package/lib/classes/Client.d.ts +7 -1
- package/lib/classes/Client.js +22 -0
- package/lib/classes/Context.js +68 -19
- package/lib/classes/Loader.d.ts +4 -2
- package/lib/classes/Loader.js +40 -0
- package/lib/classes/Utils.js +37 -7
- package/lib/classes/builders/ComponentsV2Builder.d.ts +48 -3
- package/lib/classes/builders/ComponentsV2Builder.js +391 -71
- package/lib/classes/builders/InteractionBuilder.d.ts +1 -0
- package/lib/classes/builders/InteractionBuilder.js +1 -0
- package/lib/classes/builders/components/helpers.d.ts +3 -0
- package/lib/classes/builders/components/helpers.js +56 -3
- package/lib/classes/builders/components/linter.d.ts +61 -0
- package/lib/classes/builders/components/linter.js +252 -0
- package/lib/classes/builders/components/overflow.d.ts +151 -0
- package/lib/classes/builders/components/overflow.js +534 -0
- package/lib/classes/views/V2Adaptive.d.ts +103 -0
- package/lib/classes/views/V2Adaptive.js +502 -0
- package/lib/classes/views/V2PersistentRouter.d.ts +124 -0
- package/lib/classes/views/V2PersistentRouter.js +511 -0
- package/lib/classes/views/V2View.d.ts +1 -0
- package/lib/classes/views/V2View.js +53 -15
- package/lib/experiments.d.ts +2 -0
- package/lib/experiments.js +2 -0
- package/lib/main.d.ts +4 -0
- package/lib/main.js +4 -0
- package/package.json +1 -1
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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",
|
|
@@ -180,6 +196,11 @@ class ComponentsV2Builder {
|
|
|
180
196
|
static disableMessageComponents = helpers_js_1.disableMessageComponents;
|
|
181
197
|
static countTextLength = helpers_js_1.countTextLength;
|
|
182
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;
|
|
183
204
|
|
|
184
205
|
static isBuilder(value) {
|
|
185
206
|
return Boolean(
|
|
@@ -207,11 +228,38 @@ class ComponentsV2Builder {
|
|
|
207
228
|
return {
|
|
208
229
|
kind: "container",
|
|
209
230
|
builder: container,
|
|
231
|
+
items: [],
|
|
210
232
|
hasContent: false,
|
|
233
|
+
hasOverflow: false,
|
|
211
234
|
attached: false,
|
|
212
235
|
};
|
|
213
236
|
}
|
|
214
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
|
+
|
|
215
263
|
#ensureContainerAttached(entry) {
|
|
216
264
|
if (!entry.attached) {
|
|
217
265
|
this.#topLevel.push(entry);
|
|
@@ -234,7 +282,11 @@ class ComponentsV2Builder {
|
|
|
234
282
|
|
|
235
283
|
#appendDirect(component, kind, placement = this.#placement) {
|
|
236
284
|
if (placement === "outside") {
|
|
237
|
-
|
|
285
|
+
if (kind === "overflowSection") {
|
|
286
|
+
this.#topLevel.push({ kind: "outsideOverflowSection", descriptor: component });
|
|
287
|
+
} else {
|
|
288
|
+
this.#topLevel.push({ kind: "outside", component });
|
|
289
|
+
}
|
|
238
290
|
this.#lastKindByTarget.outside = kind;
|
|
239
291
|
return;
|
|
240
292
|
}
|
|
@@ -243,29 +295,17 @@ class ComponentsV2Builder {
|
|
|
243
295
|
this.#ensureContainerAttached(entry);
|
|
244
296
|
entry.hasContent = true;
|
|
245
297
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
c.addSectionComponents(component);
|
|
256
|
-
break;
|
|
257
|
-
case "gallery":
|
|
258
|
-
c.addMediaGalleryComponents(component);
|
|
259
|
-
break;
|
|
260
|
-
case "file":
|
|
261
|
-
c.addFileComponents(component);
|
|
262
|
-
break;
|
|
263
|
-
case "actionRow":
|
|
264
|
-
c.addActionRowComponents(component);
|
|
265
|
-
break;
|
|
266
|
-
default:
|
|
267
|
-
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 });
|
|
268
307
|
}
|
|
308
|
+
this.#addComponentToContainer(entry.builder, kind, component);
|
|
269
309
|
this.#lastKindByTarget.inside = kind;
|
|
270
310
|
}
|
|
271
311
|
|
|
@@ -595,19 +635,57 @@ class ComponentsV2Builder {
|
|
|
595
635
|
});
|
|
596
636
|
}
|
|
597
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
|
+
|
|
598
673
|
/**
|
|
599
|
-
* Adds a Section (1-3 TextDisplay components paired with a Thumbnail or
|
|
674
|
+
* Adds a Section (1-3 TextDisplay components paired with a Thumbnail, Button, or OverflowMenu accessory).
|
|
600
675
|
* Falls back to `addText` automatically when no valid accessory is supplied (unless `fallbackToText: false`).
|
|
601
676
|
*/
|
|
602
677
|
addSection(texts, accessoryOrOptions = {}) {
|
|
603
678
|
let options = {};
|
|
604
679
|
let thumbnailAccessory = null;
|
|
605
680
|
let buttonAccessory = null;
|
|
681
|
+
let overflowBuilder = null;
|
|
606
682
|
|
|
607
683
|
if (accessoryOrOptions instanceof discord_js_1.ThumbnailBuilder) {
|
|
608
684
|
thumbnailAccessory = accessoryOrOptions;
|
|
609
685
|
} else if (accessoryOrOptions instanceof discord_js_1.ButtonBuilder) {
|
|
610
686
|
buttonAccessory = accessoryOrOptions;
|
|
687
|
+
} else if (accessoryOrOptions instanceof overflow_js_1.OverflowMenuBuilder) {
|
|
688
|
+
overflowBuilder = accessoryOrOptions;
|
|
611
689
|
} else if (accessoryOrOptions && typeof accessoryOrOptions === "object") {
|
|
612
690
|
options = accessoryOrOptions;
|
|
613
691
|
if (options.thumbnail instanceof discord_js_1.ThumbnailBuilder) {
|
|
@@ -626,31 +704,45 @@ class ComponentsV2Builder {
|
|
|
626
704
|
if (!thumbnailAccessory && options.button) {
|
|
627
705
|
buttonAccessory = this.#createButton(options.button);
|
|
628
706
|
}
|
|
629
|
-
}
|
|
630
707
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
if (
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
const
|
|
639
|
-
|
|
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
|
+
});
|
|
640
728
|
}
|
|
641
729
|
}
|
|
642
|
-
} else {
|
|
643
|
-
const normalized = this.#normalizeTextInput(texts, options);
|
|
644
|
-
if (!helpers_js_1.validateTextContent(normalized, options)) {
|
|
645
|
-
return this;
|
|
646
|
-
}
|
|
647
|
-
const finalText = options.maxLength ? helpers_js_1.clipText(normalized, options.maxLength) : String(normalized);
|
|
648
|
-
textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(finalText));
|
|
649
730
|
}
|
|
650
731
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
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;
|
|
654
746
|
}
|
|
655
747
|
|
|
656
748
|
if (!thumbnailAccessory && !buttonAccessory) {
|
|
@@ -660,13 +752,7 @@ class ComponentsV2Builder {
|
|
|
660
752
|
}
|
|
661
753
|
return this;
|
|
662
754
|
}
|
|
663
|
-
throw new Error("[ComponentsV2Builder] Section requires a valid thumbnail URL or
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
if (textBuilders.length > 3) {
|
|
667
|
-
const merged = textBuilders.map((tb) => tb.data?.content || "").filter(Boolean).join("\n");
|
|
668
|
-
textBuilders.length = 0;
|
|
669
|
-
textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(merged));
|
|
755
|
+
throw new Error("[ComponentsV2Builder] Section requires a valid thumbnail URL, button, or overflow accessory.");
|
|
670
756
|
}
|
|
671
757
|
|
|
672
758
|
const section = new discord_js_1.SectionBuilder().addTextDisplayComponents(...textBuilders);
|
|
@@ -680,6 +766,35 @@ class ComponentsV2Builder {
|
|
|
680
766
|
return this;
|
|
681
767
|
}
|
|
682
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
|
+
|
|
683
798
|
/**
|
|
684
799
|
* Adds a MediaGallery component (`http://`, `https://`, or `attachment://` URLs).
|
|
685
800
|
*/
|
|
@@ -1051,37 +1166,187 @@ class ComponentsV2Builder {
|
|
|
1051
1166
|
return [...this.#files];
|
|
1052
1167
|
}
|
|
1053
1168
|
|
|
1054
|
-
|
|
1055
|
-
const out = [];
|
|
1169
|
+
get hasOverflowMenu() {
|
|
1056
1170
|
for (const entry of this.#topLevel) {
|
|
1057
|
-
if (entry.kind === "
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
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
|
+
}
|
|
1061
1194
|
}
|
|
1062
1195
|
}
|
|
1063
|
-
|
|
1064
|
-
|
|
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
|
+
}
|
|
1065
1234
|
}
|
|
1066
1235
|
return out;
|
|
1067
1236
|
}
|
|
1068
1237
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
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;
|
|
1074
1249
|
const result = [];
|
|
1250
|
+
|
|
1075
1251
|
for (const entry of this.#topLevel) {
|
|
1076
1252
|
if (entry.kind === "container") {
|
|
1077
|
-
if (entry.hasContent)
|
|
1253
|
+
if (!entry.hasContent) continue;
|
|
1254
|
+
|
|
1255
|
+
if (!entry.hasOverflow || !Array.isArray(entry.items)) {
|
|
1078
1256
|
result.push(entry.builder);
|
|
1257
|
+
continue;
|
|
1079
1258
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
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;
|
|
1082
1326
|
}
|
|
1327
|
+
|
|
1328
|
+
result.push(entry.component);
|
|
1083
1329
|
}
|
|
1084
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
|
+
|
|
1085
1350
|
if (result.length === 0 && this.#topLevel.length === 0) {
|
|
1086
1351
|
return [this.#activeContainerEntry.builder];
|
|
1087
1352
|
}
|
|
@@ -1092,8 +1357,16 @@ class ComponentsV2Builder {
|
|
|
1092
1357
|
/**
|
|
1093
1358
|
* Serializes the built top-level components into plain JSON objects.
|
|
1094
1359
|
*/
|
|
1095
|
-
toJSON() {
|
|
1096
|
-
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);
|
|
1097
1370
|
}
|
|
1098
1371
|
|
|
1099
1372
|
/**
|
|
@@ -1101,7 +1374,12 @@ class ComponentsV2Builder {
|
|
|
1101
1374
|
* optional ephemeral/notification flags, attached files, and safe `allowedMentions`.
|
|
1102
1375
|
*/
|
|
1103
1376
|
toPayload(options = {}) {
|
|
1104
|
-
const
|
|
1377
|
+
const useFallback = this.#resolveUseFallback(options);
|
|
1378
|
+
const components = this.build({
|
|
1379
|
+
...options,
|
|
1380
|
+
forceOverflowFallback: useFallback,
|
|
1381
|
+
forceNativeOverflow: !useFallback,
|
|
1382
|
+
});
|
|
1105
1383
|
let flags = discord_js_1.MessageFlags.IsComponentsV2;
|
|
1106
1384
|
|
|
1107
1385
|
if (options.ephemeral) {
|
|
@@ -1133,9 +1411,51 @@ class ComponentsV2Builder {
|
|
|
1133
1411
|
payload.allowedMentions = { parse: [], repliedUser: false };
|
|
1134
1412
|
}
|
|
1135
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
|
+
|
|
1136
1423
|
return payload;
|
|
1137
1424
|
}
|
|
1138
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
|
+
|
|
1139
1459
|
// =========================================================================
|
|
1140
1460
|
// Agnostic & legacy static template factories
|
|
1141
1461
|
// =========================================================================
|
|
@@ -8,6 +8,7 @@ export declare enum Interactions {
|
|
|
8
8
|
ChatInput = "chatInput",
|
|
9
9
|
MessageContextMenu = "messageContextMenu",
|
|
10
10
|
Modal = "modalSubmit",
|
|
11
|
+
OverflowMenu = "overflowMenu",
|
|
11
12
|
UserContextMenu = "userContextMenu",
|
|
12
13
|
ChannelSelectMenu = "channelSelectMenu",
|
|
13
14
|
RoleSelectMenu = "roleSelectMenu",
|
|
@@ -13,6 +13,7 @@ var Interactions;
|
|
|
13
13
|
Interactions.ChatInput = "chatInput";
|
|
14
14
|
Interactions.MessageContextMenu = "messageContextMenu";
|
|
15
15
|
Interactions.Modal = "modalSubmit";
|
|
16
|
+
Interactions.OverflowMenu = "overflowMenu";
|
|
16
17
|
Interactions.UserContextMenu = "userContextMenu";
|
|
17
18
|
Interactions.ChannelSelectMenu = "channelSelectMenu";
|
|
18
19
|
Interactions.RoleSelectMenu = "roleSelectMenu";
|
|
@@ -4,6 +4,8 @@ export declare const MAX_V2_TEXT_LENGTH = 4000;
|
|
|
4
4
|
export declare const SAFE_V2_TEXT_LENGTH = 3950;
|
|
5
5
|
export declare const MAX_V2_COMPONENTS = 40;
|
|
6
6
|
export declare const MAX_V2_TOP_LEVEL_COMPONENTS = 10;
|
|
7
|
+
export declare const OVERFLOW_MENU_TYPE = 25;
|
|
8
|
+
export declare const MENU_ACTION_ITEM_TYPE = 26;
|
|
7
9
|
|
|
8
10
|
export type AccentColorInput = number | string | RGBTuple | null | undefined;
|
|
9
11
|
export type EmojiInput = string | APIMessageComponentEmoji | null | undefined;
|
|
@@ -12,6 +14,7 @@ export interface DisableComponentsOptions {
|
|
|
12
14
|
disableButtons?: boolean;
|
|
13
15
|
disableSelects?: boolean;
|
|
14
16
|
disableLinks?: boolean;
|
|
17
|
+
disableOverflow?: boolean;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
/**
|