Allow /popup to optionally return popup result

a3468db94e4a06e9776b73c476d62bcd4ca00a1c

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +14 -2Showing whitespace changes
public/scripts/slash-commands.js+14 -2
@@ -1272,24 +1272,28 @@ export function initDefaultSlashCommands() {
12721272 description: 'show large popup',
12731273 typeList: [ARGUMENT_TYPE.BOOLEAN],
12741274 enumList: commonEnumProviders.boolean('onOff')(),
1275+ defaultValue: 'off',
12751276 }),
12761277 SlashCommandNamedArgument.fromProps({
12771278 name: 'wide',
12781279 description: 'show wide popup',
12791280 typeList: [ARGUMENT_TYPE.BOOLEAN],
12801281 enumList: commonEnumProviders.boolean('onOff')(),
1282+ defaultValue: 'off',
12811283 }),
12821284 SlashCommandNamedArgument.fromProps({
12831285 name: 'wider',
12841286 description: 'show wider popup',
12851287 typeList: [ARGUMENT_TYPE.BOOLEAN],
12861288 enumList: commonEnumProviders.boolean('onOff')(),
1289+ defaultValue: 'off',
12871290 }),
12881291 SlashCommandNamedArgument.fromProps({
12891292 name: 'transparent',
12901293 description: 'show transparent popup',
12911294 typeList: [ARGUMENT_TYPE.BOOLEAN],
12921295 enumList: commonEnumProviders.boolean('onOff')(),
1296+ defaultValue: 'off',
12931297 }),
12941298 SlashCommandNamedArgument.fromProps({
12951299 name: 'okButton',
@@ -1302,6 +1306,13 @@ export function initDefaultSlashCommands() {
13021306 description: 'text for the Cancel button',
13031307 typeList: [ARGUMENT_TYPE.STRING],
13041308 }),
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+ }),
13051316 ],
13061317 unnamedArgumentList: [
13071318 new SlashCommandArgument(
@@ -1910,6 +1921,7 @@ async function buttonsCallback(args, text) {
19101921async function popupCallback(args, value) {
19111922 const safeBody = DOMPurify.sanitize(value || '');
19121923 const safeHeader = args?.header && typeof args?.header === 'string' ? DOMPurify.sanitize(args.header) : null;
1924+ const requestedResult = isTrueBoolean(args?.result);
19131925
19141926 /** @type {import('./popup.js').PopupOptions} */
19151927 const popupOptions = {
@@ -1920,8 +1932,8 @@ async function popupCallback(args, value) {
19201932 okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok',
19211933 cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null,
19221934 };
19231935 const result = await Popup.show.text(safeHeader, safeBody, popupOptions);
19241936 return String(requestedResult ? result : value);
19251937}
19261938
19271939async function getMessagesCallback(args, value) {