Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

refactor: remove unused surface service (#11339)

doouding56db0d3b0ee4
diff --git a/blocksuite/affine/blocks/block-surface/src/commands/reassociate-connectors.ts b/blocksuite/affine/blocks/block-surface/src/commands/reassociate-connectors.ts
index 53c30b53e2..3b96fbc447 100644
--- a/blocksuite/affine/blocks/block-surface/src/commands/reassociate-connectors.ts
+++ b/blocksuite/affine/blocks/block-surface/src/commands/reassociate-connectors.ts
@@ -1,6 +1,7 @@
import type { Command } from '@blocksuite/std';
+import { GfxControllerIdentifier } from '@blocksuite/std/gfx';
-import { SurfaceBlockService } from '../surface-service';
+import type { SurfaceBlockModel } from '../surface-model';
/**
* Re-associate bindings for block that have been converted.
@@ -13,14 +14,14 @@ export const reassociateConnectorsCommand: Command<{
newId: string;
}> = (ctx, next) => {
const { oldId, newId } = ctx;
- const service = ctx.std.get(SurfaceBlockService);
- if (!oldId || !newId || !service) {
+ const gfx = ctx.std.get(GfxControllerIdentifier);
+ if (!oldId || !newId || !gfx.surface) {
next();
return;
}
- const surface = service.surface;
- const connectors = surface.getConnectors(oldId);
+ const surface = gfx.surface;
+ const connectors = (surface as SurfaceBlockModel).getConnectors(oldId);
for (const { id, source, target } of connectors) {
if (source.id === oldId) {
surface.updateElement(id, {
diff --git a/blocksuite/affine/blocks/block-surface/src/index.ts b/blocksuite/affine/blocks/block-surface/src/index.ts
index ab98aac1c9..fa4199df2a 100644
--- a/blocksuite/affine/blocks/block-surface/src/index.ts
+++ b/blocksuite/affine/blocks/block-surface/src/index.ts
@@ -56,7 +56,6 @@ export {
SurfaceBlockSchema,
SurfaceBlockSchemaExtension,
} from './surface-model.js';
-export type { SurfaceBlockService } from './surface-service.js';
export {
EdgelessSurfaceBlockSpec,
PageSurfaceBlockSpec,
diff --git a/blocksuite/affine/blocks/block-surface/src/surface-block-void.ts b/blocksuite/affine/blocks/block-surface/src/surface-block-void.ts
index 838ecea27b..e936fab724 100644
--- a/blocksuite/affine/blocks/block-surface/src/surface-block-void.ts
+++ b/blocksuite/affine/blocks/block-surface/src/surface-block-void.ts
@@ -2,12 +2,8 @@ import { BlockComponent } from '@blocksuite/std';
import { nothing } from 'lit';
import type { SurfaceBlockModel } from './surface-model.js';
-import type { SurfaceBlockService } from './surface-service.js';
-export class SurfaceBlockVoidComponent extends BlockComponent<
- SurfaceBlockModel,
- SurfaceBlockService
-> {
+export class SurfaceBlockVoidComponent extends BlockComponent<SurfaceBlockModel> {
override render() {
return nothing;
}
diff --git a/blocksuite/affine/blocks/block-surface/src/surface-block.ts b/blocksuite/affine/blocks/block-surface/src/surface-block.ts
index 62bd8b92a3..66a398d250 100644
--- a/blocksuite/affine/blocks/block-surface/src/surface-block.ts
+++ b/blocksuite/affine/blocks/block-surface/src/surface-block.ts
@@ -17,7 +17,6 @@ import {
} from './renderer/elements/index.js';
import { OverlayIdentifier } from './renderer/overlay.js';
import type { SurfaceBlockModel } from './surface-model.js';
-import type { SurfaceBlockService } from './surface-service.js';
export interface SurfaceContext {
viewport: Viewport;
@@ -31,10 +30,7 @@ export interface SurfaceContext {
};
}
-export class SurfaceBlockComponent extends BlockComponent<
- SurfaceBlockModel,
- SurfaceBlockService
-> {
+export class SurfaceBlockComponent extends BlockComponent<SurfaceBlockModel> {
static isConnector = (element: unknown): element is ConnectorElementModel => {
return element instanceof ConnectorElementModel;
};
diff --git a/blocksuite/affine/blocks/block-surface/src/surface-service.ts b/blocksuite/affine/blocks/block-surface/src/surface-service.ts
deleted file mode 100644
index d106417c76..0000000000
--- a/blocksuite/affine/blocks/block-surface/src/surface-service.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { BlockService } from '@blocksuite/std';
-import { GfxControllerIdentifier } from '@blocksuite/std/gfx';
-
-import { type SurfaceBlockModel, SurfaceBlockSchema } from './surface-model.js';
-import { getSurfaceBlock } from './utils/get-surface-block.js';
-
-export class SurfaceBlockService extends BlockService {
- static override readonly flavour = SurfaceBlockSchema.model.flavour;
-
- surface!: SurfaceBlockModel;
-
- get layer() {
- return this.std.get(GfxControllerIdentifier).layer;
- }
-
- override mounted(): void {
- super.mounted();
-
- const surface = getSurfaceBlock(this.doc);
-
- // FIXME: BS-2271
- this.surface = surface!;
-
- if (!this.surface) {
- const disposable = this.doc.slots.blockUpdated.subscribe(payload => {
- if (payload.flavour === 'affine:surface') {
- disposable.unsubscribe();
- const surface = this.doc.getModelById(
- payload.id
- ) as SurfaceBlockModel | null;
- if (!surface) return;
- this.surface = surface;
- }
- });
- }
- }
-}
diff --git a/blocksuite/affine/blocks/block-surface/src/surface-spec.ts b/blocksuite/affine/blocks/block-surface/src/surface-spec.ts
index cd320fefb4..8bdbf0449e 100644
--- a/blocksuite/affine/blocks/block-surface/src/surface-spec.ts
+++ b/blocksuite/affine/blocks/block-surface/src/surface-spec.ts
@@ -11,11 +11,9 @@ import {
EdgelessLegacySlotExtension,
} from './extensions';
import { ExportManagerExtension } from './extensions/export-manager/export-manager';
-import { SurfaceBlockService } from './surface-service';
const CommonSurfaceBlockSpec: ExtensionType[] = [
FlavourExtension('affine:surface'),
- SurfaceBlockService,
EdgelessCRUDExtension,
EdgelessLegacySlotExtension,
ExportManagerExtension,