mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
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:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -123,6 +123,10 @@ abstract class ToolbarContextBase {
|
||||
return this.toolbarRegistry.flavour$;
|
||||
}
|
||||
|
||||
get placement$() {
|
||||
return this.toolbarRegistry.placement$;
|
||||
}
|
||||
|
||||
get message$() {
|
||||
return this.toolbarRegistry.message$;
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user