mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 02:20:19 +08:00
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:
@@ -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,
|
||||
}),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user