Add onClick arg to /echo executing closures - Adds the 'onclick' slash command arg to /echo - It utilizes the Closure object without serialization, using the exact same scope it received on creation. Should be mindful about memory leaks and possible parallel execution.

de8732fad6fa224da254fe0b35c9578f4d09ac7f

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +9 -1Ignore whitespace
public/scripts/slash-commands.js+9 -1
@@ -813,6 +813,11 @@ export function initDefaultSlashCommands() {
813 defaultValue: 'true',813 defaultValue: 'true',
814 enumList: commonEnumProviders.boolean('trueFalse')(),814 enumList: commonEnumProviders.boolean('trueFalse')(),
815 }),815 }),
816 SlashCommandNamedArgument.fromProps({
817 name: 'onClick',
818 description: 'a closure to call when the toast is clicked. This executed closure receives scope as provided in the script. Careful about possible side effects when manipulating variables and more.',
819 typeList: [ARGUMENT_TYPE.CLOSURE],
820 }),
816 ],821 ],
817 unnamedArgumentList: [822 unnamedArgumentList: [
818 new SlashCommandArgument(823 new SlashCommandArgument(
@@ -2197,7 +2202,7 @@ async function generateCallback(args, value) {
21972202
2198/**2203/**
2199 *2204 *
2200 * @param {{title?: string, severity?: string, timeout?: string, extendedTimeout?: string, preventDuplicates?: string, awaitDismissal?: string, cssClass?: string, color?: string, escapeHtml?: string}} args - named arguments from the slash command2205 * @param {{title?: string, severity?: string, timeout?: string, extendedTimeout?: string, preventDuplicates?: string, awaitDismissal?: string, cssClass?: string, color?: string, escapeHtml?: string, onClick?: SlashCommandClosure}} args - named arguments from the slash command
2201 * @param {string} value - The string to echo (unnamed argument from the slash command)2206 * @param {string} value - The string to echo (unnamed argument from the slash command)
2202 * @returns {Promise<string>} The text that was echoed2207 * @returns {Promise<string>} The text that was echoed
2203 */2208 */
@@ -2234,6 +2239,9 @@ async function echoCallback(args, value) {
2234 if (awaitDismissal) {2239 if (awaitDismissal) {
2235 options.onHidden = () => resolveToastDismissal(value);2240 options.onHidden = () => resolveToastDismissal(value);
2236 }2241 }
2242 if (args.onClick) {
2243 options.onclick = () => args.onClick.execute();
2244 }
22372245
2238 let toast;2246 let toast;
2239 switch (severity) {2247 switch (severity) {