diff --git a/packages/editor/src/services/events.ts b/packages/editor/src/services/events.ts index 336b1983..d178c80a 100644 --- a/packages/editor/src/services/events.ts +++ b/packages/editor/src/services/events.ts @@ -18,18 +18,32 @@ import { reactive } from 'vue'; import { cloneDeep } from 'lodash-es'; +import type { Writable } from 'type-fest'; import { type EventOption } from '@tmagic/core'; import { toLine } from '@tmagic/utils'; +import type { AsyncHookPlugin, SyncHookPlugin } from '@editor/type'; + import BaseService from './BaseService'; +const canUsePluginMethods = { + async: [] as const, + sync: ['setEvent', 'getEvent', 'setMethod', 'getMethod'] as const, +}; + +type AsyncMethodName = Writable<(typeof canUsePluginMethods)['async']>; +type SyncMethodName = Writable<(typeof canUsePluginMethods)['sync']>; + let eventMap: Record = reactive({}); let methodMap: Record = reactive({}); class Events extends BaseService { constructor() { - super([]); + super([ + ...canUsePluginMethods.async.map((methodName) => ({ name: methodName, isAsync: true })), + ...canUsePluginMethods.sync.map((methodName) => ({ name: methodName, isAsync: false })), + ]); } public setEvents(events: Record) { @@ -70,6 +84,10 @@ class Events extends BaseService { this.removeAllListeners(); this.removeAllPlugins(); } + + public usePlugin(options: AsyncHookPlugin & SyncHookPlugin): void { + super.usePlugin(options); + } } export type EventsService = Events;