mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 02:21:51 +08:00
@@ -1,5 +1,8 @@
|
||||
/* oxlint-disable @typescript-eslint/no-non-null-assertion */
|
||||
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
||||
import {
|
||||
DefaultTool,
|
||||
EdgelessLegacySlotIdentifier,
|
||||
} from '@blocksuite/affine-block-surface';
|
||||
import {
|
||||
type MenuHandler,
|
||||
popMenu,
|
||||
@@ -430,8 +433,7 @@ export class EdgelessToolbarWidget extends WidgetComponent<RootBlockModel> {
|
||||
}
|
||||
|
||||
get edgelessTool() {
|
||||
// FIXME: maybe we need to fix this type
|
||||
return this.gfx.tool.currentToolOption$.value as { type: string };
|
||||
return this.gfx.tool.currentToolName$.value;
|
||||
}
|
||||
|
||||
get gfx() {
|
||||
@@ -439,7 +441,7 @@ export class EdgelessToolbarWidget extends WidgetComponent<RootBlockModel> {
|
||||
}
|
||||
|
||||
get isPresentMode() {
|
||||
return this.edgelessTool.type === 'frameNavigator';
|
||||
return this.edgelessTool === 'frameNavigator';
|
||||
}
|
||||
|
||||
get scrollSeniorToolSize() {
|
||||
@@ -523,7 +525,7 @@ export class EdgelessToolbarWidget extends WidgetComponent<RootBlockModel> {
|
||||
@click=${this._openMoreQuickToolsMenu}
|
||||
?active=${this._quickTools
|
||||
.slice(this._visibleQuickToolSize)
|
||||
.some(tool => tool.type === this.edgelessTool?.type)}
|
||||
.some(tool => tool.type === this.edgelessTool)}
|
||||
>
|
||||
${MoreHorizontalIcon({ width: '20px', height: '20px' })}
|
||||
<affine-tooltip tip-position="top" .offset=${25}>
|
||||
@@ -602,16 +604,15 @@ export class EdgelessToolbarWidget extends WidgetComponent<RootBlockModel> {
|
||||
{
|
||||
Escape: () => {
|
||||
if (this.gfx.selection.editing) return;
|
||||
if (this.edgelessTool.type === 'frameNavigator') return;
|
||||
if (this.edgelessTool.type === 'default') {
|
||||
if (this.edgelessTool === 'frameNavigator') return;
|
||||
if (this.edgelessTool === 'default') {
|
||||
if (this.activePopper) {
|
||||
this.activePopper.dispose();
|
||||
this.activePopper = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// @ts-expect-error FIXME: resolve after gfx tool refactor
|
||||
this.gfx.tool.setTool('default');
|
||||
this.gfx.tool.setTool(DefaultTool);
|
||||
},
|
||||
},
|
||||
{ global: true }
|
||||
@@ -658,7 +659,7 @@ export class EdgelessToolbarWidget extends WidgetComponent<RootBlockModel> {
|
||||
}
|
||||
|
||||
override render() {
|
||||
const { type } = this.edgelessTool || {};
|
||||
const type = this.edgelessTool;
|
||||
if (this.doc.readonly && type !== 'frameNavigator') {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { MenuConfig } from '@blocksuite/affine-components/context-menu';
|
||||
import { createIdentifier } from '@blocksuite/global/di';
|
||||
import type { BlockComponent } from '@blocksuite/std';
|
||||
import type { GfxController, GfxToolsMap } from '@blocksuite/std/gfx';
|
||||
import type { GfxController } from '@blocksuite/std/gfx';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
import { type TemplateResult } from 'lit';
|
||||
|
||||
export interface QuickTool {
|
||||
type?: keyof GfxToolsMap;
|
||||
type?: string;
|
||||
enable?: boolean;
|
||||
content: TemplateResult;
|
||||
/**
|
||||
|
||||
@@ -9,9 +9,9 @@ import type { BlockComponent } from '@blocksuite/std';
|
||||
import {
|
||||
type GfxController,
|
||||
GfxControllerIdentifier,
|
||||
type GfxToolsFullOption,
|
||||
type GfxToolsFullOptionValue,
|
||||
type ToolController,
|
||||
type ToolOptionWithType,
|
||||
type ToolType,
|
||||
} from '@blocksuite/std/gfx';
|
||||
import { consume } from '@lit/context';
|
||||
import { effect } from '@preact/signals-core';
|
||||
@@ -28,8 +28,6 @@ import {
|
||||
import { createPopper, type MenuPopper } from '../create-popper';
|
||||
import type { EdgelessToolbarWidget } from '../edgeless-toolbar';
|
||||
|
||||
type ValueOf<T> = T[keyof T];
|
||||
|
||||
export declare abstract class EdgelessToolbarToolClass extends DisposableClass {
|
||||
active: boolean;
|
||||
|
||||
@@ -37,7 +35,7 @@ export declare abstract class EdgelessToolbarToolClass extends DisposableClass {
|
||||
|
||||
edgeless: BlockComponent;
|
||||
|
||||
edgelessTool: GfxToolsFullOptionValue;
|
||||
edgelessTool: ToolOptionWithType;
|
||||
|
||||
enableActiveBackground?: boolean;
|
||||
|
||||
@@ -58,9 +56,7 @@ export declare abstract class EdgelessToolbarToolClass extends DisposableClass {
|
||||
*/
|
||||
tryDisposePopper: () => boolean;
|
||||
|
||||
abstract type:
|
||||
| GfxToolsFullOptionValue['type']
|
||||
| GfxToolsFullOptionValue['type'][];
|
||||
abstract type: ToolType | ToolType[];
|
||||
|
||||
accessor toolbar: EdgelessToolbarWidget;
|
||||
}
|
||||
@@ -71,19 +67,15 @@ export const EdgelessToolbarToolMixin = <T extends Constructor<LitElement>>(
|
||||
abstract class DerivedClass extends WithDisposable(SuperClass) {
|
||||
enableActiveBackground = false;
|
||||
|
||||
abstract type:
|
||||
| GfxToolsFullOptionValue['type']
|
||||
| GfxToolsFullOptionValue['type'][];
|
||||
abstract type: ToolType | ToolType[];
|
||||
|
||||
get active() {
|
||||
const { type } = this;
|
||||
// @ts-expect-error FIXME: we need to fix the type of edgelessTool
|
||||
const activeType = this.edgelessTool?.type;
|
||||
const activeType = this.edgelessTool?.toolType;
|
||||
|
||||
return activeType
|
||||
? Array.isArray(type)
|
||||
? // @ts-expect-error FIXME: we need to fix the type of edgelessTool
|
||||
type.includes(activeType)
|
||||
? type.includes(activeType)
|
||||
: activeType === type
|
||||
: false;
|
||||
}
|
||||
@@ -93,12 +85,7 @@ export const EdgelessToolbarToolMixin = <T extends Constructor<LitElement>>(
|
||||
}
|
||||
|
||||
get setEdgelessTool() {
|
||||
return (...args: Parameters<ToolController['setTool']>) => {
|
||||
this.gfx.tool.setTool(
|
||||
// @ts-expect-error FIXME: ts error
|
||||
...args
|
||||
);
|
||||
};
|
||||
return this.gfx.tool.setTool;
|
||||
}
|
||||
|
||||
private _applyActiveStyle() {
|
||||
@@ -162,7 +149,7 @@ export const EdgelessToolbarToolMixin = <T extends Constructor<LitElement>>(
|
||||
accessor edgeless!: BlockComponent;
|
||||
|
||||
@state()
|
||||
accessor edgelessTool!: ValueOf<GfxToolsFullOption> | null;
|
||||
accessor edgelessTool!: ToolOptionWithType | null;
|
||||
|
||||
@state()
|
||||
public accessor popper: MenuPopper<HTMLElement> | null = null;
|
||||
|
||||
Reference in New Issue
Block a user