refactor(editor): introduce store container to make implement doc easier (#12146)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Introduced a new store management system for handling document stores, improving efficiency and flexibility when working with document data.

- **Refactor**
  - Updated internal store handling to use a centralized store container, simplifying store retrieval and removal across various components.
  - Renamed and updated several store-related method signatures for consistency and clarity.
  - Replaced editor extension loading logic with a new local implementation for better modularity.

- **Chores**
  - Improved and streamlined the export of store-related modules for better maintainability.
  - Removed obsolete and redundant code related to previous store management approaches.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Saul-Mirone
2025-05-07 06:08:43 +00:00
parent 93b1d6c729
commit 267bb3a975
11 changed files with 144 additions and 129 deletions
@@ -268,7 +268,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
query: this._query,
});
this.disposables.add(() => {
doc.doc.clearQuery(this._query);
doc.doc.removeStore({ query: this._query });
});
this._doc.readonly = true;
this.requestUpdate();
@@ -7,6 +7,7 @@ import {
type PageEditor,
} from '@affine/core/blocksuite/editors';
import type { AffineEditorViewOptions } from '@affine/core/blocksuite/manager/editor-view';
import { getViewManager } from '@affine/core/blocksuite/manager/migrating-view';
import { useEnableAI } from '@affine/core/components/hooks/affine/use-enable-ai';
import type { DocCustomPropertyInfo } from '@affine/core/modules/db';
import type {
@@ -21,8 +22,9 @@ import { WorkspaceService } from '@affine/core/modules/workspace';
import track from '@affine/track';
import type { DocTitle } from '@blocksuite/affine/fragments/doc-title';
import type { DocMode } from '@blocksuite/affine/model';
import type { Store } from '@blocksuite/affine/store';
import type { ExtensionType, Store } from '@blocksuite/affine/store';
import {
type FrameworkProvider,
useFramework,
useLiveData,
useService,
@@ -42,7 +44,6 @@ import {
type DefaultOpenProperty,
DocPropertiesTable,
} from '../../components/doc-properties';
import { enableEditorExtension } from '../extensions/entry/enable-editor';
import { BiDirectionalLinkPanel } from './bi-directional-link-panel';
import { BlocksuiteEditorJournalDocTitle } from './journal-doc-title';
import { StarterBar } from './starter-bar';
@@ -301,3 +302,20 @@ export const BlocksuiteEdgelessEditor = forwardRef<
</div>
);
});
function enableEditorExtension(
framework: FrameworkProvider,
mode: 'edgeless' | 'page',
enableAI: boolean,
options: AffineEditorViewOptions
): ExtensionType[] {
const manager = getViewManager(framework, enableAI, options);
if (BUILD_CONFIG.isMobileEdition) {
if (mode === 'page') {
return manager.get('mobile-page');
}
return manager.get('mobile-edgeless');
}
return manager.get(mode);
}
@@ -1,22 +0,0 @@
import type { AffineEditorViewOptions } from '@affine/core/blocksuite/manager/editor-view';
import type { ExtensionType } from '@blocksuite/affine/store';
import { type FrameworkProvider } from '@toeverything/infra';
import { getViewManager } from '../../manager/migrating-view';
export function enableEditorExtension(
framework: FrameworkProvider,
mode: 'edgeless' | 'page',
enableAI: boolean,
options: AffineEditorViewOptions
): ExtensionType[] {
const manager = getViewManager(framework, enableAI, options);
if (BUILD_CONFIG.isMobileEdition) {
if (mode === 'page') {
return manager.get('mobile-page');
}
return manager.get('mobile-edgeless');
}
return manager.get(mode);
}