Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import type { PluginManifest } from '../types'import type { PluginSource } from './types'import { validateManifest } from './manifest-validator'
/** * Registry of available plugin sources. * Manages plugin discovery and metadata before loading. */export class PluginRegistry { private sources: Map<string, PluginSource> = new Map()
/** * Register a plugin source. * @param manifest Plugin manifest (will be validated) * @param entryUrl URL to the plugin module entry point * @throws If manifest is invalid or plugin already registered */ register(manifest: PluginManifest, entryUrl: string, catalogAdmitted = false, waitForMetadata = false): void { validateManifest(manifest) if (this.sources.has(manifest.id)) { throw new Error(`Plugin '${manifest.id}' is already registered. If this is a third-party plugin that conflicts with a Reams built-in shim, disable the built-in first in Settings.`) } this.sources.set(manifest.id, { manifest, entryUrl, catalogAdmitted, waitForMetadata }) }
/** * Unregister a plugin source. * No-op if plugin is not registered. */ unregister(pluginId: string): void { this.sources.delete(pluginId) }
/** * Check if a plugin is registered. */ has(pluginId: string): boolean { return this.sources.has(pluginId) }
/** * Get a plugin source by ID. * Returns null if not registered. */ get(pluginId: string): PluginSource | null { return this.sources.get(pluginId) ?? null }
/** * Get all registered plugin sources. */ getAll(): PluginSource[] { return Array.from(this.sources.values()) }
/** * Get all registered plugin IDs. */ getIds(): string[] { return Array.from(this.sources.keys()) }
/** * Clear all registered plugins. */ clear(): void { this.sources.clear() }}