mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 22:09:08 +08:00
feat(editor): replace spec provider with extension manager (#11861)
Closes: BS-3273
This commit is contained in:
@@ -84,16 +84,17 @@ export class ExtensionManager<Scope extends string> {
|
||||
|
||||
/**
|
||||
* Retrieves all extensions registered for a specific scope.
|
||||
* If the scope hasn't been built yet, it triggers the build process.
|
||||
* It triggers the build process.
|
||||
*
|
||||
* @param scope - The scope to retrieve extensions for
|
||||
* @returns An array of extensions registered for the specified scope
|
||||
* @throws {BlockSuiteError} If the scope is not found
|
||||
*/
|
||||
get(scope: Scope) {
|
||||
if (!this._extensions.has(scope)) {
|
||||
this._build(scope);
|
||||
if (this._extensions.has(scope)) {
|
||||
this._extensions.delete(scope);
|
||||
}
|
||||
this._build(scope);
|
||||
const extensionSet = this._extensions.get(scope);
|
||||
if (!extensionSet) {
|
||||
throw new BlockSuiteError(
|
||||
@@ -117,14 +118,19 @@ export class ExtensionManager<Scope extends string> {
|
||||
provider: typeof BaseExtensionProvider<Scope, T>,
|
||||
options: ((prev: T | undefined) => T | undefined) | T | undefined
|
||||
) {
|
||||
const prev = this._providerOptions.get(provider);
|
||||
|
||||
let config: T | undefined;
|
||||
if (typeof options === 'function') {
|
||||
const prev = this._providerOptions.get(provider);
|
||||
config = (options as (prev: unknown) => T)(prev);
|
||||
} else {
|
||||
config = options;
|
||||
}
|
||||
|
||||
if (prev === config) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config === undefined) {
|
||||
this._providerOptions.delete(provider);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user