refactor: default-tool box selection (#11800)

### Changed
- Rewrite box selection in `default-tool`, the view can decide whether to be selected in box selection by return a boolean value in `onBoxSelected` method
- Cleanup unnecessary states in `default-tool` and some naming problem
This commit is contained in:
doouding
2025-04-22 08:18:25 +00:00
parent 1d58792631
commit b59f6ebde0
16 changed files with 209 additions and 150 deletions

View File

@@ -2,7 +2,7 @@ import { DefaultTheme, type FrameBlockModel } from '@blocksuite/affine-model';
import { ThemeProvider } from '@blocksuite/affine-shared/services';
import { Bound } from '@blocksuite/global/gfx';
import { GfxBlockComponent } from '@blocksuite/std';
import type { SelectedContext } from '@blocksuite/std/gfx';
import type { BoxSelectionContext, SelectedContext } from '@blocksuite/std/gfx';
import { cssVarV2 } from '@toeverything/theme/v2';
import { html } from 'lit';
import { state } from 'lit/decorators.js';
@@ -69,6 +69,16 @@ export class FrameBlockComponent extends GfxBlockComponent<FrameBlockModel> {
return super.onSelected(context);
}
override onBoxSelected(context: BoxSelectionContext) {
const { box } = context;
const bound = new Bound(box.x, box.y, box.w, box.h);
const elementBound = this.model.elementBound;
return (
this.model.childElements.length === 0 || bound.contains(elementBound)
);
}
override renderGfxBlock() {
const { model, showBorder, std } = this;
const backgroundColor = std