refactor(editor): remove service global type (#10129)

Closes: [BS-2566](https://linear.app/affine-design/issue/BS-2566/remove-global-types-in-service)
This commit is contained in:
Saul-Mirone
2025-02-12 11:46:10 +00:00
parent 6730122108
commit e7cc710f8e
11 changed files with 14 additions and 77 deletions

View File

@@ -12,13 +12,11 @@ import { Clipboard } from '../clipboard/index.js';
import { CommandManager } from '../command/index.js';
import { UIEventDispatcher } from '../event/index.js';
import { DndController } from '../extension/dnd/index.js';
import type { BlockService } from '../extension/index.js';
import { GfxController } from '../gfx/controller.js';
import { GfxSelectionManager } from '../gfx/selection.js';
import { SurfaceMiddlewareExtension } from '../gfx/surface-middleware.js';
import { ViewManager } from '../gfx/view/view-manager.js';
import {
BlockServiceIdentifier,
BlockViewIdentifier,
ConfigIdentifier,
LifeCycleWatcherIdentifier,
@@ -152,18 +150,6 @@ export class BlockStdScope {
return config;
}
/**
* @deprecated
* BlockService will be removed in the future.
*/
getService<Key extends BlockSuite.ServiceKeys>(
flavour: Key
): BlockSuite.BlockServices[Key] | null;
getService<Service extends BlockService>(flavour: string): Service | null;
getService(flavour: string): BlockService | null {
return this.getOptional(BlockServiceIdentifier(flavour));
}
getView(flavour: string) {
return this.getOptional(BlockViewIdentifier(flavour));
}
@@ -208,10 +194,8 @@ export class BlockStdScope {
declare global {
namespace BlockSuite {
interface BlockServices {}
interface BlockConfigs {}
type ServiceKeys = string & keyof BlockServices;
type ConfigKeys = string & keyof BlockConfigs;
}
}

View File

@@ -11,6 +11,7 @@ import { html } from 'lit/static-html.js';
import type { EventName, UIEventHandler } from '../../event/index.js';
import type { BlockService } from '../../extension/index.js';
import { BlockServiceIdentifier } from '../../identifier.js';
import type { BlockStdScope } from '../../scope/index.js';
import { BlockSelection } from '../../selection/index.js';
import { PropTypes, requiredProperties } from '../decorators/index.js';
@@ -146,9 +147,11 @@ export class BlockComponent<
if (this._service) {
return this._service;
}
const service = this.std.getService(this.model.flavour) as Service;
this._service = service;
return service;
const service = this.std.getOptional(
BlockServiceIdentifier(this.model.flavour)
);
this._service = service as Service;
return service as Service;
}
get topContenteditableElement(): BlockComponent | null {