From 054d12601b243a02f54af5f8776d74b5c5497858 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Tue, 13 May 2025 16:29:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(editor):=20eventsServic=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor/src/services/events.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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;