mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-23 20:18:42 +08:00
refactor(editor): remove legacy block service spec slots (#11013)
This commit is contained in:
@@ -43,6 +43,7 @@ import {
|
|||||||
compareLayer,
|
compareLayer,
|
||||||
type GfxBlockElementModel,
|
type GfxBlockElementModel,
|
||||||
type GfxCompatibleProps,
|
type GfxCompatibleProps,
|
||||||
|
GfxControllerIdentifier,
|
||||||
type GfxModel,
|
type GfxModel,
|
||||||
type GfxPrimitiveElementModel,
|
type GfxPrimitiveElementModel,
|
||||||
type SerializedElement,
|
type SerializedElement,
|
||||||
@@ -406,7 +407,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get selectionManager() {
|
private get selectionManager() {
|
||||||
return this.host.service.selection;
|
return this.std.get(GfxControllerIdentifier).selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private get std() {
|
private get std() {
|
||||||
|
|||||||
@@ -188,11 +188,11 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<RootBlockModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly _updateLabels = () => {
|
private readonly _updateLabels = () => {
|
||||||
const service = this.service;
|
const doc = this.std.store;
|
||||||
if (!service.doc.root) return;
|
const root = doc.root;
|
||||||
|
if (!root) return;
|
||||||
const pageVisibleBlocks = new Map<AutoConnectElement, number>();
|
const pageVisibleBlocks = new Map<AutoConnectElement, number>();
|
||||||
const notes = service.doc.root?.children.filter(child =>
|
const notes = root.children.filter(child =>
|
||||||
matchModels(child, [NoteBlockModel])
|
matchModels(child, [NoteBlockModel])
|
||||||
);
|
);
|
||||||
const edgelessOnlyNotesSet = new Set<NoteBlockModel>();
|
const edgelessOnlyNotesSet = new Set<NoteBlockModel>();
|
||||||
|
|||||||
@@ -63,9 +63,7 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {
|
|||||||
|
|
||||||
anchorBounds$ = signal<Bound | null>(null);
|
anchorBounds$ = signal<Bound | null>(null);
|
||||||
|
|
||||||
highlighted$ = computed(() =>
|
highlighted$ = computed(() => this.std.selection.find(HighlightSelection));
|
||||||
this.service.selectionManager.find(HighlightSelection)
|
|
||||||
);
|
|
||||||
|
|
||||||
#getBoundsInEdgeless() {
|
#getBoundsInEdgeless() {
|
||||||
const controller = this.std.get(GfxControllerIdentifier);
|
const controller = this.std.get(GfxControllerIdentifier);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
StdIdentifier,
|
StdIdentifier,
|
||||||
} from '../identifier.js';
|
} from '../identifier.js';
|
||||||
import type { BlockStdScope } from '../scope/index.js';
|
import type { BlockStdScope } from '../scope/index.js';
|
||||||
import { getSlots } from '../spec/index.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
@@ -27,8 +26,6 @@ export abstract class BlockService extends Extension {
|
|||||||
|
|
||||||
readonly flavour: string;
|
readonly flavour: string;
|
||||||
|
|
||||||
readonly specSlots = getSlots();
|
|
||||||
|
|
||||||
get collection() {
|
get collection() {
|
||||||
return this.std.workspace;
|
return this.std.workspace;
|
||||||
}
|
}
|
||||||
@@ -108,13 +105,9 @@ export abstract class BlockService extends Extension {
|
|||||||
}
|
}
|
||||||
// life cycle end
|
// life cycle end
|
||||||
|
|
||||||
mounted() {
|
mounted() {}
|
||||||
this.specSlots.mounted.next({ service: this });
|
|
||||||
}
|
|
||||||
|
|
||||||
unmounted() {
|
unmounted() {
|
||||||
this.dispose();
|
this.disposables.dispose();
|
||||||
this.specSlots.unmounted.next({ service: this });
|
|
||||||
}
|
}
|
||||||
// event handlers end
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
export * from './slots.js';
|
|
||||||
export * from './type.js';
|
export * from './type.js';
|
||||||
|
|||||||
@@ -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<Service extends BlockService = BlockService> = {
|
|
||||||
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(),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -229,20 +229,6 @@ export class BlockComponent<
|
|||||||
this.requestUpdate();
|
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<boolean> {
|
protected override async getUpdateComplete(): Promise<boolean> {
|
||||||
|
|||||||
@@ -73,20 +73,11 @@ export class WidgetComponent<
|
|||||||
override connectedCallback() {
|
override connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
this.std.view.setWidget(this);
|
this.std.view.setWidget(this);
|
||||||
|
|
||||||
this.service?.specSlots.widgetConnected.next({
|
|
||||||
service: this.service,
|
|
||||||
component: this,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override disconnectedCallback() {
|
override disconnectedCallback() {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
this.std?.view.deleteWidget(this);
|
this.std?.view.deleteWidget(this);
|
||||||
this.service?.specSlots.widgetDisconnected.next({
|
|
||||||
service: this.service,
|
|
||||||
component: this,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override render(): unknown {
|
override render(): unknown {
|
||||||
|
|||||||
Reference in New Issue
Block a user