mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
refactor(editor): remove service global type (#10129)
Closes: [BS-2566](https://linear.app/affine-design/issue/BS-2566/remove-global-types-in-service)
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
import type * as SurfaceEffects from '@blocksuite/affine-block-surface/effects';
|
||||
|
||||
declare type _GLOBAL_ = typeof SurfaceEffects;
|
||||
|
||||
export * from './adapters/notion-html';
|
||||
export * from './attachment-block';
|
||||
export * from './attachment-service';
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import type * as CommandsType from '@blocksuite/affine-shared/commands';
|
||||
|
||||
import { CodeBlockComponent } from './code-block';
|
||||
import type { CodeBlockConfig } from './code-block-config';
|
||||
import {
|
||||
@@ -18,8 +16,6 @@ export function effects() {
|
||||
customElements.define('affine-code', CodeBlockComponent);
|
||||
}
|
||||
|
||||
declare type _GLOBAL_ = typeof CommandsType;
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockConfigs {
|
||||
|
||||
@@ -1,30 +1,18 @@
|
||||
import type * as SurfaceEffects from '@blocksuite/affine-block-surface/effects';
|
||||
|
||||
import { EmbedFigmaBlockComponent } from './embed-figma-block';
|
||||
import { EmbedEdgelessBlockComponent } from './embed-figma-block/embed-edgeless-figma-block';
|
||||
import type { EmbedFigmaBlockService } from './embed-figma-block/embed-figma-service';
|
||||
import {
|
||||
EmbedGithubBlockComponent,
|
||||
type EmbedGithubBlockService,
|
||||
} from './embed-github-block';
|
||||
import { EmbedGithubBlockComponent } from './embed-github-block';
|
||||
import { EmbedEdgelessGithubBlockComponent } from './embed-github-block/embed-edgeless-github-block';
|
||||
import { EmbedHtmlBlockComponent } from './embed-html-block';
|
||||
import { EmbedHtmlFullscreenToolbar } from './embed-html-block/components/fullscreen-toolbar';
|
||||
import { EmbedEdgelessHtmlBlockComponent } from './embed-html-block/embed-edgeless-html-block';
|
||||
import { EmbedLinkedDocBlockComponent } from './embed-linked-doc-block';
|
||||
import { EmbedEdgelessLinkedDocBlockComponent } from './embed-linked-doc-block/embed-edgeless-linked-doc-block';
|
||||
import {
|
||||
EmbedLoomBlockComponent,
|
||||
type EmbedLoomBlockService,
|
||||
} from './embed-loom-block';
|
||||
import { EmbedLoomBlockComponent } from './embed-loom-block';
|
||||
import { EmbedEdgelessLoomBlockComponent } from './embed-loom-block/embed-edgeless-loom-bock';
|
||||
import { EmbedSyncedDocBlockComponent } from './embed-synced-doc-block';
|
||||
import { EmbedSyncedDocCard } from './embed-synced-doc-block/components/embed-synced-doc-card';
|
||||
import { EmbedEdgelessSyncedDocBlockComponent } from './embed-synced-doc-block/embed-edgeless-synced-doc-block';
|
||||
import {
|
||||
EmbedYoutubeBlockComponent,
|
||||
type EmbedYoutubeBlockService,
|
||||
} from './embed-youtube-block';
|
||||
import { EmbedYoutubeBlockComponent } from './embed-youtube-block';
|
||||
import { EmbedEdgelessYoutubeBlockComponent } from './embed-youtube-block/embed-edgeless-youtube-block';
|
||||
|
||||
export function effects() {
|
||||
@@ -86,8 +74,6 @@ export function effects() {
|
||||
);
|
||||
}
|
||||
|
||||
declare type _GLOBAL = typeof SurfaceEffects;
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'affine-embed-figma-block': EmbedFigmaBlockComponent;
|
||||
@@ -107,13 +93,4 @@ declare global {
|
||||
'affine-embed-linked-doc-block': EmbedLinkedDocBlockComponent;
|
||||
'affine-embed-edgeless-linked-doc-block': EmbedEdgelessLinkedDocBlockComponent;
|
||||
}
|
||||
|
||||
namespace BlockSuite {
|
||||
interface BlockServices {
|
||||
'affine:embed-figma': EmbedFigmaBlockService;
|
||||
'affine:embed-github': EmbedGithubBlockService;
|
||||
'affine:embed-loom': EmbedLoomBlockService;
|
||||
'affine:embed-youtube': EmbedYoutubeBlockService;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import type * as SurfaceEffects from '@blocksuite/affine-block-surface/effects';
|
||||
|
||||
declare type _GLOBAL_ = typeof SurfaceEffects;
|
||||
|
||||
export * from './adapters';
|
||||
export * from './commands';
|
||||
export * from './image-block';
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
AFFINE_EDGELESS_NOTE,
|
||||
EdgelessNoteBlockComponent,
|
||||
} from './note-edgeless-block';
|
||||
import type { NoteBlockService } from './note-service';
|
||||
|
||||
export function effects() {
|
||||
customElements.define('affine-note', NoteBlockComponent);
|
||||
@@ -19,9 +18,6 @@ export function effects() {
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockServices {
|
||||
'affine:note': NoteBlockService;
|
||||
}
|
||||
interface BlockConfigs {
|
||||
'affine:note': NoteConfig;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { effects as ParagraphHeadingIconEffects } from './heading-icon.js';
|
||||
import { ParagraphBlockComponent } from './paragraph-block.js';
|
||||
import type { ParagraphBlockService } from './paragraph-service.js';
|
||||
|
||||
export function effects() {
|
||||
ParagraphHeadingIconEffects();
|
||||
@@ -8,11 +7,6 @@ export function effects() {
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockServices {
|
||||
'affine:paragraph': ParagraphBlockService;
|
||||
}
|
||||
}
|
||||
interface HTMLElementTagNameMap {
|
||||
'affine-paragraph': ParagraphBlockComponent;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import type * as SurfaceEffects from '@blocksuite/affine-block-surface/effects';
|
||||
|
||||
declare type _GLOBAL_ = typeof SurfaceEffects;
|
||||
|
||||
export * from './consts';
|
||||
export * from './drag-handle';
|
||||
export * from './utils';
|
||||
|
||||
@@ -143,7 +143,6 @@ import {
|
||||
PageRootBlockComponent,
|
||||
PreviewRootBlockComponent,
|
||||
type RootBlockConfig,
|
||||
type RootService,
|
||||
} from './root-block/index.js';
|
||||
import { AIFinishTip } from './root-block/widgets/ai-panel/components/finish-tip.js';
|
||||
import { GeneratingPlaceholder } from './root-block/widgets/ai-panel/components/generating-placeholder.js';
|
||||
@@ -400,8 +399,5 @@ declare global {
|
||||
interface BlockConfigs {
|
||||
'affine:page': RootBlockConfig;
|
||||
}
|
||||
interface BlockServices {
|
||||
'affine:page': RootService;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,11 @@ import { Clipboard } from '../clipboard/index.js';
|
||||
import { CommandManager } from '../command/index.js';
|
||||
import { UIEventDispatcher } from '../event/index.js';
|
||||
import { DndController } from '../extension/dnd/index.js';
|
||||
import type { BlockService } from '../extension/index.js';
|
||||
import { GfxController } from '../gfx/controller.js';
|
||||
import { GfxSelectionManager } from '../gfx/selection.js';
|
||||
import { SurfaceMiddlewareExtension } from '../gfx/surface-middleware.js';
|
||||
import { ViewManager } from '../gfx/view/view-manager.js';
|
||||
import {
|
||||
BlockServiceIdentifier,
|
||||
BlockViewIdentifier,
|
||||
ConfigIdentifier,
|
||||
LifeCycleWatcherIdentifier,
|
||||
@@ -152,18 +150,6 @@ export class BlockStdScope {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* BlockService will be removed in the future.
|
||||
*/
|
||||
getService<Key extends BlockSuite.ServiceKeys>(
|
||||
flavour: Key
|
||||
): BlockSuite.BlockServices[Key] | null;
|
||||
getService<Service extends BlockService>(flavour: string): Service | null;
|
||||
getService(flavour: string): BlockService | null {
|
||||
return this.getOptional(BlockServiceIdentifier(flavour));
|
||||
}
|
||||
|
||||
getView(flavour: string) {
|
||||
return this.getOptional(BlockViewIdentifier(flavour));
|
||||
}
|
||||
@@ -208,10 +194,8 @@ export class BlockStdScope {
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockServices {}
|
||||
interface BlockConfigs {}
|
||||
|
||||
type ServiceKeys = string & keyof BlockServices;
|
||||
type ConfigKeys = string & keyof BlockConfigs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { html } from 'lit/static-html.js';
|
||||
|
||||
import type { EventName, UIEventHandler } from '../../event/index.js';
|
||||
import type { BlockService } from '../../extension/index.js';
|
||||
import { BlockServiceIdentifier } from '../../identifier.js';
|
||||
import type { BlockStdScope } from '../../scope/index.js';
|
||||
import { BlockSelection } from '../../selection/index.js';
|
||||
import { PropTypes, requiredProperties } from '../decorators/index.js';
|
||||
@@ -146,9 +147,11 @@ export class BlockComponent<
|
||||
if (this._service) {
|
||||
return this._service;
|
||||
}
|
||||
const service = this.std.getService(this.model.flavour) as Service;
|
||||
this._service = service;
|
||||
return service;
|
||||
const service = this.std.getOptional(
|
||||
BlockServiceIdentifier(this.model.flavour)
|
||||
);
|
||||
this._service = service as Service;
|
||||
return service as Service;
|
||||
}
|
||||
|
||||
get topContenteditableElement(): BlockComponent | null {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { SurfaceBlockModel } from '@blocksuite/blocks';
|
||||
import { BlockServiceIdentifier } from '@blocksuite/block-std';
|
||||
import type { PageRootService, SurfaceBlockModel } from '@blocksuite/blocks';
|
||||
import type { PointLocation } from '@blocksuite/global/utils';
|
||||
import { beforeEach, expect, test } from 'vitest';
|
||||
|
||||
@@ -24,7 +25,9 @@ const fieldChecker: Record<string, (value: any) => boolean> = {
|
||||
const skipFields = new Set(['_lastXYWH']);
|
||||
|
||||
const snapshotTest = async (snapshotUrl: string, elementsCount: number) => {
|
||||
const pageService = window.editor.host!.std.getService('affine:page');
|
||||
const pageService = window.editor.host!.std.getOptional(
|
||||
BlockServiceIdentifier('affine:page')
|
||||
) as PageRootService;
|
||||
if (!pageService) {
|
||||
throw new Error('page service not found');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user