mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00: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:
@@ -16,7 +16,7 @@ export const getSelectedBlocksCommand: Command<
|
||||
blockSelections?: BlockSelection[];
|
||||
imageSelections?: ImageSelection[];
|
||||
filter?: (el: BlockComponent) => boolean;
|
||||
types?: Extract<BlockSuite.SelectionType, 'block' | 'text' | 'image'>[];
|
||||
types?: Array<'image' | 'text' | 'block'>;
|
||||
roles?: RoleType[];
|
||||
mode?: 'all' | 'flat' | 'highest';
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
export const clearAndSelectFirstModelCommand: Command<'selectedModels'> = (
|
||||
ctx,
|
||||
@@ -17,7 +17,7 @@ export const clearAndSelectFirstModelCommand: Command<'selectedModels'> = (
|
||||
const firstModel = models[0];
|
||||
if (firstModel.text) {
|
||||
firstModel.text.clear();
|
||||
const selection = ctx.std.selection.create('text', {
|
||||
const selection = ctx.std.selection.create(TextSelection, {
|
||||
from: {
|
||||
blockId: firstModel.id,
|
||||
index: 0,
|
||||
|
||||
@@ -32,7 +32,7 @@ export const getSelectedModelsCommand: Command<
|
||||
never,
|
||||
'selectedModels',
|
||||
{
|
||||
types?: Extract<BlockSuite.SelectionType, 'block' | 'text' | 'image'>[];
|
||||
types?: Array<'image' | 'text' | 'block'>;
|
||||
mode?: 'all' | 'flat' | 'highest';
|
||||
}
|
||||
> = (ctx, next) => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { BlockSelection, Command } from '@blocksuite/block-std';
|
||||
import { BlockSelection, type Command } from '@blocksuite/block-std';
|
||||
|
||||
export const getBlockSelectionsCommand: Command<
|
||||
never,
|
||||
'currentBlockSelections'
|
||||
> = (ctx, next) => {
|
||||
const currentBlockSelections = ctx.std.selection.filter('block');
|
||||
const currentBlockSelections = ctx.std.selection.filter(BlockSelection);
|
||||
if (currentBlockSelections.length === 0) return;
|
||||
|
||||
next({ currentBlockSelections });
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
|
||||
import type { ImageSelection } from '../../selection/index.js';
|
||||
import { ImageSelection } from '../../selection/index.js';
|
||||
|
||||
export const getImageSelectionsCommand: Command<
|
||||
never,
|
||||
'currentImageSelections'
|
||||
> = (ctx, next) => {
|
||||
const currentImageSelections = ctx.std.selection.filter('image');
|
||||
const currentImageSelections = ctx.std.selection.filter(ImageSelection);
|
||||
if (currentImageSelections.length === 0) return;
|
||||
|
||||
next({ currentImageSelections });
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Command, TextSelection } from '@blocksuite/block-std';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
export const getTextSelectionCommand: Command<never, 'currentTextSelection'> = (
|
||||
ctx,
|
||||
next
|
||||
) => {
|
||||
const currentTextSelection = ctx.std.selection.find('text');
|
||||
const currentTextSelection = ctx.std.selection.find(TextSelection);
|
||||
if (!currentTextSelection) return;
|
||||
|
||||
next({ currentTextSelection });
|
||||
|
||||
Reference in New Issue
Block a user