There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
refactor(editor): remove service global type (#10129)
Saul-Mironee7cc710f8ea7
diff --git a/blocksuite/affine/block-attachment/src/index.ts b/blocksuite/affine/block-attachment/src/index.tsindex ad03de0d56..4298e7a67f 100644--- a/blocksuite/affine/block-attachment/src/index.ts+++ b/blocksuite/affine/block-attachment/src/index.ts@@ -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';diff --git a/blocksuite/affine/block-code/src/effects.ts b/blocksuite/affine/block-code/src/effects.tsindex 875201b09c..ac7b0ec0ef 100644--- a/blocksuite/affine/block-code/src/effects.ts+++ b/blocksuite/affine/block-code/src/effects.ts@@ -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 {diff --git a/blocksuite/affine/block-embed/src/effects.ts b/blocksuite/affine/block-embed/src/effects.tsindex a5d223e69d..cb78258fe2 100644--- a/blocksuite/affine/block-embed/src/effects.ts+++ b/blocksuite/affine/block-embed/src/effects.ts@@ -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;- }- }}diff --git a/blocksuite/affine/block-image/src/index.ts b/blocksuite/affine/block-image/src/index.tsindex 95a412ba13..808a4d44eb 100644--- a/blocksuite/affine/block-image/src/index.ts+++ b/blocksuite/affine/block-image/src/index.ts@@ -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';diff --git a/blocksuite/affine/block-note/src/effects.ts b/blocksuite/affine/block-note/src/effects.tsindex 6372bf6537..3321d00d3e 100644--- a/blocksuite/affine/block-note/src/effects.ts+++ b/blocksuite/affine/block-note/src/effects.ts@@ -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;}diff --git a/blocksuite/affine/block-paragraph/src/effects.ts b/blocksuite/affine/block-paragraph/src/effects.tsindex 4f633f167b..24349f01a9 100644--- a/blocksuite/affine/block-paragraph/src/effects.ts+++ b/blocksuite/affine/block-paragraph/src/effects.ts@@ -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;}diff --git a/blocksuite/affine/widget-drag-handle/src/index.ts b/blocksuite/affine/widget-drag-handle/src/index.tsindex c7b9579d66..1703f9557f 100644--- a/blocksuite/affine/widget-drag-handle/src/index.ts+++ b/blocksuite/affine/widget-drag-handle/src/index.ts@@ -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';diff --git a/blocksuite/blocks/src/effects.ts b/blocksuite/blocks/src/effects.tsindex b58cd3c9b3..aa50bbbee2 100644--- a/blocksuite/blocks/src/effects.ts+++ b/blocksuite/blocks/src/effects.ts@@ -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;- }}}diff --git a/blocksuite/framework/block-std/src/scope/block-std-scope.ts b/blocksuite/framework/block-std/src/scope/block-std-scope.tsindex 608c4802d1..f37b9b66b1 100644--- a/blocksuite/framework/block-std/src/scope/block-std-scope.ts+++ b/blocksuite/framework/block-std/src/scope/block-std-scope.ts@@ -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;}}diff --git a/blocksuite/framework/block-std/src/view/element/block-component.ts b/blocksuite/framework/block-std/src/view/element/block-component.tsindex 0f14ad240f..864278faf8 100644--- a/blocksuite/framework/block-std/src/view/element/block-component.ts+++ b/blocksuite/framework/block-std/src/view/element/block-component.ts@@ -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 {diff --git a/blocksuite/presets/src/__tests__/main/snapshot.spec.ts b/blocksuite/presets/src/__tests__/main/snapshot.spec.tsindex 2991a6a00d..f442873751 100644--- a/blocksuite/presets/src/__tests__/main/snapshot.spec.ts+++ b/blocksuite/presets/src/__tests__/main/snapshot.spec.ts@@ -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');}