refactor(editor): remove selection global types (#9532)

Closes: [BS-2217](https://linear.app/affine-design/issue/BS-2217/remove-global-types-in-selection)
This commit is contained in:
Saul-Mirone
2025-01-06 03:45:10 +00:00
parent 8669936f2f
commit fc863e484c
105 changed files with 501 additions and 358 deletions
@@ -1,5 +1,10 @@
import { findNoteBlockModel } from '@blocksuite/affine-shared/utils';
import type { BlockComponent } from '@blocksuite/block-std';
import {
type BlockComponent,
BlockSelection,
SurfaceSelection,
TextSelection,
} from '@blocksuite/block-std';
import type { AffineDragHandleWidget } from '../drag-handle.js';
@@ -15,7 +20,7 @@ export class SelectionHelper {
setSelectedBlocks = (blocks: BlockComponent[], noteId?: string) => {
const { selection } = this;
const selections = blocks.map(block =>
selection.create('block', {
selection.create(BlockSelection, {
blockId: block.blockId,
})
);
@@ -28,7 +33,7 @@ export class SelectionHelper {
: findNoteBlockModel(blocks[0].model)?.id;
if (!surfaceElementId) return;
const surfaceSelection = selection.create(
'surface',
SurfaceSelection,
blocks[0]!.blockId,
[surfaceElementId],
true
@@ -49,9 +54,9 @@ export class SelectionHelper {
get selectedBlocks() {
const selection = this.selection;
return selection.find('text')
? selection.filter('text')
: selection.filter('block');
return selection.find(TextSelection)
? selection.filter(TextSelection)
: selection.filter(BlockSelection);
}
get selection() {
@@ -23,6 +23,7 @@ import {
} from '@blocksuite/affine-shared/utils';
import {
type BlockComponent,
BlockSelection,
type DndEventState,
isGfxBlockComponent,
type UIEventHandler,
@@ -158,7 +159,7 @@ export class DragEventWatcher {
const selectBlockAndStartDragging = () => {
this._std.selection.setGroup('note', [
this._std.selection.create('block', {
this._std.selection.create(BlockSelection, {
blockId: hoverBlock.blockId,
}),
]);