Skip to content

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.

refactor(editor): remove old specs (#11909)

Saul-Mirone730ed16fc531
diff --git a/blocksuite/affine/all/package.json b/blocksuite/affine/all/package.json
index 52549ad762..bd2c83c582 100644
--- a/blocksuite/affine/all/package.json
+++ b/blocksuite/affine/all/package.json
@@ -214,7 +214,6 @@
"./model": "./src/model/index.ts",
"./sync": "./src/sync/index.ts",
"./adapters": "./src/adapters/index.ts",
- "./extensions": "./src/extensions/index.ts",
"./extensions/store": "./src/extensions/store.ts",
"./extensions/view": "./src/extensions/view.ts"
},
diff --git a/blocksuite/affine/all/src/extensions/common.ts b/blocksuite/affine/all/src/extensions/common.ts
deleted file mode 100644
index 1284d9b7c9..0000000000
--- a/blocksuite/affine/all/src/extensions/common.ts
+++ /dev/null
@@ -1,126 +0,0 @@
-import { AttachmentBlockSpec } from '@blocksuite/affine-block-attachment';
-import { BookmarkBlockSpec } from '@blocksuite/affine-block-bookmark';
-import { CalloutBlockSpec } from '@blocksuite/affine-block-callout';
-import { CodeBlockSpec } from '@blocksuite/affine-block-code';
-import { DataViewBlockSpec } from '@blocksuite/affine-block-data-view';
-import { DatabaseBlockSpec } from '@blocksuite/affine-block-database';
-import { DividerBlockSpec } from '@blocksuite/affine-block-divider';
-import { EdgelessTextBlockSpec } from '@blocksuite/affine-block-edgeless-text';
-import { EmbedExtensions } from '@blocksuite/affine-block-embed';
-import { FrameBlockSpec } from '@blocksuite/affine-block-frame';
-import { ImageBlockSpec } from '@blocksuite/affine-block-image';
-import { LatexBlockSpec } from '@blocksuite/affine-block-latex';
-import { ListBlockSpec } from '@blocksuite/affine-block-list';
-import {
- EdgelessNoteBlockSpec,
- NoteBlockSpec,
-} from '@blocksuite/affine-block-note';
-import { ParagraphBlockSpec } from '@blocksuite/affine-block-paragraph';
-import {
- EdgelessSurfaceBlockAdapterExtensions,
- EdgelessSurfaceBlockSpec,
- PageSurfaceBlockSpec,
- SurfaceBlockAdapterExtensions,
-} from '@blocksuite/affine-block-surface';
-import {
- EdgelessSurfaceRefBlockSpec,
- PageSurfaceRefBlockSpec,
-} from '@blocksuite/affine-block-surface-ref';
-import { TableBlockSpec } from '@blocksuite/affine-block-table';
-import {
- brushToMarkdownAdapterMatcher,
- brushToPlainTextAdapterMatcher,
-} from '@blocksuite/affine-gfx-brush';
-import {
- connectorToMarkdownAdapterMatcher,
- connectorToPlainTextAdapterMatcher,
-} from '@blocksuite/affine-gfx-connector';
-import {
- groupToMarkdownAdapterMatcher,
- groupToPlainTextAdapterMatcher,
-} from '@blocksuite/affine-gfx-group';
-import {
- mindmapToMarkdownAdapterMatcher,
- mindmapToPlainTextAdapterMatcher,
-} from '@blocksuite/affine-gfx-mindmap';
-import {
- shapeToMarkdownAdapterMatcher,
- shapeToPlainTextAdapterMatcher,
-} from '@blocksuite/affine-gfx-shape';
-import {
- textToMarkdownAdapterMatcher,
- textToPlainTextAdapterMatcher,
-} from '@blocksuite/affine-gfx-text';
-import { FootNoteInlineSpecExtension } from '@blocksuite/affine-inline-footnote';
-import { inlinePresetExtensions } from '@blocksuite/affine-inline-preset';
-import {
- DefaultOpenDocExtension,
- DocDisplayMetaService,
- EditPropsStore,
- FontLoaderService,
-} from '@blocksuite/affine-shared/services';
-import type { ExtensionType } from '@blocksuite/store';
-
-const elementToPlainTextAdapterMatchers = [
- groupToPlainTextAdapterMatcher,
- shapeToPlainTextAdapterMatcher,
- connectorToPlainTextAdapterMatcher,
- brushToPlainTextAdapterMatcher,
- textToPlainTextAdapterMatcher,
- mindmapToPlainTextAdapterMatcher,
-];
-
-const elementToMarkdownAdapterMatchers = [
- groupToMarkdownAdapterMatcher,
- shapeToMarkdownAdapterMatcher,
- connectorToMarkdownAdapterMatcher,
- brushToMarkdownAdapterMatcher,
- textToMarkdownAdapterMatcher,
- mindmapToMarkdownAdapterMatcher,
-];
-
-export const CommonBlockSpecs: ExtensionType[] = [
- FootNoteInlineSpecExtension,
- inlinePresetExtensions,
- DocDisplayMetaService,
- EditPropsStore,
- LatexBlockSpec,
- ListBlockSpec,
- DatabaseBlockSpec,
- TableBlockSpec,
- DataViewBlockSpec,
- DividerBlockSpec,
- BookmarkBlockSpec,
- EmbedExtensions,
- AttachmentBlockSpec,
- CodeBlockSpec,
- ImageBlockSpec,
- ParagraphBlockSpec,
- DefaultOpenDocExtension,
- FontLoaderService,
- CalloutBlockSpec,
- FrameBlockSpec,
-
- elementToPlainTextAdapterMatchers,
- elementToMarkdownAdapterMatchers,
-].flat();
-
-export const PageFirstPartyBlockSpecs: ExtensionType[] = [
- CommonBlockSpecs,
- NoteBlockSpec,
- PageSurfaceBlockSpec,
- PageSurfaceRefBlockSpec,
-
- ...SurfaceBlockAdapterExtensions,
-].flat();
-
-export const EdgelessFirstPartyBlockSpecs: ExtensionType[] = [
- CommonBlockSpecs,
-
- EdgelessNoteBlockSpec,
- EdgelessSurfaceBlockSpec,
- EdgelessSurfaceRefBlockSpec,
- EdgelessTextBlockSpec,
-
- ...EdgelessSurfaceBlockAdapterExtensions,
-].flat();
diff --git a/blocksuite/affine/all/src/extensions/editor-specs.ts b/blocksuite/affine/all/src/extensions/editor-specs.ts
deleted file mode 100644
index 02727c26b2..0000000000
--- a/blocksuite/affine/all/src/extensions/editor-specs.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import {
- EdgelessBuiltInSpecs,
- PageRootBlockSpec,
-} from '@blocksuite/affine-block-root';
-import type { ExtensionType } from '@blocksuite/store';
-
-import {
- EdgelessFirstPartyBlockSpecs,
- PageFirstPartyBlockSpecs,
-} from './common';
-
-export const EdgelessEditorBlockSpecs: ExtensionType[] = [
- EdgelessBuiltInSpecs,
- EdgelessFirstPartyBlockSpecs,
-].flat();
-
-export const PageEditorBlockSpecs: ExtensionType[] = [
- PageRootBlockSpec,
- PageFirstPartyBlockSpecs,
-].flat();
diff --git a/blocksuite/affine/all/src/extensions/index.ts b/blocksuite/affine/all/src/extensions/index.ts
deleted file mode 100644
index 6a51891a73..0000000000
--- a/blocksuite/affine/all/src/extensions/index.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export * from './common';
-export * from './editor-specs';
-export * from './legacy-store';
-export * from './preview-specs';
diff --git a/blocksuite/affine/all/src/extensions/legacy-store.ts b/blocksuite/affine/all/src/extensions/legacy-store.ts
deleted file mode 100644
index 48085e9c11..0000000000
--- a/blocksuite/affine/all/src/extensions/legacy-store.ts
+++ /dev/null
@@ -1,112 +0,0 @@
-import { DataViewBlockSchemaExtension } from '@blocksuite/affine-block-data-view';
-import { DatabaseSelectionExtension } from '@blocksuite/affine-block-database';
-import { EmbedIframeConfigExtensions } from '@blocksuite/affine-block-embed';
-import { ImageStoreSpec } from '@blocksuite/affine-block-image';
-import { SurfaceBlockSchemaExtension } from '@blocksuite/affine-block-surface';
-import { TableSelectionExtension } from '@blocksuite/affine-block-table';
-import {
- AttachmentBlockSchemaExtension,
- BookmarkBlockSchemaExtension,
- CalloutBlockSchemaExtension,
- CodeBlockSchemaExtension,
- DatabaseBlockSchemaExtension,
- DividerBlockSchemaExtension,
- EdgelessTextBlockSchemaExtension,
- EmbedFigmaBlockSchemaExtension,
- EmbedGithubBlockSchemaExtension,
- EmbedHtmlBlockSchemaExtension,
- EmbedIframeBlockSchemaExtension,
- EmbedLinkedDocBlockSchemaExtension,
- EmbedLoomBlockSchemaExtension,
- EmbedSyncedDocBlockSchemaExtension,
- EmbedYoutubeBlockSchemaExtension,
- FrameBlockSchemaExtension,
- ImageBlockSchemaExtension,
- LatexBlockSchemaExtension,
- ListBlockSchemaExtension,
- NoteBlockSchemaExtension,
- ParagraphBlockSchemaExtension,
- RootBlockSchemaExtension,
- SurfaceRefBlockSchemaExtension,
- TableBlockSchemaExtension,
- TranscriptionBlockSchemaExtension,
-} from '@blocksuite/affine-model';
-import {
- HighlightSelectionExtension,
- ImageSelectionExtension,
-} from '@blocksuite/affine-shared/selection';
-import {
- BlockMetaService,
- EmbedIframeService,
- FeatureFlagService,
- FileSizeLimitService,
- LinkPreviewerService,
-} from '@blocksuite/affine-shared/services';
-import {
- BlockSelectionExtension,
- CursorSelectionExtension,
- SurfaceSelectionExtension,
- TextSelectionExtension,
-} from '@blocksuite/std';
-import type { ExtensionType } from '@blocksuite/store';
-
-import {
- getAdapterFactoryExtensions,
- getHtmlAdapterExtensions,
- getMarkdownAdapterExtensions,
- getNotionHtmlAdapterExtensions,
- getPlainTextAdapterExtensions,
-} from '../adapters/extension.js';
-
-export const StoreExtensions: ExtensionType[] = [
- CodeBlockSchemaExtension,
- ParagraphBlockSchemaExtension,
- RootBlockSchemaExtension,
- ListBlockSchemaExtension,
- NoteBlockSchemaExtension,
- DividerBlockSchemaExtension,
- ImageBlockSchemaExtension,
- SurfaceBlockSchemaExtension,
- BookmarkBlockSchemaExtension,
- FrameBlockSchemaExtension,
- DatabaseBlockSchemaExtension,
- SurfaceRefBlockSchemaExtension,
- DataViewBlockSchemaExtension,
- AttachmentBlockSchemaExtension,
- EmbedSyncedDocBlockSchemaExtension,
- EmbedLinkedDocBlockSchemaExtension,
- EmbedHtmlBlockSchemaExtension,
- EmbedIframeBlockSchemaExtension,
- EmbedGithubBlockSchemaExtension,
- EmbedFigmaBlockSchemaExtension,
- EmbedLoomBlockSchemaExtension,
- EmbedYoutubeBlockSchemaExtension,
- EdgelessTextBlockSchemaExtension,
- LatexBlockSchemaExtension,
- TableBlockSchemaExtension,
- CalloutBlockSchemaExtension,
- TranscriptionBlockSchemaExtension,
-
- BlockSelectionExtension,
- TextSelectionExtension,
- SurfaceSelectionExtension,
- CursorSelectionExtension,
- HighlightSelectionExtension,
- ImageSelectionExtension,
- DatabaseSelectionExtension,
- TableSelectionExtension,
-
- getHtmlAdapterExtensions(),
- getMarkdownAdapterExtensions(),
- getNotionHtmlAdapterExtensions(),
- getPlainTextAdapterExtensions(),
- getAdapterFactoryExtensions(),
-
- FeatureFlagService,
- LinkPreviewerService,
- FileSizeLimitService,
- ImageStoreSpec,
- BlockMetaService,
- EmbedIframeConfigExtensions,
- EmbedIframeService,
-].flat();
diff --git a/blocksuite/affine/all/src/extensions/preview-specs.ts b/blocksuite/affine/all/src/extensions/preview-specs.ts
deleted file mode 100644
index 5948748ab0..0000000000
--- a/blocksuite/affine/all/src/extensions/preview-specs.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import {
- PreviewEdgelessRootBlockSpec,
- PreviewPageRootBlockSpec,
- ReadOnlyClipboard,
-} from '@blocksuite/affine-block-root';
-import type { ExtensionType } from '@blocksuite/store';
-
-import {
- EdgelessFirstPartyBlockSpecs,
- PageFirstPartyBlockSpecs,
-} from './common.js';
-
-export const PreviewEdgelessEditorBlockSpecs: ExtensionType[] = [
- PreviewEdgelessRootBlockSpec,
- EdgelessFirstPartyBlockSpecs,
- ReadOnlyClipboard,
-].flat();
-
-export const PreviewPageEditorBlockSpecs: ExtensionType[] = [
- PreviewPageRootBlockSpec,
- PageFirstPartyBlockSpecs,
- ReadOnlyClipboard,
-].flat();
diff --git a/packages/frontend/core/src/blocksuite/ai/components/text-renderer.ts b/packages/frontend/core/src/blocksuite/ai/components/text-renderer.ts
index f50c0d8cfa..f80e4f3340 100644
--- a/packages/frontend/core/src/blocksuite/ai/components/text-renderer.ts
+++ b/packages/frontend/core/src/blocksuite/ai/components/text-renderer.ts
@@ -4,7 +4,6 @@ import {
defaultImageProxyMiddleware,
ImageProxyService,
} from '@blocksuite/affine/blocks/image';
-import { PageEditorBlockSpecs } from '@blocksuite/affine/extensions';
import { Container, type ServiceProvider } from '@blocksuite/affine/global/di';
import { WithDisposable } from '@blocksuite/affine/global/lit';
import { codeBlockWrapMiddleware } from '@blocksuite/affine/shared/adapters';
@@ -37,14 +36,15 @@ import { keyed } from 'lit/directives/keyed.js';
import { literal } from 'lit/static-html.js';
import React from 'react';
+import { getViewManager } from '../../manager/migrating-view';
import { markDownToDoc } from '../../utils';
import type {
AffineAIPanelState,
AffineAIPanelWidgetConfig,
} from '../widgets/ai-panel/type';
-export const CustomPageEditorBlockSpecs: ExtensionType[] = [
- ...PageEditorBlockSpecs,
+export const getCustomPageEditorBlockSpecs: () => ExtensionType[] = () => [
+ ...getViewManager().get('page'),
{
setup: di => {
di.override(
@@ -316,7 +316,8 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
html`<div class="ai-answer-text-editor affine-page-viewport">
${new BlockStdScope({
store: this._doc,
- extensions: this.options.extensions ?? CustomPageEditorBlockSpecs,
+ extensions:
+ this.options.extensions ?? getCustomPageEditorBlockSpecs(),
}).render()}
</div>`
)}
diff --git a/packages/frontend/core/src/blocksuite/editors/edgeless-editor.ts b/packages/frontend/core/src/blocksuite/editors/edgeless-editor.ts
index 2113f29f71..7686c15123 100644
--- a/packages/frontend/core/src/blocksuite/editors/edgeless-editor.ts
+++ b/packages/frontend/core/src/blocksuite/editors/edgeless-editor.ts
@@ -1,8 +1,7 @@
-import { EdgelessEditorBlockSpecs } from '@blocksuite/affine/extensions';
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
import { ThemeProvider } from '@blocksuite/affine/shared/services';
import { BlockStdScope, ShadowlessElement } from '@blocksuite/affine/std';
-import type { Store } from '@blocksuite/affine/store';
+import type { ExtensionType, Store } from '@blocksuite/affine/store';
import { css, html, nothing, type TemplateResult } from 'lit';
import { property, state } from 'lit/decorators.js';
import { guard } from 'lit/directives/guard.js';
@@ -95,7 +94,7 @@ export class EdgelessEditor extends SignalWatcher(
accessor editor!: TemplateResult;
@property({ attribute: false })
- accessor specs = EdgelessEditorBlockSpecs;
+ accessor specs: ExtensionType[] = [];
@state()
accessor std!: BlockStdScope;
diff --git a/packages/frontend/core/src/blocksuite/editors/page-editor.ts b/packages/frontend/core/src/blocksuite/editors/page-editor.ts
index c8ae3052ce..03d1ccb740 100644
--- a/packages/frontend/core/src/blocksuite/editors/page-editor.ts
+++ b/packages/frontend/core/src/blocksuite/editors/page-editor.ts
@@ -1,4 +1,3 @@
-import { PageEditorBlockSpecs } from '@blocksuite/affine/extensions';
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
import { noop } from '@blocksuite/affine/global/utils';
import { ThemeProvider } from '@blocksuite/affine/shared/services';
@@ -7,7 +6,7 @@ import {
EditorHost,
ShadowlessElement,
} from '@blocksuite/affine/std';
-import type { Store } from '@blocksuite/affine/store';
+import type { ExtensionType, Store } from '@blocksuite/affine/store';
import { css, html, nothing } from 'lit';
import { property, state } from 'lit/decorators.js';
import { guard } from 'lit/directives/guard.js';
@@ -104,7 +103,7 @@ export class PageEditor extends SignalWatcher(
accessor doc!: Store;
@property({ attribute: false })
- accessor specs = PageEditorBlockSpecs;
+ accessor specs: ExtensionType[] = [];
@state()
accessor std!: BlockStdScope;
diff --git a/packages/frontend/core/src/blocksuite/manager/migrating-view.ts b/packages/frontend/core/src/blocksuite/manager/migrating-view.ts
index 31606eafd4..06fa45e8a5 100644
--- a/packages/frontend/core/src/blocksuite/manager/migrating-view.ts
+++ b/packages/frontend/core/src/blocksuite/manager/migrating-view.ts
@@ -51,7 +51,7 @@ import { getThemeExtension } from '../extensions/theme';
const optionsSchema = z.object({
enableAI: z.boolean().optional(),
- framework: z.instanceof(FrameworkProvider),
+ framework: z.instanceof(FrameworkProvider).optional(),
});
class MigratingAffineViewExtension extends ViewExtensionProvider<
@@ -173,8 +173,8 @@ const manager = new ViewExtensionManager([
]);
export function getViewManager(
- framework: FrameworkProvider,
- enableAI: boolean
+ framework?: FrameworkProvider,
+ enableAI?: boolean
) {
manager.configure(MigratingAffineViewExtension, {
framework,
diff --git a/packages/frontend/core/src/components/page-list/__tests__/use-block-suite-page-preview.spec.ts b/packages/frontend/core/src/components/page-list/__tests__/use-block-suite-page-preview.spec.ts
index 6d095641db..2655136d30 100644
--- a/packages/frontend/core/src/components/page-list/__tests__/use-block-suite-page-preview.spec.ts
+++ b/packages/frontend/core/src/components/page-list/__tests__/use-block-suite-page-preview.spec.ts
@@ -3,7 +3,7 @@
*/
import 'fake-indexeddb/auto';
-import { StoreExtensions } from '@blocksuite/affine/extensions';
+import { getStoreManager } from '@affine/core/blocksuite/manager/migrating-store';
import { type Store, Text } from '@blocksuite/affine/store';
import { TestWorkspace } from '@blocksuite/affine/store/test';
import { renderHook } from '@testing-library/react';
@@ -13,7 +13,7 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
import { useBlockSuitePagePreview } from '../use-block-suite-page-preview';
let docCollection: TestWorkspace;
-const extensions = StoreExtensions;
+const extensions = getStoreManager().get('store');
beforeEach(async () => {
vi.useFakeTimers({ toFake: ['requestIdleCallback'] });
diff --git a/packages/frontend/core/src/modules/doc-info/utils.ts b/packages/frontend/core/src/modules/doc-info/utils.ts
index 64627ebb2f..d794f35dde 100644
--- a/packages/frontend/core/src/modules/doc-info/utils.ts
+++ b/packages/frontend/core/src/modules/doc-info/utils.ts
@@ -1,5 +1,5 @@
+import { getViewManager } from '@affine/core/blocksuite/manager/migrating-view';
import { DebugLogger } from '@affine/debug';
-import { PageEditorBlockSpecs } from '@blocksuite/affine/extensions';
import { BlockStdScope } from '@blocksuite/affine/std';
import type { Store } from '@blocksuite/affine/store';
import { useEffect, useMemo, useState } from 'react';
@@ -44,7 +44,7 @@ export function createBlockStdScope(doc: Store) {
logger.debug('createBlockStdScope', doc.id);
const std = new BlockStdScope({
store: doc,
- extensions: PageEditorBlockSpecs,
+ extensions: getViewManager().get('page'),
});
return std;
}