fix(editor): improve type declaration definition (#10866)

Closes: [BS-2809](https://linear.app/affine-design/issue/BS-2809/改进继承自抽象类的类型后-createidentifier-类型定义)

### What's Changed!

* Improved type declaration definition
This commit is contained in:
fundon
2025-03-14 10:38:16 +00:00
parent d8dfea6ccf
commit 99fdfe821a
7 changed files with 22 additions and 36 deletions

View File

@@ -40,9 +40,7 @@ export class FrameOverlay extends Overlay {
private readonly _prevXYWH: SerializedXYWH | null = null; private readonly _prevXYWH: SerializedXYWH | null = null;
private get _frameManager() { private get _frameManager() {
return this.gfx.std.get( return this.gfx.std.get(EdgelessFrameManagerIdentifier);
GfxExtensionIdentifier('frame-manager')
) as EdgelessFrameManager;
} }
constructor(gfx: GfxController) { constructor(gfx: GfxController) {
@@ -130,6 +128,9 @@ export class FrameOverlay extends Overlay {
} }
} }
export const EdgelessFrameManagerIdentifier =
GfxExtensionIdentifier<EdgelessFrameManager>('frame-manager');
export class EdgelessFrameManager extends GfxExtension { export class EdgelessFrameManager extends GfxExtension {
static override key = 'frame-manager'; static override key = 'frame-manager';

View File

@@ -7,7 +7,7 @@ import {
SYNCED_MIN_WIDTH, SYNCED_MIN_WIDTH,
} from '@blocksuite/affine-block-embed'; } from '@blocksuite/affine-block-embed';
import { import {
type EdgelessFrameManager, EdgelessFrameManagerIdentifier,
type FrameOverlay, type FrameOverlay,
isFrameBlock, isFrameBlock,
} from '@blocksuite/affine-block-frame'; } from '@blocksuite/affine-block-frame';
@@ -45,7 +45,6 @@ import {
type CursorType, type CursorType,
getTopElements, getTopElements,
GfxControllerIdentifier, GfxControllerIdentifier,
GfxExtensionIdentifier,
type GfxModel, type GfxModel,
type GfxPrimitiveElementModel, type GfxPrimitiveElementModel,
} from '@blocksuite/block-std/gfx'; } from '@blocksuite/block-std/gfx';
@@ -1096,9 +1095,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
} }
#adjustFrame(frame: FrameBlockModel, bound: Bound) { #adjustFrame(frame: FrameBlockModel, bound: Bound) {
const frameManager = this.std.get( const frameManager = this.std.get(EdgelessFrameManagerIdentifier);
GfxExtensionIdentifier('frame-manager')
) as EdgelessFrameManager;
const oldChildren = frameManager.getChildElementsInFrame(frame); const oldChildren = frameManager.getChildElementsInFrame(frame);

View File

@@ -1,4 +1,4 @@
import type { EdgelessFrameManager } from '@blocksuite/affine-block-frame'; import { EdgelessFrameManagerIdentifier } from '@blocksuite/affine-block-frame';
import { import {
EdgelessCRUDIdentifier, EdgelessCRUDIdentifier,
EdgelessLegacySlotIdentifier, EdgelessLegacySlotIdentifier,
@@ -25,7 +25,6 @@ import type {
import { import {
GfxBlockElementModel, GfxBlockElementModel,
GfxControllerIdentifier, GfxControllerIdentifier,
GfxExtensionIdentifier,
isGfxGroupCompatibleModel, isGfxGroupCompatibleModel,
ZOOM_MAX, ZOOM_MAX,
ZOOM_MIN, ZOOM_MIN,
@@ -76,9 +75,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
} }
get frame() { get frame() {
return this.std.get( return this.std.get(EdgelessFrameManagerIdentifier);
GfxExtensionIdentifier('frame-manager')
) as EdgelessFrameManager;
} }
/** /**

View File

@@ -1,6 +1,6 @@
import { insertEdgelessTextCommand } from '@blocksuite/affine-block-edgeless-text'; import { insertEdgelessTextCommand } from '@blocksuite/affine-block-edgeless-text';
import { import {
type EdgelessFrameManager, EdgelessFrameManagerIdentifier,
type FrameOverlay, type FrameOverlay,
isFrameBlock, isFrameBlock,
} from '@blocksuite/affine-block-frame'; } from '@blocksuite/affine-block-frame';
@@ -36,7 +36,6 @@ import {
BaseTool, BaseTool,
getTopElements, getTopElements,
type GfxBlockElementModel, type GfxBlockElementModel,
GfxExtensionIdentifier,
type GfxModel, type GfxModel,
type GfxPrimitiveElementModel, type GfxPrimitiveElementModel,
isGfxGroupCompatibleModel, isGfxGroupCompatibleModel,
@@ -233,9 +232,7 @@ export class DefaultTool extends BaseTool {
} }
private get _frameMgr() { private get _frameMgr() {
return this.std.get( return this.std.get(EdgelessFrameManagerIdentifier);
GfxExtensionIdentifier('frame-manager')
) as EdgelessFrameManager;
} }
private get _supportedExts() { private get _supportedExts() {

View File

@@ -1,6 +1,6 @@
import type { import {
EdgelessFrameManager, EdgelessFrameManagerIdentifier,
FrameOverlay, type FrameOverlay,
} from '@blocksuite/affine-block-frame'; } from '@blocksuite/affine-block-frame';
import { OverlayIdentifier } from '@blocksuite/affine-block-surface'; import { OverlayIdentifier } from '@blocksuite/affine-block-surface';
import type { FrameBlockModel } from '@blocksuite/affine-model'; import type { FrameBlockModel } from '@blocksuite/affine-model';
@@ -9,11 +9,7 @@ import {
TelemetryProvider, TelemetryProvider,
} from '@blocksuite/affine-shared/services'; } from '@blocksuite/affine-shared/services';
import type { PointerEventState } from '@blocksuite/block-std'; import type { PointerEventState } from '@blocksuite/block-std';
import { import { BaseTool, getTopElements } from '@blocksuite/block-std/gfx';
BaseTool,
getTopElements,
GfxExtensionIdentifier,
} from '@blocksuite/block-std/gfx';
import type { IPoint, IVec } from '@blocksuite/global/gfx'; import type { IPoint, IVec } from '@blocksuite/global/gfx';
import { Bound, Vec } from '@blocksuite/global/gfx'; import { Bound, Vec } from '@blocksuite/global/gfx';
import { Text } from '@blocksuite/store'; import { Text } from '@blocksuite/store';
@@ -27,9 +23,7 @@ export class FrameTool extends BaseTool {
private _startPoint: IVec | null = null; private _startPoint: IVec | null = null;
get frameManager() { get frameManager() {
return this.std.get( return this.std.get(EdgelessFrameManagerIdentifier);
GfxExtensionIdentifier('frame-manager')
) as EdgelessFrameManager;
} }
get frameOverlay() { get frameOverlay() {

View File

@@ -1,4 +1,4 @@
import type { EdgelessFrameManager } from '@blocksuite/affine-block-frame'; import { EdgelessFrameManagerIdentifier } from '@blocksuite/affine-block-frame';
import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface'; import { EdgelessCRUDIdentifier } from '@blocksuite/affine-block-surface';
import type { import type {
EdgelessColorPickerButton, EdgelessColorPickerButton,
@@ -17,7 +17,6 @@ import {
} from '@blocksuite/affine-model'; } from '@blocksuite/affine-model';
import { FeatureFlagService } from '@blocksuite/affine-shared/services'; import { FeatureFlagService } from '@blocksuite/affine-shared/services';
import { matchModels } from '@blocksuite/affine-shared/utils'; import { matchModels } from '@blocksuite/affine-shared/utils';
import { GfxExtensionIdentifier } from '@blocksuite/block-std/gfx';
import { deserializeXYWH, serializeXYWH } from '@blocksuite/global/gfx'; import { deserializeXYWH, serializeXYWH } from '@blocksuite/global/gfx';
import { WithDisposable } from '@blocksuite/global/lit'; import { WithDisposable } from '@blocksuite/global/lit';
import { EditIcon, PageIcon, UngroupIcon } from '@blocksuite/icons/lit'; import { EditIcon, PageIcon, UngroupIcon } from '@blocksuite/icons/lit';
@@ -159,8 +158,8 @@ export class EdgelessChangeFrameButton extends WithDisposable(LitElement) {
@click=${() => { @click=${() => {
this.edgeless.doc.captureSync(); this.edgeless.doc.captureSync();
const frameMgr = this.edgeless.std.get( const frameMgr = this.edgeless.std.get(
GfxExtensionIdentifier('frame-manager') EdgelessFrameManagerIdentifier
) as EdgelessFrameManager; );
frames.forEach(frame => frames.forEach(frame =>
frameMgr.removeAllChildrenFromFrame(frame) frameMgr.removeAllChildrenFromFrame(frame)
); );

View File

@@ -78,10 +78,11 @@ import type {
export function createIdentifier<T>( export function createIdentifier<T>(
name: string, name: string,
variant: ServiceVariant = DEFAULT_SERVICE_VARIANT variant: ServiceVariant = DEFAULT_SERVICE_VARIANT
): ServiceIdentifier<T> & ((variant: ServiceVariant) => ServiceIdentifier<T>) { ): ServiceIdentifier<T> &
(<U extends T = T>(variant: ServiceVariant) => ServiceIdentifier<U>) {
return Object.assign( return Object.assign(
(variant: ServiceVariant) => { <U extends T = T>(variant: ServiceVariant) => {
return createIdentifier<T>(name, variant); return createIdentifier<U>(name, variant);
}, },
{ {
identifierName: name, identifierName: name,