mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 10:06:17 +08:00
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:
@@ -40,9 +40,7 @@ export class FrameOverlay extends Overlay {
|
||||
private readonly _prevXYWH: SerializedXYWH | null = null;
|
||||
|
||||
private get _frameManager() {
|
||||
return this.gfx.std.get(
|
||||
GfxExtensionIdentifier('frame-manager')
|
||||
) as EdgelessFrameManager;
|
||||
return this.gfx.std.get(EdgelessFrameManagerIdentifier);
|
||||
}
|
||||
|
||||
constructor(gfx: GfxController) {
|
||||
@@ -130,6 +128,9 @@ export class FrameOverlay extends Overlay {
|
||||
}
|
||||
}
|
||||
|
||||
export const EdgelessFrameManagerIdentifier =
|
||||
GfxExtensionIdentifier<EdgelessFrameManager>('frame-manager');
|
||||
|
||||
export class EdgelessFrameManager extends GfxExtension {
|
||||
static override key = 'frame-manager';
|
||||
|
||||
|
||||
+2
-5
@@ -7,7 +7,7 @@ import {
|
||||
SYNCED_MIN_WIDTH,
|
||||
} from '@blocksuite/affine-block-embed';
|
||||
import {
|
||||
type EdgelessFrameManager,
|
||||
EdgelessFrameManagerIdentifier,
|
||||
type FrameOverlay,
|
||||
isFrameBlock,
|
||||
} from '@blocksuite/affine-block-frame';
|
||||
@@ -45,7 +45,6 @@ import {
|
||||
type CursorType,
|
||||
getTopElements,
|
||||
GfxControllerIdentifier,
|
||||
GfxExtensionIdentifier,
|
||||
type GfxModel,
|
||||
type GfxPrimitiveElementModel,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
@@ -1096,9 +1095,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
||||
}
|
||||
|
||||
#adjustFrame(frame: FrameBlockModel, bound: Bound) {
|
||||
const frameManager = this.std.get(
|
||||
GfxExtensionIdentifier('frame-manager')
|
||||
) as EdgelessFrameManager;
|
||||
const frameManager = this.std.get(EdgelessFrameManagerIdentifier);
|
||||
|
||||
const oldChildren = frameManager.getChildElementsInFrame(frame);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { EdgelessFrameManager } from '@blocksuite/affine-block-frame';
|
||||
import { EdgelessFrameManagerIdentifier } from '@blocksuite/affine-block-frame';
|
||||
import {
|
||||
EdgelessCRUDIdentifier,
|
||||
EdgelessLegacySlotIdentifier,
|
||||
@@ -25,7 +25,6 @@ import type {
|
||||
import {
|
||||
GfxBlockElementModel,
|
||||
GfxControllerIdentifier,
|
||||
GfxExtensionIdentifier,
|
||||
isGfxGroupCompatibleModel,
|
||||
ZOOM_MAX,
|
||||
ZOOM_MIN,
|
||||
@@ -76,9 +75,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
|
||||
}
|
||||
|
||||
get frame() {
|
||||
return this.std.get(
|
||||
GfxExtensionIdentifier('frame-manager')
|
||||
) as EdgelessFrameManager;
|
||||
return this.std.get(EdgelessFrameManagerIdentifier);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { insertEdgelessTextCommand } from '@blocksuite/affine-block-edgeless-text';
|
||||
import {
|
||||
type EdgelessFrameManager,
|
||||
EdgelessFrameManagerIdentifier,
|
||||
type FrameOverlay,
|
||||
isFrameBlock,
|
||||
} from '@blocksuite/affine-block-frame';
|
||||
@@ -36,7 +36,6 @@ import {
|
||||
BaseTool,
|
||||
getTopElements,
|
||||
type GfxBlockElementModel,
|
||||
GfxExtensionIdentifier,
|
||||
type GfxModel,
|
||||
type GfxPrimitiveElementModel,
|
||||
isGfxGroupCompatibleModel,
|
||||
@@ -233,9 +232,7 @@ export class DefaultTool extends BaseTool {
|
||||
}
|
||||
|
||||
private get _frameMgr() {
|
||||
return this.std.get(
|
||||
GfxExtensionIdentifier('frame-manager')
|
||||
) as EdgelessFrameManager;
|
||||
return this.std.get(EdgelessFrameManagerIdentifier);
|
||||
}
|
||||
|
||||
private get _supportedExts() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type {
|
||||
EdgelessFrameManager,
|
||||
FrameOverlay,
|
||||
import {
|
||||
EdgelessFrameManagerIdentifier,
|
||||
type FrameOverlay,
|
||||
} from '@blocksuite/affine-block-frame';
|
||||
import { OverlayIdentifier } from '@blocksuite/affine-block-surface';
|
||||
import type { FrameBlockModel } from '@blocksuite/affine-model';
|
||||
@@ -9,11 +9,7 @@ import {
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import type { PointerEventState } from '@blocksuite/block-std';
|
||||
import {
|
||||
BaseTool,
|
||||
getTopElements,
|
||||
GfxExtensionIdentifier,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import { BaseTool, getTopElements } from '@blocksuite/block-std/gfx';
|
||||
import type { IPoint, IVec } from '@blocksuite/global/gfx';
|
||||
import { Bound, Vec } from '@blocksuite/global/gfx';
|
||||
import { Text } from '@blocksuite/store';
|
||||
@@ -27,9 +23,7 @@ export class FrameTool extends BaseTool {
|
||||
private _startPoint: IVec | null = null;
|
||||
|
||||
get frameManager() {
|
||||
return this.std.get(
|
||||
GfxExtensionIdentifier('frame-manager')
|
||||
) as EdgelessFrameManager;
|
||||
return this.std.get(EdgelessFrameManagerIdentifier);
|
||||
}
|
||||
|
||||
get frameOverlay() {
|
||||
|
||||
+3
-4
@@ -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 type {
|
||||
EdgelessColorPickerButton,
|
||||
@@ -17,7 +17,6 @@ import {
|
||||
} from '@blocksuite/affine-model';
|
||||
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { GfxExtensionIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import { deserializeXYWH, serializeXYWH } from '@blocksuite/global/gfx';
|
||||
import { WithDisposable } from '@blocksuite/global/lit';
|
||||
import { EditIcon, PageIcon, UngroupIcon } from '@blocksuite/icons/lit';
|
||||
@@ -159,8 +158,8 @@ export class EdgelessChangeFrameButton extends WithDisposable(LitElement) {
|
||||
@click=${() => {
|
||||
this.edgeless.doc.captureSync();
|
||||
const frameMgr = this.edgeless.std.get(
|
||||
GfxExtensionIdentifier('frame-manager')
|
||||
) as EdgelessFrameManager;
|
||||
EdgelessFrameManagerIdentifier
|
||||
);
|
||||
frames.forEach(frame =>
|
||||
frameMgr.removeAllChildrenFromFrame(frame)
|
||||
);
|
||||
|
||||
@@ -78,10 +78,11 @@ import type {
|
||||
export function createIdentifier<T>(
|
||||
name: string,
|
||||
variant: ServiceVariant = DEFAULT_SERVICE_VARIANT
|
||||
): ServiceIdentifier<T> & ((variant: ServiceVariant) => ServiceIdentifier<T>) {
|
||||
): ServiceIdentifier<T> &
|
||||
(<U extends T = T>(variant: ServiceVariant) => ServiceIdentifier<U>) {
|
||||
return Object.assign(
|
||||
(variant: ServiceVariant) => {
|
||||
return createIdentifier<T>(name, variant);
|
||||
<U extends T = T>(variant: ServiceVariant) => {
|
||||
return createIdentifier<U>(name, variant);
|
||||
},
|
||||
{
|
||||
identifierName: name,
|
||||
|
||||
Reference in New Issue
Block a user