refactor(editor): Add types to global link actions event bus (no-changelog) (#10452)

Co-authored-by: Alex Grozav <alex@grozav.com>
This commit is contained in:
Tomi Turtiainen 2024-08-20 11:25:22 +03:00 committed by GitHub
parent 61ac0c7775
commit 51f3e84dff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 7 deletions

View file

@ -3,15 +3,16 @@
* unsafe onclick attribute * unsafe onclick attribute
*/ */
import { reactive, computed, onMounted, onUnmounted } from 'vue'; import { reactive, computed, onMounted, onUnmounted } from 'vue';
import type { LinkActionFn, RegisterCustomActionOpts } from '@/event-bus';
import { globalLinkActionsEventBus } from '@/event-bus'; import { globalLinkActionsEventBus } from '@/event-bus';
const state = reactive({ const state = reactive({
customActions: {} as Record<string, Function>, customActions: {} as Record<string, LinkActionFn>,
delegatedClickHandler: null as null | ((e: MouseEvent) => void), delegatedClickHandler: null as null | ((e: MouseEvent) => void),
}); });
export function useGlobalLinkActions() { export function useGlobalLinkActions() {
function registerCustomAction({ key, action }: { key: string; action: Function }) { function registerCustomAction({ key, action }: RegisterCustomActionOpts) {
state.customActions[key] = action; state.customActions[key] = action;
} }
function unregisterCustomAction(key: string) { function unregisterCustomAction(key: string) {
@ -51,7 +52,7 @@ export function useGlobalLinkActions() {
} }
} }
const availableActions = computed<{ [key: string]: Function }>(() => ({ const availableActions = computed<{ [key: string]: LinkActionFn }>(() => ({
reload, reload,
...state.customActions, ...state.customActions,
})); }));

View file

@ -0,0 +1,16 @@
import { createEventBus } from 'n8n-design-system/utils';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type LinkActionFn = (...args: any[]) => void;
export type RegisterCustomActionOpts = {
key: string;
action: LinkActionFn;
};
export interface GlobalLinkActionsEventBusEvents {
/** See useGlobalLinkActions.ts */
registerGlobalLinkAction: RegisterCustomActionOpts;
}
export const globalLinkActionsEventBus = createEventBus<GlobalLinkActionsEventBusEvents>();

View file

@ -1,6 +1,6 @@
export * from './code-node-editor'; export * from './code-node-editor';
export * from './data-pinning'; export * from './data-pinning';
export * from './link-actions'; export * from './global-link-actions';
export * from './html-editor'; export * from './html-editor';
export * from './import-curl'; export * from './import-curl';
export * from './node-view'; export * from './node-view';

View file

@ -1,3 +0,0 @@
import { createEventBus } from 'n8n-design-system/utils';
export const globalLinkActionsEventBus = createEventBus();