@minesa-org/mini-interaction 0.3.7 → 0.3.9
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.
|
@@ -63,44 +63,71 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
63
63
|
};
|
|
64
64
|
const getResponse = () => capturedResponse;
|
|
65
65
|
const getTextFieldValue = (customId) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (component.custom_id === customId &&
|
|
72
|
-
typeof component.value === "string") {
|
|
73
|
-
return component.value;
|
|
74
|
-
}
|
|
66
|
+
const findValue = (components) => {
|
|
67
|
+
for (const component of components) {
|
|
68
|
+
if (component?.custom_id === customId &&
|
|
69
|
+
typeof component.value === "string") {
|
|
70
|
+
return component.value;
|
|
75
71
|
}
|
|
72
|
+
// Nested Label wrapper: single child in .component
|
|
73
|
+
if (component?.component) {
|
|
74
|
+
const found = findValue([component.component]);
|
|
75
|
+
if (found)
|
|
76
|
+
return found;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
|
81
|
+
for (const top of interaction.data.components) {
|
|
82
|
+
if ("components" in top && Array.isArray(top.components)) {
|
|
83
|
+
const result = findValue(top.components);
|
|
84
|
+
if (result)
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
if ("component" in top && top.component) {
|
|
88
|
+
const result = findValue([top.component]);
|
|
89
|
+
if (result)
|
|
90
|
+
return result;
|
|
76
91
|
}
|
|
77
92
|
}
|
|
78
93
|
return undefined;
|
|
79
94
|
};
|
|
80
95
|
/**
|
|
81
96
|
* Helper method to get the value(s) of a select menu component by its custom ID.
|
|
82
|
-
* Handles the nested structure of modal components (Action Rows -> Components
|
|
97
|
+
* Handles the nested structure of modal components (Action Rows -> Components,
|
|
98
|
+
* and Label -> single component). Select menus in modals are typically inside
|
|
99
|
+
* Label components, not Action Rows.
|
|
83
100
|
*/
|
|
84
101
|
const getSelectMenuValues = (customId) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
for (const rawComponent of actionRow.components) {
|
|
91
|
-
// Cast to any to handle potential type definitions that might not fully support Select Menus in Modals yet
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
-
const component = rawComponent;
|
|
94
|
-
// 4. Match customId and check for 'values' property (specific to Select Menus)
|
|
95
|
-
if (component.custom_id === customId &&
|
|
96
|
-
Array.isArray(component.values)) {
|
|
97
|
-
// 5. Return its values property
|
|
98
|
-
return component.values;
|
|
99
|
-
}
|
|
102
|
+
const findValues = (components) => {
|
|
103
|
+
for (const component of components) {
|
|
104
|
+
if (component?.custom_id === customId &&
|
|
105
|
+
Array.isArray(component.values)) {
|
|
106
|
+
return component.values;
|
|
100
107
|
}
|
|
108
|
+
// Nested Label wrapper: single child in .component
|
|
109
|
+
if (component?.component) {
|
|
110
|
+
const found = findValues([component.component]);
|
|
111
|
+
if (found)
|
|
112
|
+
return found;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
};
|
|
117
|
+
for (const top of interaction.data.components) {
|
|
118
|
+
// Action Row: multiple components in .components
|
|
119
|
+
if ("components" in top && Array.isArray(top.components)) {
|
|
120
|
+
const result = findValues(top.components);
|
|
121
|
+
if (result)
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
// Label: select menu (and other modal components) wrapped in .component
|
|
125
|
+
if ("component" in top && top.component) {
|
|
126
|
+
const result = findValues([top.component]);
|
|
127
|
+
if (result)
|
|
128
|
+
return result;
|
|
101
129
|
}
|
|
102
130
|
}
|
|
103
|
-
// 6. If not found, return undefined
|
|
104
131
|
return undefined;
|
|
105
132
|
};
|
|
106
133
|
const getComponentValue = (customId) => {
|
package/package.json
CHANGED