From d5fb443b60686a56bfe57f7cf1407aa64a614978 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 23 May 2026 01:17:03 +0400 Subject: [PATCH] Cleanup tracking --- packages/core/src/plugin_manager/index.ts | 41 ++++++++----------- .../core/src/plugin_manager/model/Plugin.ts | 1 - packages/core/src/plugin_manager/types.ts | 3 +- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/packages/core/src/plugin_manager/index.ts b/packages/core/src/plugin_manager/index.ts index 587fe29f9..52826a5f3 100644 --- a/packages/core/src/plugin_manager/index.ts +++ b/packages/core/src/plugin_manager/index.ts @@ -4,15 +4,14 @@ import BlocksEvents from '../block_manager/types'; import { ComponentsEvents } from '../dom_components/types'; import DeviceEvents from '../device_manager/types'; import EditorModel from '../editor/model/Editor'; +import type { EditorEvent, EditorEventCallbacks } from '../editor/types'; import { KeymapsEvents } from '../keymaps/types'; import { StyleManagerEvents } from '../style_manager/types'; import PluginModel, { createPluginAdded } from './model/Plugin'; import Plugins from './model/Plugins'; -import { Plugin, PluginCleanup, PluginInput, PluginOptions, PluginsEvents } from './types'; +import { Plugin, PluginCleanup, PluginInput, PluginOptions, PluginsEvents, PluginTarget } from './types'; import { getPluginId, getPlugin, isPluginDescriptor, isPluginFunction, logPluginWarn, unwrapPluginMeta } from './utils'; -type PluginTarget = string | Plugin | PluginModel; - export default class PluginManager extends ItemManagerModule { events = PluginsEvents; storageKey = ''; @@ -84,56 +83,50 @@ export default class PluginManager extends ItemManagerModule void]> = []; - const listen = (event: string, callback: (...args: any[]) => void) => { - editor.on(event, callback); + const listeners: Array<[EditorEvent, (...args: any[]) => void]> = []; + const listen = ( + event: E, + callback: (...args: EditorEventCallbacks[E]) => void, + ) => { + editor.on(event, callback as any); listeners.push([event, callback]); }; - listen(BlocksEvents.add, (block: any) => { - const id = block.get?.('id'); + listen(BlocksEvents.add, (block) => { + const id = block.get('id'); if (!id || added.blocks.includes(id)) return; added.blocks.push(id); cleanup.push(() => editor.Blocks.remove(id)); }); - listen(KeymapsEvents.add, (keymap: any) => { + listen(KeymapsEvents.add, (keymap) => { const id = keymap.id; if (!id || added.keymaps.includes(id)) return; added.keymaps.push(id); cleanup.push(() => editor.Keymaps.remove(id)); }); - listen(ComponentsEvents.typeAdd, (type: any) => { - const id = type?.id; + listen(ComponentsEvents.typeAdd, (type) => { + const id = type.id; if (!id || added.componentTypes.includes(id)) return; added.componentTypes.push(id); cleanup.push(() => editor.Components.removeType(id)); }); - listen(DeviceEvents.add, (device: any) => { - const id = device?.id || device?.get?.('id'); + listen(DeviceEvents.add, (device) => { + const id = device.get('id'); if (!id || added.devices.includes(id)) return; added.devices.push(id); cleanup.push(() => editor.Devices.remove(id)); }); - listen(StyleManagerEvents.sectorAdd, (sector: any) => { - const id = sector?.id || sector?.get?.('id'); + listen(StyleManagerEvents.sectorAdd, (sector) => { + const id = sector.get('id'); if (!id || added.styleSectors.includes(id)) return; added.styleSectors.push(id); cleanup.push(() => editor.StyleManager.removeSector(id)); }); - listen(StyleManagerEvents.propertyAdd, (property: any) => { - const sectorId = property?.collection?.sector?.get?.('id'); - const id = property?.get?.('property') || property?.get?.('id'); - const alreadyAdded = added.styleProperties.some((item) => item.sectorId === sectorId && item.id === id); - if (!sectorId || !id || alreadyAdded) return; - added.styleProperties.push({ sectorId, id }); - cleanup.push(() => editor.StyleManager.removeProperty(sectorId, id)); - }); - return { added, stop: () => listeners.forEach(([event, callback]) => editor.off(event, callback)), diff --git a/packages/core/src/plugin_manager/model/Plugin.ts b/packages/core/src/plugin_manager/model/Plugin.ts index 83f1bf2c5..ca77987cd 100644 --- a/packages/core/src/plugin_manager/model/Plugin.ts +++ b/packages/core/src/plugin_manager/model/Plugin.ts @@ -11,7 +11,6 @@ export const createPluginAdded = (): PluginAdded => ({ styleTypes: [], assetTypes: [], styleSectors: [], - styleProperties: [], }); export interface PluginProperties { diff --git a/packages/core/src/plugin_manager/types.ts b/packages/core/src/plugin_manager/types.ts index 9b86bdb27..6236f7150 100644 --- a/packages/core/src/plugin_manager/types.ts +++ b/packages/core/src/plugin_manager/types.ts @@ -10,6 +10,8 @@ import PluginModel from './model/Plugin'; export type PluginOptions = Record; +export type PluginTarget = string | Plugin | PluginModel; + export interface PluginAdded { blocks: string[]; commands: string[]; @@ -20,7 +22,6 @@ export interface PluginAdded { styleTypes: string[]; assetTypes: string[]; styleSectors: string[]; - styleProperties: Array<{ sectorId: string; id: string }>; } export type PluginCleanup = () => void;