Skip to content

Commit

Permalink
fix: typing
Browse files Browse the repository at this point in the history
  • Loading branch information
doouding committed Oct 22, 2024
1 parent 9076e52 commit 34a6a69
Show file tree
Hide file tree
Showing 42 changed files with 173 additions and 166 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GfxController , GfxModel } from '@blocksuite/block-std/gfx';
import type { GfxController, GfxModel } from '@blocksuite/block-std/gfx';
import type { XYWH } from '@blocksuite/global/utils';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import { EditPropsStore } from '@blocksuite/affine-shared/services';
import { ThemeObserver } from '@blocksuite/affine-shared/theme';
import { SignalWatcher } from '@blocksuite/global/utils';
Expand Down Expand Up @@ -43,7 +45,7 @@ export class EdgelessBrushMenu extends EdgelessToolbarToolMixin(
};
});

type: BlockSuite.GfxToolsFullOptionValue['type'] = 'brush';
type: GfxToolsFullOptionValue['type'] = 'brush';

override render() {
const color = ThemeObserver.getColorValue(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import {
ConnectorCWithArrowIcon,
ConnectorLWithArrowIcon,
Expand Down Expand Up @@ -101,7 +103,7 @@ export class EdgelessConnectorMenu extends EdgelessToolbarToolMixin(
return { mode, stroke, strokeWidth };
});

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'connector';
override type: GfxToolsFullOptionValue['type'] = 'connector';

override render() {
const { stroke, strokeWidth, mode } = this._props$.value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import {
ArrowUpIcon,
HandIcon,
Expand Down Expand Up @@ -32,10 +34,7 @@ export class EdgelessDefaultToolButton extends QuickToolMixin(LitElement) {
}
`;

override type: BlockSuite.GfxToolsFullOptionValue['type'][] = [
'default',
'pan',
];
override type: GfxToolsFullOptionValue['type'][] = ['default', 'pan'];

private _changeTool() {
if (this.toolbar.activePopper) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import {
type MenuHandler,
popMenu,
Expand Down Expand Up @@ -657,7 +659,7 @@ export class EdgelessToolbar extends WithDisposable(LitElement) {
accessor containerWidth = 1920;

@state()
accessor edgelessTool: BlockSuite.GfxToolsFullOptionValue = {
accessor edgelessTool: GfxToolsFullOptionValue = {
type: localStorage.defaultTool ?? 'default',
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import {
EdgelessEraserDarkIcon,
EdgelessEraserLightIcon,
Expand Down Expand Up @@ -35,7 +37,7 @@ export class EdgelessEraserToolButton extends EdgelessToolbarToolMixin(

override enableActiveBackground = true;

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'eraser';
override type: GfxToolsFullOptionValue['type'] = 'eraser';

override firstUpdated() {
this.disposables.add(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import { css, html, LitElement } from 'lit';
import { repeat } from 'lit/directives/repeat.js';

Expand Down Expand Up @@ -63,7 +65,7 @@ export class EdgelessFrameMenu extends EdgelessToolbarToolMixin(LitElement) {
}
`;

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'frame';
override type: GfxToolsFullOptionValue['type'] = 'frame';

override render() {
const { edgeless } = this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import {
ArrowUpIcon,
LargeFrameIcon,
Expand All @@ -22,7 +24,7 @@ export class EdgelessFrameToolButton extends QuickToolMixin(LitElement) {
}
`;

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'frame';
override type: GfxToolsFullOptionValue['type'] = 'frame';

private _toggleFrameMenu() {
if (this.tryDisposePopper()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
MindmapElementModel,
MindmapStyle,
} from '@blocksuite/affine-model';
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';
import type { Bound } from '@blocksuite/global/utils';

import { EditPropsStore } from '@blocksuite/affine-shared/services';
Expand Down Expand Up @@ -131,10 +132,7 @@ export class EdgelessMindmapToolButton extends EdgelessToolbarToolMixin(

override enableActiveBackground = true;

override type: BlockSuite.GfxToolsFullOptionValue['type'][] = [
'empty',
'text',
];
override type: GfxToolsFullOptionValue['type'][] = ['empty', 'text'];

get draggableTools(): DraggableTool[] {
const style = this._style$.value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { ColorScheme } from '@blocksuite/affine-model';
import type { ToolController } from '@blocksuite/block-std/gfx';
import type {
GfxToolsFullOption,
GfxToolsFullOptionValue,
ToolController,
} from '@blocksuite/block-std/gfx';
import type { LitElement } from 'lit';

import {
Expand Down Expand Up @@ -32,7 +36,7 @@ export declare abstract class EdgelessToolbarToolClass extends DisposableClass {

edgeless: EdgelessRootBlockComponent;

edgelessTool: BlockSuite.GfxToolsFullOptionValue;
edgelessTool: GfxToolsFullOptionValue;

enableActiveBackground?: boolean;

Expand All @@ -52,8 +56,8 @@ export declare abstract class EdgelessToolbarToolClass extends DisposableClass {
tryDisposePopper: () => boolean;

abstract type:
| BlockSuite.GfxToolsFullOptionValue['type']
| BlockSuite.GfxToolsFullOptionValue['type'][];
| GfxToolsFullOptionValue['type']
| GfxToolsFullOptionValue['type'][];

accessor toolbar: EdgelessToolbar;
}
Expand All @@ -65,8 +69,8 @@ export const EdgelessToolbarToolMixin = <T extends Constructor<LitElement>>(
enableActiveBackground = false;

abstract type:
| BlockSuite.GfxToolsFullOptionValue['type']
| BlockSuite.GfxToolsFullOptionValue['type'][];
| GfxToolsFullOptionValue['type']
| GfxToolsFullOptionValue['type'][];

get active() {
const { type } = this;
Expand Down Expand Up @@ -149,7 +153,7 @@ export const EdgelessToolbarToolMixin = <T extends Constructor<LitElement>>(
accessor edgeless!: EdgelessRootBlockComponent;

@state()
accessor edgelessTool!: ValueOf<BlockSuite.GfxToolsFullOption> | null;
accessor edgelessTool!: ValueOf<GfxToolsFullOption> | null;

@state()
public accessor popper: MenuPopper<HTMLElement> | null = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import { AttachmentIcon, LinkIcon } from '@blocksuite/affine-components/icons';
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
import { effect } from '@preact/signals-core';
Expand Down Expand Up @@ -49,7 +51,7 @@ export class EdgelessNoteMenu extends EdgelessToolbarToolMixin(LitElement) {
}
`;

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'affine:note';
override type: GfxToolsFullOptionValue['type'] = 'affine:note';

private async _addImages() {
this._imageLoading = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import { ArrowUpIcon, NoteIcon } from '@blocksuite/affine-components/icons';
import { effect } from '@preact/signals-core';
import { css, html, LitElement } from 'lit';
Expand Down Expand Up @@ -29,7 +31,7 @@ export class EdgelessNoteToolButton extends QuickToolMixin(LitElement) {

private _states = ['childFlavour', 'childType', 'tip'] as const;

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'affine:note';
override type: GfxToolsFullOptionValue['type'] = 'affine:note';

private _disposeMenu() {
this._noteMenu?.dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import { FrameNavigatorIcon } from '@blocksuite/affine-components/icons';
import { css, html, LitElement } from 'lit';

Expand All @@ -23,7 +25,7 @@ export class EdgelessPresentButton extends QuickToolMixin(
}
`;

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'frameNavigator';
override type: GfxToolsFullOptionValue['type'] = 'frameNavigator';

override render() {
return html`<edgeless-tool-icon-button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { FrameBlockModel } from '@blocksuite/affine-model';
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import { CommonUtils } from '@blocksuite/affine-block-surface';
import {
Expand Down Expand Up @@ -106,7 +107,7 @@ export class PresentationToolbar extends EdgelessToolbarToolMixin(LitElement) {

private _timer?: ReturnType<typeof setTimeout>;

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'frameNavigator';
override type: GfxToolsFullOptionValue['type'] = 'frameNavigator';

private get _cachedPresentHideToolbar() {
return !!this.edgeless.std
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import { ArrowDownSmallIcon } from '@blocksuite/affine-components/icons';
import { once } from '@blocksuite/affine-shared/utils';
import {
Expand Down Expand Up @@ -115,11 +117,11 @@ export class EdgelessTemplateButton extends EdgelessToolbarToolMixin(

private _cleanup: (() => void) | null = null;

private _prevTool: BlockSuite.GfxToolsFullOptionValue | null = null;
private _prevTool: GfxToolsFullOptionValue | null = null;

override enableActiveBackground = true;

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'template';
override type: GfxToolsFullOptionValue['type'] = 'template';

get cards() {
const { theme } = this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';

import { css, html, LitElement, nothing } from 'lit';
import { property } from 'lit/decorators.js';

Expand All @@ -14,7 +16,7 @@ export class EdgelessTextMenu extends EdgelessToolbarToolMixin(LitElement) {
}
`;

override type: BlockSuite.GfxToolsFullOptionValue['type'] = 'text';
override type: GfxToolsFullOptionValue['type'] = 'text';

override render() {
if (this.edgelessTool.type !== 'text') return nothing;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { MenuConfig } from '@blocksuite/affine-components/context-menu';
import type { GfxToolsMap } from '@blocksuite/block-std/gfx';

import { html, type TemplateResult } from 'lit';

Expand All @@ -9,7 +10,7 @@ import { buildFrameDenseMenu } from './frame/frame-dense-menu.js';
import { buildLinkDenseMenu } from './link/link-dense-menu.js';

export interface QuickTool {
type?: keyof BlockSuite.GfxToolsMap;
type?: keyof GfxToolsMap;
content: TemplateResult;
/**
* if not configured, the tool will not be shown in dense mode
Expand Down
8 changes: 5 additions & 3 deletions packages/blocks/src/root-block/edgeless/edgeless-keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { GfxToolsMap, GfxToolsOption } from '@blocksuite/block-std/gfx';

import {
LayoutType,
MindmapElementModel,
Expand Down Expand Up @@ -634,10 +636,10 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
});
}

private _setEdgelessTool<K extends keyof BlockSuite.GfxToolsMap>(
private _setEdgelessTool<K extends keyof GfxToolsMap>(
toolName: K,
...options: K extends keyof BlockSuite.GfxToolsOption
? [option: BlockSuite.GfxToolsOption[K], ignoreActiveState?: boolean]
...options: K extends keyof GfxToolsOption
? [option: GfxToolsOption[K], ignoreActiveState?: boolean]
: [option: void, ignoreActiveState?: boolean]
) {
const ignoreActiveState =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { BlockComponent } from '@blocksuite/block-std';
import {
GfxBlockElementModel,
GfxControllerIdentifier,
type GfxToolsFullOptionValue,
type GfxViewportElement,
} from '@blocksuite/block-std/gfx';
import { IS_WINDOWS } from '@blocksuite/global/env';
Expand Down Expand Up @@ -960,7 +961,7 @@ export class EdgelessRootBlockComponent extends BlockComponent<
accessor backgroundElm: HTMLDivElement | null = null;

@state()
accessor edgelessTool: BlockSuite.GfxToolsFullOptionValue = {
accessor edgelessTool: GfxToolsFullOptionValue = {
type: localStorage.defaultTool ?? 'default',
};

Expand Down
2 changes: 0 additions & 2 deletions packages/blocks/src/root-block/edgeless/frame-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import type { Doc } from '@blocksuite/store';
import { Overlay } from '@blocksuite/affine-block-surface';
import {
getTopElements,
} from '@blocksuite/affine-model';
import {
type GfxController,
GfxExtension,
GfxExtensionIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@ export class BrushTool extends BaseTool {
}
}

declare global {
namespace BlockSuite {
interface GfxToolsMap {
brush: BrushTool;
}
declare module '@blocksuite/block-std/gfx' {
interface GfxToolsMap {
brush: BrushTool;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,12 @@ export class ConnectorTool extends BaseTool<ConnectorToolOptions> {
}
}

declare global {
namespace BlockSuite {
interface GfxToolsMap {
connector: ConnectorTool;
}
declare module '@blocksuite/block-std/gfx' {
interface GfxToolsMap {
connector: ConnectorTool;
}

interface GfxToolsOption {
connector: ConnectorToolOptions;
}
interface GfxToolsOption {
connector: ConnectorToolOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@ export class CopilotTool extends BaseTool {
}
}

declare global {
namespace BlockSuite {
interface GfxToolsMap {
copilot: CopilotTool;
}
declare module '@blocksuite/block-std/gfx' {
interface GfxToolsMap {
copilot: CopilotTool;
}
}
Loading

0 comments on commit 34a6a69

Please sign in to comment.