mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 12:32:00 +08:00
refactor: remove unused surface service (#11339)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import type { Command } from '@blocksuite/std';
|
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.
|
* Re-associate bindings for block that have been converted.
|
||||||
@@ -13,14 +14,14 @@ export const reassociateConnectorsCommand: Command<{
|
|||||||
newId: string;
|
newId: string;
|
||||||
}> = (ctx, next) => {
|
}> = (ctx, next) => {
|
||||||
const { oldId, newId } = ctx;
|
const { oldId, newId } = ctx;
|
||||||
const service = ctx.std.get(SurfaceBlockService);
|
const gfx = ctx.std.get(GfxControllerIdentifier);
|
||||||
if (!oldId || !newId || !service) {
|
if (!oldId || !newId || !gfx.surface) {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const surface = service.surface;
|
const surface = gfx.surface;
|
||||||
const connectors = surface.getConnectors(oldId);
|
const connectors = (surface as SurfaceBlockModel).getConnectors(oldId);
|
||||||
for (const { id, source, target } of connectors) {
|
for (const { id, source, target } of connectors) {
|
||||||
if (source.id === oldId) {
|
if (source.id === oldId) {
|
||||||
surface.updateElement(id, {
|
surface.updateElement(id, {
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ export {
|
|||||||
SurfaceBlockSchema,
|
SurfaceBlockSchema,
|
||||||
SurfaceBlockSchemaExtension,
|
SurfaceBlockSchemaExtension,
|
||||||
} from './surface-model.js';
|
} from './surface-model.js';
|
||||||
export type { SurfaceBlockService } from './surface-service.js';
|
|
||||||
export {
|
export {
|
||||||
EdgelessSurfaceBlockSpec,
|
EdgelessSurfaceBlockSpec,
|
||||||
PageSurfaceBlockSpec,
|
PageSurfaceBlockSpec,
|
||||||
|
|||||||
@@ -2,12 +2,8 @@ import { BlockComponent } from '@blocksuite/std';
|
|||||||
import { nothing } from 'lit';
|
import { nothing } from 'lit';
|
||||||
|
|
||||||
import type { SurfaceBlockModel } from './surface-model.js';
|
import type { SurfaceBlockModel } from './surface-model.js';
|
||||||
import type { SurfaceBlockService } from './surface-service.js';
|
|
||||||
|
|
||||||
export class SurfaceBlockVoidComponent extends BlockComponent<
|
export class SurfaceBlockVoidComponent extends BlockComponent<SurfaceBlockModel> {
|
||||||
SurfaceBlockModel,
|
|
||||||
SurfaceBlockService
|
|
||||||
> {
|
|
||||||
override render() {
|
override render() {
|
||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
} from './renderer/elements/index.js';
|
} from './renderer/elements/index.js';
|
||||||
import { OverlayIdentifier } from './renderer/overlay.js';
|
import { OverlayIdentifier } from './renderer/overlay.js';
|
||||||
import type { SurfaceBlockModel } from './surface-model.js';
|
import type { SurfaceBlockModel } from './surface-model.js';
|
||||||
import type { SurfaceBlockService } from './surface-service.js';
|
|
||||||
|
|
||||||
export interface SurfaceContext {
|
export interface SurfaceContext {
|
||||||
viewport: Viewport;
|
viewport: Viewport;
|
||||||
@@ -31,10 +30,7 @@ export interface SurfaceContext {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SurfaceBlockComponent extends BlockComponent<
|
export class SurfaceBlockComponent extends BlockComponent<SurfaceBlockModel> {
|
||||||
SurfaceBlockModel,
|
|
||||||
SurfaceBlockService
|
|
||||||
> {
|
|
||||||
static isConnector = (element: unknown): element is ConnectorElementModel => {
|
static isConnector = (element: unknown): element is ConnectorElementModel => {
|
||||||
return element instanceof ConnectorElementModel;
|
return element instanceof ConnectorElementModel;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,11 +11,9 @@ import {
|
|||||||
EdgelessLegacySlotExtension,
|
EdgelessLegacySlotExtension,
|
||||||
} from './extensions';
|
} from './extensions';
|
||||||
import { ExportManagerExtension } from './extensions/export-manager/export-manager';
|
import { ExportManagerExtension } from './extensions/export-manager/export-manager';
|
||||||
import { SurfaceBlockService } from './surface-service';
|
|
||||||
|
|
||||||
const CommonSurfaceBlockSpec: ExtensionType[] = [
|
const CommonSurfaceBlockSpec: ExtensionType[] = [
|
||||||
FlavourExtension('affine:surface'),
|
FlavourExtension('affine:surface'),
|
||||||
SurfaceBlockService,
|
|
||||||
EdgelessCRUDExtension,
|
EdgelessCRUDExtension,
|
||||||
EdgelessLegacySlotExtension,
|
EdgelessLegacySlotExtension,
|
||||||
ExportManagerExtension,
|
ExportManagerExtension,
|
||||||
|
|||||||
Reference in New Issue
Block a user