mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 21:48:48 +08:00
refactor(editor): remove global types in edgeless (#10092)
Closes: [BS-2553](https://linear.app/affine-design/issue/BS-2553/remove-global-types-in-edgeless)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { SurfaceElementModelMap } from '@blocksuite/affine-model';
|
||||
import { EditPropsStore } from '@blocksuite/affine-shared/services';
|
||||
import { type BlockStdScope, StdIdentifier } from '@blocksuite/block-std';
|
||||
import {
|
||||
@@ -62,13 +63,13 @@ export class EdgelessCRUDExtension extends Extension {
|
||||
};
|
||||
|
||||
addBlock = (
|
||||
flavour: BlockSuite.EdgelessModelKeys | string,
|
||||
flavour: string,
|
||||
props: Record<string, unknown>,
|
||||
parentId?: string | BlockModel,
|
||||
parentIndex?: number
|
||||
) => {
|
||||
const gfx = this.std.get(GfxControllerIdentifier);
|
||||
const key = getLastPropsKey(flavour as BlockSuite.EdgelessModelKeys, props);
|
||||
const key = getLastPropsKey(flavour, props);
|
||||
if (key) {
|
||||
props = this.std.get(EditPropsStore).applyLastProps(key, props);
|
||||
}
|
||||
@@ -94,7 +95,7 @@ export class EdgelessCRUDExtension extends Extension {
|
||||
}
|
||||
|
||||
const gfx = this.std.get(GfxControllerIdentifier);
|
||||
const key = getLastPropsKey(type as BlockSuite.EdgelessModelKeys, props);
|
||||
const key = getLastPropsKey(type, props);
|
||||
if (key) {
|
||||
props = this.std.get(EditPropsStore).applyLastProps(key, props) as T;
|
||||
}
|
||||
@@ -117,10 +118,10 @@ export class EdgelessCRUDExtension extends Extension {
|
||||
|
||||
const element = this._surface.getElementById(id);
|
||||
if (element) {
|
||||
const key = getLastPropsKey(
|
||||
element.type as BlockSuite.EdgelessModelKeys,
|
||||
{ ...element.yMap.toJSON(), ...props }
|
||||
);
|
||||
const key = getLastPropsKey(element.type, {
|
||||
...element.yMap.toJSON(),
|
||||
...props,
|
||||
});
|
||||
key && this.std.get(EditPropsStore).recordLastProps(key, props);
|
||||
this._surface.updateElement(id, props);
|
||||
return;
|
||||
@@ -128,10 +129,10 @@ export class EdgelessCRUDExtension extends Extension {
|
||||
|
||||
const block = this.std.store.getBlockById(id);
|
||||
if (block) {
|
||||
const key = getLastPropsKey(
|
||||
block.flavour as BlockSuite.EdgelessModelKeys,
|
||||
{ ...block.yBlock.toJSON(), ...props }
|
||||
);
|
||||
const key = getLastPropsKey(block.flavour, {
|
||||
...block.yBlock.toJSON(),
|
||||
...props,
|
||||
});
|
||||
key && this.std.get(EditPropsStore).recordLastProps(key, props);
|
||||
this.std.store.updateBlock(block, props);
|
||||
}
|
||||
@@ -142,17 +143,13 @@ export class EdgelessCRUDExtension extends Extension {
|
||||
if (!surface) {
|
||||
return null;
|
||||
}
|
||||
const el =
|
||||
surface.getElementById(id) ??
|
||||
(this.std.store.getBlockById(
|
||||
id
|
||||
) as BlockSuite.EdgelessBlockModelType | null);
|
||||
return el;
|
||||
const el = surface.getElementById(id) ?? this.std.store.getBlockById(id);
|
||||
return el as GfxModel | null;
|
||||
}
|
||||
|
||||
getElementsByType<K extends keyof BlockSuite.SurfaceElementModelMap>(
|
||||
getElementsByType<K extends keyof SurfaceElementModelMap>(
|
||||
type: K
|
||||
): BlockSuite.SurfaceElementModelMap[K][] {
|
||||
): SurfaceElementModelMap[K][] {
|
||||
if (!this._surface) {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user