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

@@ -217,14 +217,18 @@ function createToolbarMoreMenuConfigV2(baseUrl?: string) {
id: 'copy-as-image',
label: 'Copy as Image',
icon: CopyAsImgaeIcon(),
when: ({ isEdgelessMode, gfx }) =>
isEdgelessMode && gfx.selection.selectedElements.length > 0,
when: ({ isEdgelessMode, gfx, flags }) =>
!flags.isHovering() &&
isEdgelessMode &&
gfx.selection.selectedElements.length > 0,
},
{
id: 'copy-link-to-block',
label: 'Copy link to block',
icon: LinkIcon(),
when: ({ isPageMode, selection, gfx }) => {
when: ({ isPageMode, selection, gfx, flags }) => {
if (flags.isHovering()) return false;
const items = selection
.getGroup('note')
.filter(item =>
@@ -394,7 +398,7 @@ function createToolbarMoreMenuConfigV2(baseUrl?: string) {
}
function createExternalLinkableToolbarConfig(
kclass:
klass:
| typeof BookmarkBlockComponent
| typeof EmbedFigmaBlockComponent
| typeof EmbedGithubBlockComponent
@@ -411,10 +415,7 @@ function createExternalLinkableToolbarConfig(
tooltip: 'Copy link',
icon: CopyIcon(),
run(ctx) {
const model = ctx.getCurrentBlockComponentBy(
BlockSelection,
kclass
)?.model;
const model = ctx.getCurrentBlockComponentBy(klass)?.model;
if (!model) return;
const { url } = model.props;
@@ -439,10 +440,7 @@ function createExternalLinkableToolbarConfig(
tooltip: 'Edit',
icon: EditIcon(),
run(ctx) {
const component = ctx.getCurrentBlockComponentBy(
BlockSelection,
kclass
);
const component = ctx.getCurrentBlockComponentBy(klass);
if (!component) return;
ctx.hide();
@@ -516,7 +514,7 @@ function createOpenDocActionGroup(
id: 'A.open-doc',
actions: openDocActions,
content(ctx) {
const component = ctx.getCurrentBlockComponentBy(BlockSelection, klass);
const component = ctx.getCurrentBlockComponentBy(klass);
if (!component) return null;
const actions = this.actions
@@ -624,7 +622,6 @@ const embedLinkedDocToolbarConfig = {
icon: EditIcon(),
run(ctx) {
const component = ctx.getCurrentBlockComponentBy(
BlockSelection,
EmbedLinkedDocBlockComponent
);
if (!component) return;
@@ -717,7 +714,6 @@ const embedSyncedDocToolbarConfig = {
icon: EditIcon(),
run(ctx) {
const component = ctx.getCurrentBlockComponentBy(
BlockSelection,
EmbedSyncedDocBlockComponent
);
if (!component) return;
@@ -922,7 +918,6 @@ const embedIframeToolbarConfig = {
icon: CopyIcon(),
run(ctx) {
const model = ctx.getCurrentBlockComponentBy(
BlockSelection,
EmbedIframeBlockComponent
)?.model;
if (!model) return;
@@ -950,7 +945,6 @@ const embedIframeToolbarConfig = {
icon: EditIcon(),
run(ctx) {
const component = ctx.getCurrentBlockComponentBy(
BlockSelection,
EmbedIframeBlockComponent
);
if (!component) return;