Allow /popup to optionally return popup result
| @@ -1272,24 +1272,28 @@ export function initDefaultSlashCommands() { | ||
| 1272 | 1272 | description: 'show large popup', |
| 1273 | 1273 | typeList: [ARGUMENT_TYPE.BOOLEAN], |
| 1274 | 1274 | enumList: commonEnumProviders.boolean('onOff')(), |
| 1275 | + defaultValue: 'off', | |
| 1275 | 1276 | }), |
| 1276 | 1277 | SlashCommandNamedArgument.fromProps({ |
| 1277 | 1278 | name: 'wide', |
| 1278 | 1279 | description: 'show wide popup', |
| 1279 | 1280 | typeList: [ARGUMENT_TYPE.BOOLEAN], |
| 1280 | 1281 | enumList: commonEnumProviders.boolean('onOff')(), |
| 1282 | + defaultValue: 'off', | |
| 1281 | 1283 | }), |
| 1282 | 1284 | SlashCommandNamedArgument.fromProps({ |
| 1283 | 1285 | name: 'wider', |
| 1284 | 1286 | description: 'show wider popup', |
| 1285 | 1287 | typeList: [ARGUMENT_TYPE.BOOLEAN], |
| 1286 | 1288 | enumList: commonEnumProviders.boolean('onOff')(), |
| 1289 | + defaultValue: 'off', | |
| 1287 | 1290 | }), |
| 1288 | 1291 | SlashCommandNamedArgument.fromProps({ |
| 1289 | 1292 | name: 'transparent', |
| 1290 | 1293 | description: 'show transparent popup', |
| 1291 | 1294 | typeList: [ARGUMENT_TYPE.BOOLEAN], |
| 1292 | 1295 | enumList: commonEnumProviders.boolean('onOff')(), |
| 1296 | + defaultValue: 'off', | |
| 1293 | 1297 | }), |
| 1294 | 1298 | SlashCommandNamedArgument.fromProps({ |
| 1295 | 1299 | name: 'okButton', |
| @@ -1302,6 +1306,13 @@ export function initDefaultSlashCommands() { | ||
| 1302 | 1306 | description: 'text for the Cancel button', |
| 1303 | 1307 | typeList: [ARGUMENT_TYPE.STRING], |
| 1304 | 1308 | }), |
| 1309 | + SlashCommandNamedArgument.fromProps({ | |
| 1310 | + name: 'result', | |
| 1311 | + description: 'if enabled, returns the popup result (as an integer) instead of the popup text. Resolves to 1 for OK and 0/null for cancel or exiting out.', | |
| 1312 | + typeList: [ARGUMENT_TYPE.BOOLEAN], | |
| 1313 | + enumList: commonEnumProviders.boolean('onOff')(), | |
| 1314 | + defaultValue: 'off', | |
| 1315 | + }), | |
| 1305 | 1316 | ], |
| 1306 | 1317 | unnamedArgumentList: [ |
| 1307 | 1318 | new SlashCommandArgument( |
| @@ -1910,6 +1921,7 @@ async function buttonsCallback(args, text) { | ||
| 1910 | 1921 | async function popupCallback(args, value) { |
| 1911 | 1922 | const safeBody = DOMPurify.sanitize(value || ''); |
| 1912 | 1923 | const safeHeader = args?.header && typeof args?.header === 'string' ? DOMPurify.sanitize(args.header) : null; |
| 1924 | + const requestedResult = isTrueBoolean(args?.result); | |
| 1913 | 1925 | |
| 1914 | 1926 | /** @type {import('./popup.js').PopupOptions} */ |
| 1915 | 1927 | const popupOptions = { |
| @@ -1920,8 +1932,8 @@ async function popupCallback(args, value) { | ||
| 1920 | 1932 | okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok', |
| 1921 | 1933 | cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null, |
| 1922 | 1934 | }; |
| 1923 | 1935 | const result = await Popup.show.text(safeHeader, safeBody, popupOptions); |
| 1924 | 1936 | return String(requestedResult ? result : value); |
| 1925 | 1937 | } |
| 1926 | 1938 | |
| 1927 | 1939 | async function getMessagesCallback(args, value) { |