enh(interact) generalize (inter-)actions and make it more flexible

This commit is contained in:
Benjamin Wegener
2024-01-16 20:09:49 +00:00
parent 97b836f54d
commit 6784649d82

View File

@@ -3,7 +3,7 @@ import Registry from '../core/Registry';
import Logger from '../core/Logger'; import Logger from '../core/Logger';
export default class Interact extends CetraPlugin { export default class Interact extends CetraPlugin {
static #actions = [ static #commands = [
'on', 'on',
'off', 'off',
'click', 'click',
@@ -28,7 +28,7 @@ export default class Interact extends CetraPlugin {
`no cetra instance found: ${this.#cetraIdentifier}` `no cetra instance found: ${this.#cetraIdentifier}`
); );
cetra.registerCommands(Interact.#actions, this.#pluginName); cetra.registerCommands(Interact.#commands, this.#pluginName);
return this; return this;
} }
@@ -39,7 +39,7 @@ export default class Interact extends CetraPlugin {
throw new Error( throw new Error(
`no cetra instance found: ${this.#cetraIdentifier}` `no cetra instance found: ${this.#cetraIdentifier}`
); );
return (action ? [action] : Interact.#actions) return (action ? [action] : Interact.#commands)
.map((action) => .map((action) =>
[ [
`[data-${cetra.getOption('selector')}-${action}]`, `[data-${cetra.getOption('selector')}-${action}]`,
@@ -70,7 +70,7 @@ export default class Interact extends CetraPlugin {
); );
} }
let [action, method, varName] = ( let [action, command, ...options] = (
el.getAttribute(`data-${cetra.getOption('selector')}-on`) || el.getAttribute(`data-${cetra.getOption('selector')}-on`) ||
el.getAttribute(`${cetra.getOption('selector')}-on`) || el.getAttribute(`${cetra.getOption('selector')}-on`) ||
'' ''
@@ -82,7 +82,7 @@ export default class Interact extends CetraPlugin {
// if there is a command named like the action // if there is a command named like the action
// and if so it gives the action to the appropriate // and if so it gives the action to the appropriate
// component // component
cetra.exec(method, varName, componentId, e); cetra.exec(componentId, { command, options, e });
}); });
} }
} }