fix(editor): block selected style in note under edgeless (#10326)
Related to: https://github.com/toeverything/AFFiNE/pull/9849 Currently missing selected style in note under edgeless. <img width="860" alt="Screenshot 2025-02-20 at 20 51 12" src="https://github.com/user-attachments/assets/77d68cfb-13d0-4e09-a567-f2a30ba72db1" />
This commit is contained in:
@@ -38,8 +38,6 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
|
|
||||||
protected _isResizing = false;
|
protected _isResizing = false;
|
||||||
|
|
||||||
protected _isSelected = false;
|
|
||||||
|
|
||||||
protected _whenHover: HoverController | null = new HoverController(
|
protected _whenHover: HoverController | null = new HoverController(
|
||||||
this,
|
this,
|
||||||
({ abortController }) => {
|
({ abortController }) => {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class AttachmentEdgelessBlockComponent extends toGfxBlockComponent(
|
|||||||
this.slots.elementResizeEnd.on(() => {
|
this.slots.elementResizeEnd.on(() => {
|
||||||
this._isResizing = false;
|
this._isResizing = false;
|
||||||
this._showOverlay =
|
this._showOverlay =
|
||||||
this._isResizing || this._isDragging || !this._isSelected;
|
this._isResizing || this._isDragging || !this.selected$.peek();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import {
|
|||||||
} from '@blocksuite/affine-components/caption';
|
} from '@blocksuite/affine-components/caption';
|
||||||
import type { BookmarkBlockModel } from '@blocksuite/affine-model';
|
import type { BookmarkBlockModel } from '@blocksuite/affine-model';
|
||||||
import { DocModeProvider } from '@blocksuite/affine-shared/services';
|
import { DocModeProvider } from '@blocksuite/affine-shared/services';
|
||||||
|
import { computed, type ReadonlySignal } from '@preact/signals-core';
|
||||||
import { html } from 'lit';
|
import { html } from 'lit';
|
||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
import { classMap } from 'lit/directives/class-map.js';
|
import { type ClassInfo, classMap } from 'lit/directives/class-map.js';
|
||||||
import { type StyleInfo, styleMap } from 'lit/directives/style-map.js';
|
import { type StyleInfo, styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
import { refreshBookmarkUrlData } from './utils.js';
|
import { refreshBookmarkUrlData } from './utils.js';
|
||||||
@@ -14,6 +15,12 @@ import { refreshBookmarkUrlData } from './utils.js';
|
|||||||
export const BOOKMARK_MIN_WIDTH = 450;
|
export const BOOKMARK_MIN_WIDTH = 450;
|
||||||
|
|
||||||
export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBlockModel> {
|
export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBlockModel> {
|
||||||
|
selectedStyle$: ReadonlySignal<ClassInfo> | null = computed<ClassInfo>(
|
||||||
|
() => ({
|
||||||
|
'selected-style': this.selected$.value,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
private _fetchAbortController?: AbortController;
|
private _fetchAbortController?: AbortController;
|
||||||
|
|
||||||
blockDraggable = true;
|
blockDraggable = true;
|
||||||
@@ -69,16 +76,12 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
override renderBlock() {
|
override renderBlock() {
|
||||||
const selected = this.selected$.value;
|
|
||||||
const isInEdgeless =
|
|
||||||
this.std.get(DocModeProvider).getEditorMode() === 'edgeless';
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div
|
<div
|
||||||
draggable="${this.blockDraggable ? 'true' : 'false'}"
|
draggable="${this.blockDraggable ? 'true' : 'false'}"
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
'affine-bookmark-container': true,
|
'affine-bookmark-container': true,
|
||||||
'selected-style': selected && !isInEdgeless,
|
...this.selectedStyle$?.value,
|
||||||
})}
|
})}
|
||||||
style=${this.containerStyleMap}
|
style=${this.containerStyleMap}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import { BookmarkBlockComponent } from './bookmark-block.js';
|
|||||||
export class BookmarkEdgelessBlockComponent extends toGfxBlockComponent(
|
export class BookmarkEdgelessBlockComponent extends toGfxBlockComponent(
|
||||||
BookmarkBlockComponent
|
BookmarkBlockComponent
|
||||||
) {
|
) {
|
||||||
|
override selectedStyle$ = null;
|
||||||
|
|
||||||
override blockDraggable = false;
|
override blockDraggable = false;
|
||||||
|
|
||||||
override getRenderingRect() {
|
override getRenderingRect() {
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ import { DocModeProvider } from '@blocksuite/affine-shared/services';
|
|||||||
import type { BlockService } from '@blocksuite/block-std';
|
import type { BlockService } from '@blocksuite/block-std';
|
||||||
import type { GfxCompatibleProps } from '@blocksuite/block-std/gfx';
|
import type { GfxCompatibleProps } from '@blocksuite/block-std/gfx';
|
||||||
import type { BlockModel } from '@blocksuite/store';
|
import type { BlockModel } from '@blocksuite/store';
|
||||||
|
import { computed, type ReadonlySignal } from '@preact/signals-core';
|
||||||
import type { TemplateResult } from 'lit';
|
import type { TemplateResult } from 'lit';
|
||||||
import { html } from 'lit';
|
import { html } from 'lit';
|
||||||
import { query } from 'lit/decorators.js';
|
import { query } from 'lit/decorators.js';
|
||||||
import { classMap } from 'lit/directives/class-map.js';
|
import { type ClassInfo, classMap } from 'lit/directives/class-map.js';
|
||||||
import { type StyleInfo, styleMap } from 'lit/directives/style-map.js';
|
import { type StyleInfo, styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
export class EmbedBlockComponent<
|
export class EmbedBlockComponent<
|
||||||
@@ -23,6 +24,12 @@ export class EmbedBlockComponent<
|
|||||||
Service extends BlockService = BlockService,
|
Service extends BlockService = BlockService,
|
||||||
WidgetName extends string = string,
|
WidgetName extends string = string,
|
||||||
> extends CaptionedBlockComponent<Model, Service, WidgetName> {
|
> extends CaptionedBlockComponent<Model, Service, WidgetName> {
|
||||||
|
selectedStyle$: ReadonlySignal<ClassInfo> | null = computed<ClassInfo>(
|
||||||
|
() => ({
|
||||||
|
'selected-style': this.selected$.value,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
private _fetchAbortController = new AbortController();
|
private _fetchAbortController = new AbortController();
|
||||||
|
|
||||||
_cardStyle: EmbedCardStyle = 'horizontal';
|
_cardStyle: EmbedCardStyle = 'horizontal';
|
||||||
@@ -43,10 +50,6 @@ export class EmbedBlockComponent<
|
|||||||
protected embedContainerStyle: StyleInfo = {};
|
protected embedContainerStyle: StyleInfo = {};
|
||||||
|
|
||||||
renderEmbed = (content: () => TemplateResult) => {
|
renderEmbed = (content: () => TemplateResult) => {
|
||||||
const selected = this.selected$.value;
|
|
||||||
const isInEdgeless =
|
|
||||||
this.std.get(DocModeProvider).getEditorMode() === 'edgeless';
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this._cardStyle === 'horizontal' ||
|
this._cardStyle === 'horizontal' ||
|
||||||
this._cardStyle === 'horizontalThin' ||
|
this._cardStyle === 'horizontalThin' ||
|
||||||
@@ -54,7 +57,7 @@ export class EmbedBlockComponent<
|
|||||||
) {
|
) {
|
||||||
this.style.display = 'block';
|
this.style.display = 'block';
|
||||||
|
|
||||||
if (isInEdgeless) {
|
if (this.std.get(DocModeProvider).getEditorMode() === 'edgeless') {
|
||||||
this.style.minWidth = `${EMBED_CARD_MIN_WIDTH}px`;
|
this.style.minWidth = `${EMBED_CARD_MIN_WIDTH}px`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +67,7 @@ export class EmbedBlockComponent<
|
|||||||
draggable="${this.blockDraggable ? 'true' : 'false'}"
|
draggable="${this.blockDraggable ? 'true' : 'false'}"
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
'embed-block-container': true,
|
'embed-block-container': true,
|
||||||
'selected-style': selected && !isInEdgeless,
|
...this.selectedStyle$?.value,
|
||||||
})}
|
})}
|
||||||
style=${styleMap({
|
style=${styleMap({
|
||||||
height: `${this._cardHeight}px`,
|
height: `${this._cardHeight}px`,
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ export function toEdgelessEmbedBlock<
|
|||||||
B extends typeof EmbedBlockComponent<Model, Service, WidgetName>,
|
B extends typeof EmbedBlockComponent<Model, Service, WidgetName>,
|
||||||
>(block: B) {
|
>(block: B) {
|
||||||
return class extends toGfxBlockComponent(block) {
|
return class extends toGfxBlockComponent(block) {
|
||||||
|
override selectedStyle$ = null;
|
||||||
|
|
||||||
_isDragging = false;
|
_isDragging = false;
|
||||||
|
|
||||||
_isResizing = false;
|
_isResizing = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user