diff --git a/packages/editor-ui/src/composables/useGlobalLinkActions.ts b/packages/editor-ui/src/composables/useGlobalLinkActions.ts index 8e493f0cb7ee1..dbfa25680aced 100644 --- a/packages/editor-ui/src/composables/useGlobalLinkActions.ts +++ b/packages/editor-ui/src/composables/useGlobalLinkActions.ts @@ -3,15 +3,16 @@ * unsafe onclick attribute */ import { reactive, computed, onMounted, onUnmounted } from 'vue'; +import type { LinkActionFn, RegisterCustomActionOpts } from '@/event-bus'; import { globalLinkActionsEventBus } from '@/event-bus'; const state = reactive({ - customActions: {} as Record, + customActions: {} as Record, delegatedClickHandler: null as null | ((e: MouseEvent) => void), }); export function useGlobalLinkActions() { - function registerCustomAction({ key, action }: { key: string; action: Function }) { + function registerCustomAction({ key, action }: RegisterCustomActionOpts) { state.customActions[key] = action; } function unregisterCustomAction(key: string) { @@ -51,7 +52,7 @@ export function useGlobalLinkActions() { } } - const availableActions = computed<{ [key: string]: Function }>(() => ({ + const availableActions = computed<{ [key: string]: LinkActionFn }>(() => ({ reload, ...state.customActions, })); diff --git a/packages/editor-ui/src/event-bus/global-link-actions.ts b/packages/editor-ui/src/event-bus/global-link-actions.ts new file mode 100644 index 0000000000000..11e482ffe7265 --- /dev/null +++ b/packages/editor-ui/src/event-bus/global-link-actions.ts @@ -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(); diff --git a/packages/editor-ui/src/event-bus/index.ts b/packages/editor-ui/src/event-bus/index.ts index 91d9a1a5429f7..b094684a9428d 100644 --- a/packages/editor-ui/src/event-bus/index.ts +++ b/packages/editor-ui/src/event-bus/index.ts @@ -1,6 +1,6 @@ export * from './code-node-editor'; export * from './data-pinning'; -export * from './link-actions'; +export * from './global-link-actions'; export * from './html-editor'; export * from './import-curl'; export * from './node-view'; diff --git a/packages/editor-ui/src/event-bus/link-actions.ts b/packages/editor-ui/src/event-bus/link-actions.ts deleted file mode 100644 index 41386147ea2e0..0000000000000 --- a/packages/editor-ui/src/event-bus/link-actions.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { createEventBus } from 'n8n-design-system/utils'; - -export const globalLinkActionsEventBus = createEventBus();