mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 01:26:37 +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:
@@ -52,7 +52,12 @@ import {
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { getHostName, referenceToNode } from '@blocksuite/affine-shared/utils';
|
||||
import { type BlockStdScope, WidgetComponent } from '@blocksuite/block-std';
|
||||
import {
|
||||
BlockSelection,
|
||||
type BlockStdScope,
|
||||
TextSelection,
|
||||
WidgetComponent,
|
||||
} from '@blocksuite/block-std';
|
||||
import { type BlockModel, Text } from '@blocksuite/store';
|
||||
import { autoUpdate, computePosition, flip, offset } from '@floating-ui/dom';
|
||||
import { html, nothing, type TemplateResult } from 'lit';
|
||||
@@ -709,13 +714,13 @@ export class EmbedCardToolbar extends WidgetComponent<
|
||||
|
||||
this.disposables.add(
|
||||
this._selection.slots.changed.on(() => {
|
||||
const hasTextSelection = this._selection.find('text');
|
||||
const hasTextSelection = this._selection.find(TextSelection);
|
||||
if (hasTextSelection) {
|
||||
this._hide();
|
||||
return;
|
||||
}
|
||||
|
||||
const blockSelections = this._selection.filter('block');
|
||||
const blockSelections = this._selection.filter(BlockSelection);
|
||||
if (!blockSelections || blockSelections.length !== 1) {
|
||||
this._hide();
|
||||
return;
|
||||
|
||||
@@ -8,12 +8,15 @@ import {
|
||||
} from '@blocksuite/affine-components/toolbar';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import type {
|
||||
BaseSelection,
|
||||
BlockComponent,
|
||||
import {
|
||||
type BaseSelection,
|
||||
type BlockComponent,
|
||||
BlockSelection,
|
||||
CursorSelection,
|
||||
TextSelection,
|
||||
WidgetComponent,
|
||||
} from '@blocksuite/block-std';
|
||||
import { WidgetComponent } from '@blocksuite/block-std';
|
||||
import { DatabaseSelection } from '@blocksuite/data-view';
|
||||
import {
|
||||
assertExists,
|
||||
DisposableGroup,
|
||||
@@ -129,11 +132,12 @@ export class AffineFormatBarWidget extends WidgetComponent {
|
||||
this.disposables.add(
|
||||
this._selectionManager.slots.changed.on(() => {
|
||||
const update = async () => {
|
||||
const textSelection = rootComponent.selection.find('text');
|
||||
const blockSelections = rootComponent.selection.filter('block');
|
||||
const textSelection = rootComponent.selection.find(TextSelection);
|
||||
const blockSelections =
|
||||
rootComponent.selection.filter(BlockSelection);
|
||||
|
||||
// Should not re-render format bar when only cursor selection changed in edgeless
|
||||
const cursorSelection = rootComponent.selection.find('cursor');
|
||||
const cursorSelection = rootComponent.selection.find(CursorSelection);
|
||||
if (cursorSelection) {
|
||||
if (!this._lastCursor) {
|
||||
this._lastCursor = cursorSelection;
|
||||
@@ -202,7 +206,7 @@ export class AffineFormatBarWidget extends WidgetComponent {
|
||||
this.disposables.addFromEvent(document, 'selectionchange', () => {
|
||||
if (!this.host.event.active) return;
|
||||
|
||||
const databaseSelection = this.host.selection.find('database');
|
||||
const databaseSelection = this.host.selection.find(DatabaseSelection);
|
||||
if (!databaseSelection) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,11 @@ import {
|
||||
} from '@blocksuite/affine-components/toolbar';
|
||||
import type { ImageBlockModel } from '@blocksuite/affine-model';
|
||||
import { PAGE_HEADER_HEIGHT } from '@blocksuite/affine-shared/consts';
|
||||
import { WidgetComponent } from '@blocksuite/block-std';
|
||||
import {
|
||||
BlockSelection,
|
||||
TextSelection,
|
||||
WidgetComponent,
|
||||
} from '@blocksuite/block-std';
|
||||
import { limitShift, shift } from '@floating-ui/dom';
|
||||
import { html } from 'lit';
|
||||
|
||||
@@ -35,7 +39,7 @@ export class AffineImageToolbarWidget extends WidgetComponent<
|
||||
const imageBlock = this.block;
|
||||
const selection = this.host.selection;
|
||||
|
||||
const textSelection = selection.find('text');
|
||||
const textSelection = selection.find(TextSelection);
|
||||
if (
|
||||
!!textSelection &&
|
||||
(!!textSelection.to || !!textSelection.from.length)
|
||||
@@ -43,7 +47,7 @@ export class AffineImageToolbarWidget extends WidgetComponent<
|
||||
return null;
|
||||
}
|
||||
|
||||
const blockSelections = selection.filter('block');
|
||||
const blockSelections = selection.filter(BlockSelection);
|
||||
if (
|
||||
blockSelections.length > 1 ||
|
||||
(blockSelections.length === 1 &&
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
getBlockProps,
|
||||
isInsidePageEditor,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { BlockSelection } from '@blocksuite/block-std';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
|
||||
export function duplicate(
|
||||
@@ -38,7 +39,7 @@ export function duplicate(
|
||||
.then(() => {
|
||||
const { selection } = editorHost;
|
||||
selection.setGroup('note', [
|
||||
selection.create('block', {
|
||||
selection.create(BlockSelection, {
|
||||
blockId: duplicateId,
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
import {
|
||||
BLOCK_ID_ATTR,
|
||||
BlockComponent,
|
||||
BlockSelection,
|
||||
type PointerEventState,
|
||||
WidgetComponent,
|
||||
} from '@blocksuite/block-std';
|
||||
@@ -188,7 +189,7 @@ export class AffinePageDraggingAreaWidget extends WidgetComponent<
|
||||
this._allBlocksWithRect,
|
||||
userRect
|
||||
).map(blockPath => {
|
||||
return this.host.selection.create('block', {
|
||||
return this.host.selection.create(BlockSelection, {
|
||||
blockId: blockPath,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
matchFlavours,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import type { UIEventStateContext } from '@blocksuite/block-std';
|
||||
import { WidgetComponent } from '@blocksuite/block-std';
|
||||
import { TextSelection, WidgetComponent } from '@blocksuite/block-std';
|
||||
import {
|
||||
assertExists,
|
||||
assertType,
|
||||
@@ -122,7 +122,7 @@ export class AffineSlashMenuWidget extends WidgetComponent {
|
||||
}
|
||||
}
|
||||
|
||||
const textSelection = this.host.selection.find('text');
|
||||
const textSelection = this.host.selection.find(TextSelection);
|
||||
if (!textSelection) return;
|
||||
|
||||
const model = this.host.doc.getBlock(textSelection.blockId)?.model;
|
||||
@@ -149,7 +149,7 @@ export class AffineSlashMenuWidget extends WidgetComponent {
|
||||
assertType<RootBlockComponent>(rootComponent);
|
||||
|
||||
inlineRangeApplyCallback(() => {
|
||||
const textSelection = this.host.selection.find('text');
|
||||
const textSelection = this.host.selection.find(TextSelection);
|
||||
if (!textSelection) return;
|
||||
|
||||
const model = this.host.doc.getBlock(textSelection.blockId)?.model;
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
TextFormatConfig,
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
import { isInsideBlockByFlavour } from '@blocksuite/affine-shared/utils';
|
||||
import { BlockSelection } from '@blocksuite/block-std';
|
||||
import { assertType } from '@blocksuite/global/utils';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
@@ -128,7 +129,7 @@ export function createTextFormatItem(
|
||||
.chain()
|
||||
.formatBlock({
|
||||
blockSelections: [
|
||||
std.selection.create('block', {
|
||||
std.selection.create(BlockSelection, {
|
||||
blockId: model.id,
|
||||
}),
|
||||
],
|
||||
|
||||
@@ -19,7 +19,11 @@ import {
|
||||
} from '@blocksuite/affine-components/toolbar';
|
||||
import type { SurfaceRefBlockModel } from '@blocksuite/affine-model';
|
||||
import { PAGE_HEADER_HEIGHT } from '@blocksuite/affine-shared/consts';
|
||||
import { WidgetComponent } from '@blocksuite/block-std';
|
||||
import {
|
||||
BlockSelection,
|
||||
TextSelection,
|
||||
WidgetComponent,
|
||||
} from '@blocksuite/block-std';
|
||||
import { offset, shift } from '@floating-ui/dom';
|
||||
import { html, nothing } from 'lit';
|
||||
import { ifDefined } from 'lit/directives/if-defined.js';
|
||||
@@ -48,7 +52,7 @@ export class AffineSurfaceRefToolbar extends WidgetComponent<
|
||||
const surfaceRefBlock = this.block;
|
||||
const selection = this.host.selection;
|
||||
|
||||
const textSelection = selection.find('text');
|
||||
const textSelection = selection.find(TextSelection);
|
||||
if (
|
||||
!!textSelection &&
|
||||
(!!textSelection.to || !!textSelection.from.length)
|
||||
@@ -56,7 +60,7 @@ export class AffineSurfaceRefToolbar extends WidgetComponent<
|
||||
return null;
|
||||
}
|
||||
|
||||
const blockSelections = selection.filter('block');
|
||||
const blockSelections = selection.filter(BlockSelection);
|
||||
if (
|
||||
blockSelections.length > 1 ||
|
||||
(blockSelections.length === 1 &&
|
||||
|
||||
Reference in New Issue
Block a user