From 76dc55f328d12c6c9a34800ecfe5b78a528793fc Mon Sep 17 00:00:00 2001 From: Saul-Mirone Date: Wed, 19 Mar 2025 15:52:20 +0000 Subject: [PATCH] refactor(editor): remove legacy block service spec slots (#11013) --- .../src/edgeless/clipboard/clipboard.ts | 3 ++- .../widget-edgeless-auto-connect/src/index.ts | 8 +++--- .../src/scroll-anchoring.ts | 4 +-- .../block-std/src/extension/service.ts | 11 ++------ .../framework/block-std/src/spec/index.ts | 1 - .../framework/block-std/src/spec/slots.ts | 27 ------------------- .../src/view/element/block-component.ts | 14 ---------- .../src/view/element/widget-component.ts | 9 ------- 8 files changed, 9 insertions(+), 68 deletions(-) delete mode 100644 blocksuite/framework/block-std/src/spec/slots.ts diff --git a/blocksuite/affine/blocks/block-root/src/edgeless/clipboard/clipboard.ts b/blocksuite/affine/blocks/block-root/src/edgeless/clipboard/clipboard.ts index 1f7e310533..8df3547e74 100644 --- a/blocksuite/affine/blocks/block-root/src/edgeless/clipboard/clipboard.ts +++ b/blocksuite/affine/blocks/block-root/src/edgeless/clipboard/clipboard.ts @@ -43,6 +43,7 @@ import { compareLayer, type GfxBlockElementModel, type GfxCompatibleProps, + GfxControllerIdentifier, type GfxModel, type GfxPrimitiveElementModel, type SerializedElement, @@ -406,7 +407,7 @@ export class EdgelessClipboardController extends PageClipboard { } private get selectionManager() { - return this.host.service.selection; + return this.std.get(GfxControllerIdentifier).selection; } private get std() { diff --git a/blocksuite/affine/widgets/widget-edgeless-auto-connect/src/index.ts b/blocksuite/affine/widgets/widget-edgeless-auto-connect/src/index.ts index 12d09ddded..106737c752 100644 --- a/blocksuite/affine/widgets/widget-edgeless-auto-connect/src/index.ts +++ b/blocksuite/affine/widgets/widget-edgeless-auto-connect/src/index.ts @@ -188,11 +188,11 @@ export class EdgelessAutoConnectWidget extends WidgetComponent { } private readonly _updateLabels = () => { - const service = this.service; - if (!service.doc.root) return; - + const doc = this.std.store; + const root = doc.root; + if (!root) return; const pageVisibleBlocks = new Map(); - const notes = service.doc.root?.children.filter(child => + const notes = root.children.filter(child => matchModels(child, [NoteBlockModel]) ); const edgelessOnlyNotesSet = new Set(); diff --git a/blocksuite/affine/widgets/widget-scroll-anchoring/src/scroll-anchoring.ts b/blocksuite/affine/widgets/widget-scroll-anchoring/src/scroll-anchoring.ts index 8371e1d53d..edecdee830 100644 --- a/blocksuite/affine/widgets/widget-scroll-anchoring/src/scroll-anchoring.ts +++ b/blocksuite/affine/widgets/widget-scroll-anchoring/src/scroll-anchoring.ts @@ -63,9 +63,7 @@ export class AffineScrollAnchoringWidget extends WidgetComponent { anchorBounds$ = signal(null); - highlighted$ = computed(() => - this.service.selectionManager.find(HighlightSelection) - ); + highlighted$ = computed(() => this.std.selection.find(HighlightSelection)); #getBoundsInEdgeless() { const controller = this.std.get(GfxControllerIdentifier); diff --git a/blocksuite/framework/block-std/src/extension/service.ts b/blocksuite/framework/block-std/src/extension/service.ts index fb2d639d2b..2ed30b587d 100644 --- a/blocksuite/framework/block-std/src/extension/service.ts +++ b/blocksuite/framework/block-std/src/extension/service.ts @@ -10,7 +10,6 @@ import { StdIdentifier, } from '../identifier.js'; import type { BlockStdScope } from '../scope/index.js'; -import { getSlots } from '../spec/index.js'; /** * @deprecated @@ -27,8 +26,6 @@ export abstract class BlockService extends Extension { readonly flavour: string; - readonly specSlots = getSlots(); - get collection() { return this.std.workspace; } @@ -108,13 +105,9 @@ export abstract class BlockService extends Extension { } // life cycle end - mounted() { - this.specSlots.mounted.next({ service: this }); - } + mounted() {} unmounted() { - this.dispose(); - this.specSlots.unmounted.next({ service: this }); + this.disposables.dispose(); } - // event handlers end } diff --git a/blocksuite/framework/block-std/src/spec/index.ts b/blocksuite/framework/block-std/src/spec/index.ts index 2782fbabdb..23623aefa7 100644 --- a/blocksuite/framework/block-std/src/spec/index.ts +++ b/blocksuite/framework/block-std/src/spec/index.ts @@ -1,2 +1 @@ -export * from './slots.js'; export * from './type.js'; diff --git a/blocksuite/framework/block-std/src/spec/slots.ts b/blocksuite/framework/block-std/src/spec/slots.ts deleted file mode 100644 index 044756928e..0000000000 --- a/blocksuite/framework/block-std/src/spec/slots.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Subject } from 'rxjs'; - -import type { BlockService } from '../extension/service.js'; -import type { BlockComponent, WidgetComponent } from '../view/index.js'; - -export type BlockSpecSlots = { - mounted: Subject<{ service: Service }>; - unmounted: Subject<{ service: Service }>; - viewConnected: Subject<{ component: BlockComponent; service: Service }>; - viewDisconnected: Subject<{ component: BlockComponent; service: Service }>; - widgetConnected: Subject<{ component: WidgetComponent; service: Service }>; - widgetDisconnected: Subject<{ - component: WidgetComponent; - service: Service; - }>; -}; - -export const getSlots = (): BlockSpecSlots => { - return { - mounted: new Subject(), - unmounted: new Subject(), - viewConnected: new Subject(), - viewDisconnected: new Subject(), - widgetConnected: new Subject(), - widgetDisconnected: new Subject(), - }; -}; diff --git a/blocksuite/framework/block-std/src/view/element/block-component.ts b/blocksuite/framework/block-std/src/view/element/block-component.ts index 0888f2f2b2..3a059cef88 100644 --- a/blocksuite/framework/block-std/src/view/element/block-component.ts +++ b/blocksuite/framework/block-std/src/view/element/block-component.ts @@ -229,20 +229,6 @@ export class BlockComponent< this.requestUpdate(); }) ); - - this.service?.specSlots.viewConnected.next({ - service: this.service, - component: this, - }); - } - - override disconnectedCallback() { - super.disconnectedCallback(); - - this.service?.specSlots.viewDisconnected.next({ - service: this.service, - component: this, - }); } protected override async getUpdateComplete(): Promise { diff --git a/blocksuite/framework/block-std/src/view/element/widget-component.ts b/blocksuite/framework/block-std/src/view/element/widget-component.ts index cb88544e6f..e1d22b0f7b 100644 --- a/blocksuite/framework/block-std/src/view/element/widget-component.ts +++ b/blocksuite/framework/block-std/src/view/element/widget-component.ts @@ -73,20 +73,11 @@ export class WidgetComponent< override connectedCallback() { super.connectedCallback(); this.std.view.setWidget(this); - - this.service?.specSlots.widgetConnected.next({ - service: this.service, - component: this, - }); } override disconnectedCallback() { super.disconnectedCallback(); this.std?.view.deleteWidget(this); - this.service?.specSlots.widgetDisconnected.next({ - service: this.service, - component: this, - }); } override render(): unknown {