@minesa-org/mini-interaction 0.3.8 → 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,24 +63,29 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
63
63
|
};
|
|
64
64
|
const getResponse = () => capturedResponse;
|
|
65
65
|
const getTextFieldValue = (customId) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const result = findValue(
|
|
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;
|
|
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]);
|
|
84
89
|
if (result)
|
|
85
90
|
return result;
|
|
86
91
|
}
|
|
@@ -89,28 +94,36 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
89
94
|
};
|
|
90
95
|
/**
|
|
91
96
|
* Helper method to get the value(s) of a select menu component by its custom ID.
|
|
92
|
-
* Handles the nested structure of modal components (Action Rows -> Components
|
|
93
|
-
*
|
|
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.
|
|
94
100
|
*/
|
|
95
101
|
const getSelectMenuValues = (customId) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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;
|
|
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]);
|
|
114
127
|
if (result)
|
|
115
128
|
return result;
|
|
116
129
|
}
|
package/package.json
CHANGED