mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 12:06:35 +08:00
refactor: reorganize specs and adapter extensions (#10359)
### TL;DR Refactored `SpecProvider` singleton access pattern and reorganized adapter/extension code structure. ### What changed? - Changed `SpecProvider.getInstance()` to `SpecProvider._` for cleaner singleton access - Moved adapter/extension code from `_common` directory to dedicated `adapters` and `extensions` folders - Consolidated adapter extensions into a single file - Removed unused dependencies from package.json - Deleted unnecessary schema files - Extracted `MobileSpecsPatches` class into the mobile patching code - Updated all references to use the new `SpecProvider._` accessor ### How to test? - Verify all specs are properly registered and accessible via `SpecProvider._` - Test adapter functionality for HTML, Markdown, Notion HTML and plain text - Check mobile-specific features and patches work correctly - Ensure preview functionality works in both page and edgeless modes ### Why make this change? - Improves code organization by properly separating adapters and extensions - Simplifies singleton access pattern - Removes unnecessary dependencies and files - Makes the codebase more maintainable by consolidating related functionality
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
import { AttachmentBlockSpec } from '@blocksuite/affine-block-attachment';
|
||||
import { BookmarkBlockSpec } from '@blocksuite/affine-block-bookmark';
|
||||
import { CodeBlockSpec } from '@blocksuite/affine-block-code';
|
||||
import { DataViewBlockSpec } from '@blocksuite/affine-block-data-view';
|
||||
import {
|
||||
DatabaseBlockSpec,
|
||||
DatabaseSelectionExtension,
|
||||
} 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, ImageStoreSpec } 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 {
|
||||
EdgelessSurfaceBlockSpec,
|
||||
PageSurfaceBlockSpec,
|
||||
} from '@blocksuite/affine-block-surface';
|
||||
import {
|
||||
EdgelessSurfaceRefBlockSpec,
|
||||
PageSurfaceRefBlockSpec,
|
||||
} from '@blocksuite/affine-block-surface-ref';
|
||||
import {
|
||||
TableBlockSpec,
|
||||
TableSelectionExtension,
|
||||
} from '@blocksuite/affine-block-table';
|
||||
import {
|
||||
RefNodeSlotsExtension,
|
||||
RichTextExtensions,
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
import {
|
||||
HighlightSelectionExtension,
|
||||
ImageSelectionExtension,
|
||||
} from '@blocksuite/affine-shared/selection';
|
||||
import {
|
||||
DefaultOpenDocExtension,
|
||||
DocDisplayMetaService,
|
||||
EditPropsStore,
|
||||
FeatureFlagService,
|
||||
FileSizeLimitService,
|
||||
FontLoaderService,
|
||||
LinkPreviewerService,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
BlockSelectionExtension,
|
||||
CursorSelectionExtension,
|
||||
SurfaceSelectionExtension,
|
||||
TextSelectionExtension,
|
||||
} from '@blocksuite/block-std';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
AdapterFactoryExtensions,
|
||||
HtmlAdapterExtension,
|
||||
MarkdownAdapterExtension,
|
||||
NotionHtmlAdapterExtension,
|
||||
PlainTextAdapterExtension,
|
||||
} from '../adapters/extension.js';
|
||||
|
||||
export const CommonBlockSpecs: ExtensionType[] = [
|
||||
DocDisplayMetaService,
|
||||
RefNodeSlotsExtension,
|
||||
EditPropsStore,
|
||||
RichTextExtensions,
|
||||
LatexBlockSpec,
|
||||
ListBlockSpec,
|
||||
DatabaseBlockSpec,
|
||||
TableBlockSpec,
|
||||
DataViewBlockSpec,
|
||||
DividerBlockSpec,
|
||||
BookmarkBlockSpec,
|
||||
EmbedExtensions,
|
||||
AttachmentBlockSpec,
|
||||
CodeBlockSpec,
|
||||
ImageBlockSpec,
|
||||
ParagraphBlockSpec,
|
||||
DefaultOpenDocExtension,
|
||||
FontLoaderService,
|
||||
AdapterFactoryExtensions,
|
||||
].flat();
|
||||
|
||||
export const PageFirstPartyBlockSpecs: ExtensionType[] = [
|
||||
CommonBlockSpecs,
|
||||
NoteBlockSpec,
|
||||
PageSurfaceBlockSpec,
|
||||
PageSurfaceRefBlockSpec,
|
||||
].flat();
|
||||
|
||||
export const EdgelessFirstPartyBlockSpecs: ExtensionType[] = [
|
||||
CommonBlockSpecs,
|
||||
|
||||
EdgelessNoteBlockSpec,
|
||||
EdgelessSurfaceBlockSpec,
|
||||
EdgelessSurfaceRefBlockSpec,
|
||||
FrameBlockSpec,
|
||||
EdgelessTextBlockSpec,
|
||||
].flat();
|
||||
|
||||
export const StoreExtensions: ExtensionType[] = [
|
||||
BlockSelectionExtension,
|
||||
TextSelectionExtension,
|
||||
SurfaceSelectionExtension,
|
||||
CursorSelectionExtension,
|
||||
HighlightSelectionExtension,
|
||||
ImageSelectionExtension,
|
||||
DatabaseSelectionExtension,
|
||||
TableSelectionExtension,
|
||||
|
||||
FeatureFlagService,
|
||||
LinkPreviewerService,
|
||||
FileSizeLimitService,
|
||||
ImageStoreSpec,
|
||||
|
||||
HtmlAdapterExtension,
|
||||
MarkdownAdapterExtension,
|
||||
NotionHtmlAdapterExtension,
|
||||
PlainTextAdapterExtension,
|
||||
].flat();
|
||||
@@ -0,0 +1,20 @@
|
||||
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();
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './common.js';
|
||||
export * from './editor-specs.js';
|
||||
export * from './preview-specs.js';
|
||||
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
PreviewEdgelessRootBlockSpec,
|
||||
PreviewPageRootBlockSpec,
|
||||
} from '@blocksuite/affine-block-root';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
EdgelessFirstPartyBlockSpecs,
|
||||
PageFirstPartyBlockSpecs,
|
||||
} from './common.js';
|
||||
|
||||
export const PreviewEdgelessEditorBlockSpecs: ExtensionType[] = [
|
||||
PreviewEdgelessRootBlockSpec,
|
||||
EdgelessFirstPartyBlockSpecs,
|
||||
].flat();
|
||||
|
||||
export const PreviewPageEditorBlockSpecs: ExtensionType[] = [
|
||||
PreviewPageRootBlockSpec,
|
||||
PageFirstPartyBlockSpecs,
|
||||
].flat();
|
||||
@@ -0,0 +1,19 @@
|
||||
import { SpecProvider } from '@blocksuite/affine-shared/utils';
|
||||
|
||||
import { StoreExtensions } from './common.js';
|
||||
import {
|
||||
EdgelessEditorBlockSpecs,
|
||||
PageEditorBlockSpecs,
|
||||
} from './editor-specs.js';
|
||||
import {
|
||||
PreviewEdgelessEditorBlockSpecs,
|
||||
PreviewPageEditorBlockSpecs,
|
||||
} from './preview-specs.js';
|
||||
|
||||
export function registerSpecs() {
|
||||
SpecProvider._.addSpec('store', StoreExtensions);
|
||||
SpecProvider._.addSpec('page', PageEditorBlockSpecs);
|
||||
SpecProvider._.addSpec('edgeless', EdgelessEditorBlockSpecs);
|
||||
SpecProvider._.addSpec('preview:page', PreviewPageEditorBlockSpecs);
|
||||
SpecProvider._.addSpec('preview:edgeless', PreviewEdgelessEditorBlockSpecs);
|
||||
}
|
||||
Reference in New Issue
Block a user