fix(editor): should not show inner toolbar of surface-ref in edgeless (#11453)

Closes: [BS-3015](https://linear.app/affine-design/issue/BS-3015/toolbar-有时会出现空状态且被显示) [BS-3023](https://linear.app/affine-design/issue/BS-3023/surface-ref-inner-toolbar-的标题圆角)
This commit is contained in:
fundon
2025-04-03 11:13:09 +00:00
parent a9ba54a92e
commit 565d7b2b1e
7 changed files with 74 additions and 26 deletions

View File

@@ -4,7 +4,7 @@ import {
MindmapElementModel,
ShapeElementModel,
} from '@blocksuite/affine-model';
import { unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme';
import { unsafeCSSVar, unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme';
import {
EdgelessIcon,
FrameIcon,
@@ -24,8 +24,10 @@ export class SurfaceRefToolbarTitle extends ShadowlessElement {
margin-right: auto;
align-items: center;
gap: 4px;
border-radius: 2px;
background: ${unsafeCSSVarV2('button/iconButtonSolid')};
border-radius: 4px;
color: ${unsafeCSSVarV2('text/primary')};
box-shadow: ${unsafeCSSVar('buttonShadow')};
background: ${unsafeCSSVar('white')};
svg {
color: ${unsafeCSSVarV2('icon/primary')};

View File

@@ -11,24 +11,20 @@ import { literal } from 'lit/static-html.js';
import { SurfaceRefSlashMenuConfigExtension } from './configs/slash-menu';
import { surfaceRefToolbarModuleConfig } from './configs/toolbar';
const flavour = SurfaceRefBlockSchema.model.flavour;
export const PageSurfaceRefBlockSpec: ExtensionType[] = [
FlavourExtension(SurfaceRefBlockSchema.model.flavour),
BlockViewExtension(
SurfaceRefBlockSchema.model.flavour,
literal`affine-surface-ref`
),
FlavourExtension(flavour),
BlockViewExtension(flavour, literal`affine-surface-ref`),
ToolbarModuleExtension({
id: BlockFlavourIdentifier(SurfaceRefBlockSchema.model.flavour),
id: BlockFlavourIdentifier(flavour),
config: surfaceRefToolbarModuleConfig,
}),
SurfaceRefSlashMenuConfigExtension,
];
export const EdgelessSurfaceRefBlockSpec: ExtensionType[] = [
FlavourExtension(SurfaceRefBlockSchema.model.flavour),
BlockViewExtension(
SurfaceRefBlockSchema.model.flavour,
literal`affine-edgeless-surface-ref`
),
FlavourExtension(flavour),
BlockViewExtension(flavour, literal`affine-edgeless-surface-ref`),
SurfaceRefSlashMenuConfigExtension,
];

View File

@@ -46,10 +46,14 @@ export class ToolbarRegistryExtension extends Extension {
return this.std.provider.getAll(ToolbarModuleIdentifier);
}
getModuleBy(flavour: string) {
return this.modules.get(flavour)?.config ?? null;
}
getModulePlacement(flavour: string, fallback: ToolbarPlacement = 'top') {
return (
this.modules.get(`custom:${flavour}`)?.config.placement ??
this.modules.get(flavour)?.config.placement ??
this.getModuleBy(`custom:${flavour}`)?.placement ??
this.getModuleBy(flavour)?.placement ??
fallback
);
}

View File

@@ -641,8 +641,6 @@ export class AffineToolbarWidget extends WidgetComponent {
// 4. `Flag.Hovering`: inline links in note/database/table
// 5. `Flag.Surface`: elements in edgeless
renderToolbar(toolbar, context, flavour);
if (toolbar.dataset.open) return;
toolbar.dataset.open = 'true';
})
);

View File

@@ -70,9 +70,8 @@ export function autoUpdatePosition(
offset(({ rects }) => -rects.floating.height),
size({
apply: ({ elements }) => {
elements.floating.style.width = `${
elements.reference.getBoundingClientRect().width
}px`;
const { width } = elements.reference.getBoundingClientRect();
elements.floating.style.width = `${width}px`;
},
}),
],
@@ -126,12 +125,14 @@ export function autoUpdatePosition(
toolbar.style.transform = `translate3d(${x}px, ${y}px, 0)`;
if (toolbar.dataset.open) {
if (middlewareData.hide?.referenceHidden) {
delete toolbar.dataset.open;
if (middlewareData.hide) {
if (toolbar.dataset.open) {
if (middlewareData.hide.referenceHidden) {
delete toolbar.dataset.open;
}
} else {
toolbar.dataset.open = 'true';
}
} else {
toolbar.dataset.open = 'true';
}
};
@@ -239,6 +240,12 @@ export function renderToolbar(
a => a.placement === ActionPlacement.More
);
// Resets
if (primaryActionGroup.length === 0) {
context.reset();
return;
}
const innerToolbar = context.placement$.value === 'inner';
if (moreActionGroup.length) {
@@ -289,6 +296,9 @@ export function renderToolbar(
),
toolbar
);
if (toolbar.dataset.open) return;
toolbar.dataset.open = 'true';
}
function renderActions(