refactor(editor): reorg block specs (#9421)

This commit is contained in:
Saul-Mirone
2024-12-30 05:59:25 +00:00
parent 87331b49b7
commit e3b6841944
16 changed files with 121 additions and 173 deletions

View File

@@ -14,13 +14,7 @@ import {
DataViewBlockSpec,
DividerBlockSpec,
EditPropsStore,
EmbedFigmaBlockSpec,
EmbedGithubBlockSpec,
EmbedHtmlBlockSpec,
EmbedLinkedDocBlockSpec,
EmbedLoomBlockSpec,
EmbedSyncedDocBlockSpec,
EmbedYoutubeBlockSpec,
EmbedExtensions,
ImageBlockSpec,
LatexBlockSpec,
ListBlockSpec,
@@ -30,7 +24,7 @@ import {
} from '@blocksuite/affine/blocks';
const CommonBlockSpecs: ExtensionType[] = [
RefNodeSlotsExtension(),
RefNodeSlotsExtension,
EditPropsStore,
RichTextExtensions,
LatexBlockSpec,
@@ -38,16 +32,9 @@ const CommonBlockSpecs: ExtensionType[] = [
DatabaseBlockSpec,
DataViewBlockSpec,
DividerBlockSpec,
EmbedExtensions,
BookmarkBlockSpec,
EmbedFigmaBlockSpec,
EmbedGithubBlockSpec,
EmbedYoutubeBlockSpec,
EmbedLoomBlockSpec,
EmbedHtmlBlockSpec,
EmbedSyncedDocBlockSpec,
EmbedLinkedDocBlockSpec,
AttachmentBlockSpec,
// special
AdapterFactoryExtensions,
].flat();

View File

@@ -29,7 +29,6 @@ import { isNewTabTrigger } from '@affine/core/utils';
import { DebugLogger } from '@affine/debug';
import { track } from '@affine/track';
import {
type BlockService,
BlockServiceWatcher,
BlockViewIdentifier,
ConfigIdentifier,
@@ -44,7 +43,6 @@ import type {
PeekViewService as BSPeekViewService,
QuickSearchResult,
RootBlockConfig,
RootService,
} from '@blocksuite/affine/blocks';
import {
AffineSlashMenuWidget,
@@ -81,21 +79,15 @@ export type ReferenceReactRenderer = (
const logger = new DebugLogger('affine::spec-patchers');
function patchSpecService<Service extends BlockService = BlockService>(
function patchSpecService(
flavour: string,
onMounted: (service: Service) => (() => void) | void,
onWidgetConnected?: (component: WidgetComponent) => void
) {
class TempServiceWatcher extends BlockServiceWatcher {
static override readonly flavour = flavour;
override mounted() {
super.mounted();
const disposable = onMounted(this.blockService as any);
const disposableGroup = this.blockService.disposables;
if (disposable) {
disposableGroup.add(disposable);
}
if (onWidgetConnected) {
disposableGroup.add(
this.blockService.specSlots.widgetConnected.on(({ component }) => {
@@ -424,9 +416,8 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
},
});
const SlashMenuQuickSearchExtension = patchSpecService<RootService>(
const SlashMenuQuickSearchExtension = patchSpecService(
'affine:page',
() => {},
(component: WidgetComponent) => {
if (component instanceof AffineSlashMenuWidget) {
component.config.items.forEach(item => {