Files
AFFiNE-Mirror/blocksuite/affine/blocks/surface-ref/src/configs/toolbar.ts
L-Sun 1d865f16fe feat(editor): comment for edgeless element (#13098)
#### PR Dependency Tree


* **PR #13098** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added support for comments on graphical elements, allowing users to
comment on both blocks and graphical elements within surfaces.
* Enhanced comment previews to include graphical elements in selection
summaries.
* Improved editor navigation to focus on commented graphical elements in
addition to blocks and inline texts.

* **Bug Fixes**
* Updated comment highlighting and management to consistently use the
new comment manager across all block and element types.

* **Refactor**
* Renamed and extended the comment manager to handle both block and
element comments.
* Streamlined toolbar configurations by removing outdated comment button
entries and adding a consolidated comment button in the root toolbar.

* **Tests**
* Disabled the mock comment provider integration in the test editor
environment to refine testing setup.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-08 10:33:09 +00:00

96 lines
2.6 KiB
TypeScript

import { toast } from '@blocksuite/affine-components/toast';
import {
copySelectedModelsCommand,
draftSelectedModelsCommand,
} from '@blocksuite/affine-shared/commands';
import {
ActionPlacement,
type ToolbarModuleConfig,
} from '@blocksuite/affine-shared/services';
import { CaptionIcon, CopyIcon, DeleteIcon } from '@blocksuite/icons/lit';
import { html } from 'lit';
import { SurfaceRefBlockComponent } from '../surface-ref-block';
export const surfaceRefToolbarModuleConfig: ToolbarModuleConfig = {
actions: [
{
id: 'a.surface-ref-title',
when: ctx =>
!!ctx.getCurrentBlockByType(SurfaceRefBlockComponent)?.referenceModel,
content: ctx => {
const surfaceRefBlock = ctx.getCurrentBlockByType(
SurfaceRefBlockComponent
);
if (!surfaceRefBlock) return null;
return html`<surface-ref-toolbar-title
.referenceModel=${surfaceRefBlock.referenceModel}
></surface-ref-toolbar-title>`;
},
},
{
id: 'c.copy-surface-ref',
label: 'Copy',
icon: CopyIcon(),
run: ctx => {
const surfaceRefBlock = ctx.getCurrentBlockByType(
SurfaceRefBlockComponent
);
if (!surfaceRefBlock) return;
ctx.chain
.pipe(draftSelectedModelsCommand, {
selectedModels: [surfaceRefBlock.model],
})
.pipe(copySelectedModelsCommand)
.run();
toast(surfaceRefBlock.std.host, 'Copied to clipboard');
},
},
{
id: 'd.surface-ref-caption',
icon: CaptionIcon(),
run: ctx => {
const surfaceRefBlock = ctx.getCurrentBlockByType(
SurfaceRefBlockComponent
);
if (!surfaceRefBlock) return;
surfaceRefBlock.captionElement.show();
},
},
{
id: 'a.clipboard',
placement: ActionPlacement.More,
when: ctx => {
const surfaceRefBlock = ctx.getCurrentBlock();
if (!(surfaceRefBlock instanceof SurfaceRefBlockComponent))
return false;
return !!surfaceRefBlock.referenceModel;
},
actions: [
// TODO(@L-Sun): add duplicate action after refactoring root-block/edgeless
],
},
{
id: 'g.surface-ref-deletion',
label: 'Delete',
icon: DeleteIcon(),
placement: ActionPlacement.More,
variant: 'destructive',
run: ctx => {
const surfaceRefBlock = ctx.getCurrentBlockByType(
SurfaceRefBlockComponent
);
if (!surfaceRefBlock) return;
ctx.store.deleteBlock(surfaceRefBlock.model);
},
},
],
placement: 'inner',
};