refactor(editor): edgeless element toolbar with new pattern (#10511)

This commit is contained in:
fundon
2025-03-18 15:36:25 +00:00
parent 3939cc1c52
commit cb37d25d7b
31 changed files with 838 additions and 367 deletions

View File

@@ -4,6 +4,7 @@ import type { ToolbarContext } from './context';
export enum ActionPlacement {
Start = 0,
Normal = 1 << 0,
End = 1 << 1,
More = 1 << 2,
}

View File

@@ -2,6 +2,7 @@ import {
type BlockComponent,
BlockSelection,
type BlockStdScope,
SurfaceSelection,
} from '@blocksuite/block-std';
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
import { nextTick } from '@blocksuite/global/utils';
@@ -61,7 +62,8 @@ abstract class ToolbarContextBase {
if (this.flags.accept()) return true;
if (this.host.event.active) return true;
// Selects `embed-synced-doc-block`
return this.host.contains(document.activeElement);
if (this.host.contains(document.activeElement)) return true;
return this.isEdgelessMode;
}
get readonly() {
@@ -108,6 +110,26 @@ abstract class ToolbarContextBase {
return this.toolbarRegistry.message$;
}
getCurrentElement() {
const selection = this.selection.find(SurfaceSelection);
return selection?.elements.length
? this.gfx.getElementById(selection.elements[0])
: null;
}
getCurrentBlock(): Block | null {
return this.getCurrentBlockBy();
}
getCurrentBlockComponent(): BlockComponent | null {
const block = this.getCurrentBlock();
return block && this.view.getBlock(block.id);
}
getCurrentModel() {
return this.getCurrentBlock()?.model ?? null;
}
getCurrentBlockBy<T extends SelectionConstructor>(type?: T): Block | null {
const selection = this.selection.find(type ?? BlockSelection);
return (selection && this.store.getBlock(selection.blockId)) ?? null;
@@ -125,11 +147,10 @@ abstract class ToolbarContextBase {
return matchModels(model, [klass]) ? model : null;
}
getCurrentBlockComponentBy<
T extends SelectionConstructor,
K extends abstract new (...args: any) => any,
>(type: T, klass: K): InstanceType<K> | null {
const block = this.getCurrentBlockBy<T>(type);
getCurrentBlockComponentBy<K extends abstract new (...args: any) => any>(
klass: K
): InstanceType<K> | null {
const block = this.getCurrentBlockBy();
const component = block && this.view.getBlock(block.id);
return this.blockComponentIs(component, klass) ? component : null;
}

View File

@@ -62,6 +62,10 @@ export class Flags {
});
}
isSurface() {
return this.check(Flag.Surface);
}
isText() {
return this.check(Flag.Text);
}
@@ -74,6 +78,10 @@ export class Flags {
return this.check(Flag.Native);
}
isHovering() {
return this.check(Flag.Hovering);
}
accept() {
return this.check(Flag.Accepting);
}