mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
refactor(editor): Refactor utils files and mixins (#4654)
* ✨ Added `utils` module. Moved `canvasHelpers` and old `utils.ts` file to it * ✨ Moved rest of utils and helpers * ⚡ Fixing sytax errors * 🔨 Refactoring new utils files * 🔨 Organizing imports, adding comments and a bit more refactoring * ✔️ Fixing tests * 🔨 Moving mixins to `src`
This commit is contained in:
committed by
GitHub
parent
67983e8f94
commit
5059c57f4a
55
packages/editor-ui/src/mixins/globalLinkActions.ts
Normal file
55
packages/editor-ui/src/mixins/globalLinkActions.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Creates event listeners for `data-action` attribute to allow for actions to be called from locale without using
|
||||
* unsafe onclick attribute
|
||||
*/
|
||||
import Vue from 'vue';
|
||||
|
||||
export const globalLinkActions = Vue.extend({
|
||||
data(): {[key: string]: {[key: string]: Function}} {
|
||||
return {
|
||||
customActions: {},
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
window.addEventListener('click', this.delegateClick);
|
||||
this.$root.$on('registerGlobalLinkAction', this.registerCustomAction);
|
||||
},
|
||||
destroyed() {
|
||||
window.removeEventListener('click', this.delegateClick);
|
||||
this.$root.$off('registerGlobalLinkAction', this.registerCustomAction);
|
||||
},
|
||||
computed: {
|
||||
availableActions(): {[key: string]: Function} {
|
||||
return {
|
||||
reload: this.reload,
|
||||
...this.customActions,
|
||||
};
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
registerCustomAction(key: string, action: Function) {
|
||||
this.customActions[key] = action;
|
||||
},
|
||||
unregisterCustomAction(key: string) {
|
||||
Vue.delete(this.customActions, key);
|
||||
},
|
||||
delegateClick(e: MouseEvent) {
|
||||
const clickedElement = e.target;
|
||||
if (!(clickedElement instanceof Element) || clickedElement.tagName !== 'A') return;
|
||||
|
||||
const actionAttribute = clickedElement.getAttribute('data-action');
|
||||
if(actionAttribute && typeof this.availableActions[actionAttribute] === 'function') {
|
||||
e.preventDefault();
|
||||
this.availableActions[actionAttribute]();
|
||||
}
|
||||
},
|
||||
reload() {
|
||||
if (window.top) {
|
||||
window.top.location.reload();
|
||||
} else {
|
||||
window.location.reload();
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user