From a9e4bef01b1253efd3af752cc85a28c966f1cd00 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Fri, 6 Sep 2024 22:22:35 +0200 Subject: [PATCH 1/6] Add wider and transparent styles to /popup --- public/scripts/slash-commands.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index ecc2b2259..6706d6692 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1273,6 +1273,12 @@ export function initDefaultSlashCommands() { new SlashCommandNamedArgument( 'wide', 'show wide popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), ), + new SlashCommandNamedArgument( + 'wider', 'show wider popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), + ), + new SlashCommandNamedArgument( + 'transparent', 'show transparent popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), + ), new SlashCommandNamedArgument( 'okButton', 'text for the OK button', [ARGUMENT_TYPE.STRING], false, ), @@ -1883,9 +1889,12 @@ async function buttonsCallback(args, text) { async function popupCallback(args, value) { const safeValue = DOMPurify.sanitize(value || ''); + /** @type {import('./popup.js').PopupOptions} */ const popupOptions = { large: isTrueBoolean(args?.large), wide: isTrueBoolean(args?.wide), + wider: isTrueBoolean(args?.wider), + transparent: isTrueBoolean(args?.transparent), okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok', }; await delay(1); From a9c0dd38c7878f059e58f6b075a5160eb914563d Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Fri, 6 Sep 2024 22:38:02 +0200 Subject: [PATCH 2/6] Refactor /popup args and docs, add 'cancelButton' --- public/scripts/slash-commands.js | 55 +++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 6706d6692..a1e83a4c2 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1267,21 +1267,41 @@ export function initDefaultSlashCommands() { callback: popupCallback, returns: 'popup text', namedArgumentList: [ - new SlashCommandNamedArgument( - 'large', 'show large popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'wide', 'show wide popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'wider', 'show wider popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'transparent', 'show transparent popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'okButton', 'text for the OK button', [ARGUMENT_TYPE.STRING], false, - ), + SlashCommandNamedArgument.fromProps({ + name: 'large', + description: 'show large popup', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('onOff')(), + }), + SlashCommandNamedArgument.fromProps({ + name: 'wide', + description: 'show wide popup', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('onOff')(), + }), + SlashCommandNamedArgument.fromProps({ + name: 'wider', + description: 'show wider popup', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('onOff')(), + }), + SlashCommandNamedArgument.fromProps({ + name: 'transparent', + description: 'show transparent popup', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('onOff')(), + }), + SlashCommandNamedArgument.fromProps({ + name: 'okButton', + description: 'text for the OK button', + typeList: [ARGUMENT_TYPE.STRING], + defaultValue: 'OK', + }), + SlashCommandNamedArgument.fromProps({ + name: 'cancelButton', + description: 'text for the Cancel button', + typeList: [ARGUMENT_TYPE.STRING], + }), ], unnamedArgumentList: [ new SlashCommandArgument( @@ -1297,7 +1317,7 @@ export function initDefaultSlashCommands() { Example: @@ -1896,10 +1916,9 @@ async function popupCallback(args, value) { wider: isTrueBoolean(args?.wider), transparent: isTrueBoolean(args?.transparent), okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok', + cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null, }; - await delay(1); await callGenericPopup(safeValue, POPUP_TYPE.TEXT, '', popupOptions); - await delay(1); return String(value); } From e4e10c3d6b3ab8ab02844bc7c01fca6f4912f007 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Fri, 6 Sep 2024 23:14:52 +0200 Subject: [PATCH 3/6] /popup allow header arg, with sanitization --- public/scripts/slash-commands.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index a1e83a4c2..ab83dfeb5 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1908,7 +1908,9 @@ async function buttonsCallback(args, text) { } async function popupCallback(args, value) { - const safeValue = DOMPurify.sanitize(value || ''); + const safeBody = DOMPurify.sanitize(value || ''); + const safeHeader = args?.header && typeof args?.header === 'string' ? DOMPurify.sanitize(args.header) : null; + /** @type {import('./popup.js').PopupOptions} */ const popupOptions = { large: isTrueBoolean(args?.large), @@ -1918,7 +1920,7 @@ async function popupCallback(args, value) { okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok', cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null, }; - await callGenericPopup(safeValue, POPUP_TYPE.TEXT, '', popupOptions); + await Popup.show.text(safeHeader, safeBody, popupOptions); return String(value); } From a3468db94e4a06e9776b73c476d62bcd4ca00a1c Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Fri, 6 Sep 2024 23:29:18 +0200 Subject: [PATCH 4/6] Allow /popup to optionally return popup result --- public/scripts/slash-commands.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index ab83dfeb5..cafa3707f 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1272,24 +1272,28 @@ export function initDefaultSlashCommands() { description: 'show large popup', typeList: [ARGUMENT_TYPE.BOOLEAN], enumList: commonEnumProviders.boolean('onOff')(), + defaultValue: 'off', }), SlashCommandNamedArgument.fromProps({ name: 'wide', description: 'show wide popup', typeList: [ARGUMENT_TYPE.BOOLEAN], enumList: commonEnumProviders.boolean('onOff')(), + defaultValue: 'off', }), SlashCommandNamedArgument.fromProps({ name: 'wider', description: 'show wider popup', typeList: [ARGUMENT_TYPE.BOOLEAN], enumList: commonEnumProviders.boolean('onOff')(), + defaultValue: 'off', }), SlashCommandNamedArgument.fromProps({ name: 'transparent', description: 'show transparent popup', typeList: [ARGUMENT_TYPE.BOOLEAN], enumList: commonEnumProviders.boolean('onOff')(), + defaultValue: 'off', }), SlashCommandNamedArgument.fromProps({ name: 'okButton', @@ -1302,6 +1306,13 @@ export function initDefaultSlashCommands() { description: 'text for the Cancel button', typeList: [ARGUMENT_TYPE.STRING], }), + SlashCommandNamedArgument.fromProps({ + name: 'result', + 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.', + typeList: [ARGUMENT_TYPE.BOOLEAN], + enumList: commonEnumProviders.boolean('onOff')(), + defaultValue: 'off', + }), ], unnamedArgumentList: [ new SlashCommandArgument( @@ -1910,6 +1921,7 @@ async function buttonsCallback(args, text) { async function popupCallback(args, value) { const safeBody = DOMPurify.sanitize(value || ''); const safeHeader = args?.header && typeof args?.header === 'string' ? DOMPurify.sanitize(args.header) : null; + const requestedResult = isTrueBoolean(args?.result); /** @type {import('./popup.js').PopupOptions} */ const popupOptions = { @@ -1920,8 +1932,8 @@ async function popupCallback(args, value) { okButton: args?.okButton !== undefined && typeof args?.okButton === 'string' ? args.okButton : 'Ok', cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null, }; - await Popup.show.text(safeHeader, safeBody, popupOptions); - return String(value); + const result = await Popup.show.text(safeHeader, safeBody, popupOptions); + return String(requestedResult ? result : value); } async function getMessagesCallback(args, value) { From 43b08cdd64913afbb333c3e1a8ec81ccf238c6b3 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Fri, 6 Sep 2024 23:56:26 +0200 Subject: [PATCH 5/6] Refactor /popup to actual booleans - still supports on/off, no worries. --- public/scripts/slash-commands.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index cafa3707f..e8a403f23 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1271,29 +1271,29 @@ export function initDefaultSlashCommands() { name: 'large', description: 'show large popup', typeList: [ARGUMENT_TYPE.BOOLEAN], - enumList: commonEnumProviders.boolean('onOff')(), - defaultValue: 'off', + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', }), SlashCommandNamedArgument.fromProps({ name: 'wide', description: 'show wide popup', typeList: [ARGUMENT_TYPE.BOOLEAN], - enumList: commonEnumProviders.boolean('onOff')(), - defaultValue: 'off', + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', }), SlashCommandNamedArgument.fromProps({ name: 'wider', description: 'show wider popup', typeList: [ARGUMENT_TYPE.BOOLEAN], - enumList: commonEnumProviders.boolean('onOff')(), - defaultValue: 'off', + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', }), SlashCommandNamedArgument.fromProps({ name: 'transparent', description: 'show transparent popup', typeList: [ARGUMENT_TYPE.BOOLEAN], - enumList: commonEnumProviders.boolean('onOff')(), - defaultValue: 'off', + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', }), SlashCommandNamedArgument.fromProps({ name: 'okButton', @@ -1310,14 +1310,16 @@ export function initDefaultSlashCommands() { name: 'result', 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.', typeList: [ARGUMENT_TYPE.BOOLEAN], - enumList: commonEnumProviders.boolean('onOff')(), - defaultValue: 'off', + enumList: commonEnumProviders.boolean('trueFalse')(), + defaultValue: 'false', }), ], unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), + SlashCommandArgument.fromProps({ + description: 'popup text', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + }), ], helpString: `
@@ -1330,6 +1332,9 @@ export function initDefaultSlashCommands() {
  • /popup large=on wide=on okButton="Confirm" Please confirm this action.
  • +
  • +
    /popup okButton="Left" cancelButton="Right" result=true Do you want to go left or right? | /echo 0 means right, 1 means left. Choice: {{pipe}}
    +
  • `, From 2385c5a59a4b729224678b1cfe8f8a2eb642974a Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sat, 7 Sep 2024 01:21:04 +0200 Subject: [PATCH 6/6] Change popup cancel result in command to empty str --- public/scripts/popup.js | 4 ++-- public/scripts/slash-commands.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/scripts/popup.js b/public/scripts/popup.js index 7315fd536..1a9d9ce36 100644 --- a/public/scripts/popup.js +++ b/public/scripts/popup.js @@ -92,7 +92,7 @@ const showPopupHelper = { * @param {string?} header - The header text for the popup. * @param {string?} text - The main text for the popup. * @param {PopupOptions} [popupOptions={}] - Options for the popup. - * @return {Promise} A Promise that resolves with the result of the user's interaction. + * @return {Promise} A Promise that resolves with the result of the user's interaction. */ confirm: async (header, text, popupOptions = {}) => { const content = PopupUtils.BuildTextWithHeader(header, text); @@ -107,7 +107,7 @@ const showPopupHelper = { * @param {string?} header - The header text for the popup. * @param {string?} text - The main text for the popup. * @param {PopupOptions} [popupOptions={}] - Options for the popup. - * @return {Promise} A Promise that resolves with the result of the user's interaction. + * @return {Promise} A Promise that resolves with the result of the user's interaction. */ text: async (header, text, popupOptions = {}) => { const content = PopupUtils.BuildTextWithHeader(header, text); diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index e8a403f23..444639760 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1308,7 +1308,7 @@ export function initDefaultSlashCommands() { }), SlashCommandNamedArgument.fromProps({ name: 'result', - 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.', + description: 'if enabled, returns the popup result (as an integer) instead of the popup text. Resolves to 1 for OK and 0 cancel button, empty string for exiting out.', typeList: [ARGUMENT_TYPE.BOOLEAN], enumList: commonEnumProviders.boolean('trueFalse')(), defaultValue: 'false', @@ -1938,7 +1938,7 @@ async function popupCallback(args, value) { cancelButton: args?.cancelButton !== undefined && typeof args?.cancelButton === 'string' ? args.cancelButton : null, }; const result = await Popup.show.text(safeHeader, safeBody, popupOptions); - return String(requestedResult ? result : value); + return String(requestedResult ? result ?? '' : value); } async function getMessagesCallback(args, value) {