feat(editor): inner toolbar layout for block (#11243)

Close [BS-2808](https://linear.app/affine-design/issue/BS-2808/组件内-toolbar-重构)
This commit is contained in:
L-Sun
2025-03-28 03:47:37 +00:00
parent 7193393a06
commit e2c752d56f
8 changed files with 150 additions and 62 deletions

View File

@@ -3,10 +3,14 @@ import type { Placement } from '@floating-ui/dom';
import type { ToolbarActions } from './action';
import type { ToolbarContext } from './context';
export type ToolbarPlacement =
| Extract<Placement, 'top' | 'top-start'>
| 'inner';
export type ToolbarModuleConfig = {
actions: ToolbarActions;
when?: ((ctx: ToolbarContext) => boolean) | boolean;
placement?: Extract<Placement, 'top' | 'top-start'>;
placement?: ToolbarPlacement;
};

View File

@@ -123,6 +123,10 @@ abstract class ToolbarContextBase {
return this.toolbarRegistry.flavour$;
}
get placement$() {
return this.toolbarRegistry.placement$;
}
get message$() {
return this.toolbarRegistry.message$;
}

View File

@@ -4,6 +4,7 @@ import { type Container, createIdentifier } from '@blocksuite/global/di';
import { Extension, type ExtensionType } from '@blocksuite/store';
import { signal } from '@preact/signals-core';
import type { ToolbarPlacement } from './config';
import { Flags } from './flags';
import type { ToolbarModule } from './module';
@@ -33,6 +34,8 @@ export class ToolbarRegistryExtension extends Extension {
setFloating: (element?: Element) => void;
} | null>(null);
placement$ = signal<ToolbarPlacement>('top');
flags = new Flags();
constructor(readonly std: BlockStdScope) {
@@ -43,6 +46,14 @@ export class ToolbarRegistryExtension extends Extension {
return this.std.provider.getAll(ToolbarModuleIdentifier);
}
getModulePlacement(flavour: string, fallback: ToolbarPlacement = 'top') {
return (
this.modules.get(`custom:${flavour}`)?.config.placement ??
this.modules.get(flavour)?.config.placement ??
fallback
);
}
static override setup(di: Container) {
di.addImpl(ToolbarRegistryIdentifier, this, [StdIdentifier]);
}