mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
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:
parent
61ac0c7775
commit
51f3e84dff
|
@ -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,
|
||||||
}));
|
}));
|
||||||
|
|
16
packages/editor-ui/src/event-bus/global-link-actions.ts
Normal file
16
packages/editor-ui/src/event-bus/global-link-actions.ts
Normal 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>();
|
|
@ -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';
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
import { createEventBus } from 'n8n-design-system/utils';
|
|
||||||
|
|
||||||
export const globalLinkActionsEventBus = createEventBus();
|
|
Loading…
Reference in a new issue