mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 00:26:51 +08:00
feat: 1. add toc;
This commit is contained in:
@@ -5,6 +5,7 @@ import { Database } from './database';
|
||||
import { EditorBlock } from './editor-block';
|
||||
import { FileService } from './file';
|
||||
import { PageTree } from './workspace/page-tree';
|
||||
import { TOC } from './workspace/toc';
|
||||
import { UserConfig } from './workspace/user-config';
|
||||
|
||||
export {
|
||||
@@ -48,6 +49,7 @@ export interface DbServicesMap {
|
||||
userConfig: UserConfig;
|
||||
file: FileService;
|
||||
commentService: CommentService;
|
||||
tocService: TOC;
|
||||
}
|
||||
|
||||
interface RegisterDependencyConfigWithName extends RegisterDependencyConfig {
|
||||
@@ -76,6 +78,13 @@ const dbServiceConfig: RegisterDependencyConfigWithName[] = [
|
||||
value: PageTree,
|
||||
dependencies: [{ token: Database }],
|
||||
},
|
||||
{
|
||||
type: 'class',
|
||||
callName: 'tocService',
|
||||
token: TOC,
|
||||
value: TOC,
|
||||
dependencies: [{ token: Database }],
|
||||
},
|
||||
{
|
||||
type: 'class',
|
||||
callName: 'userConfig',
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { ServiceBaseClass } from '../base';
|
||||
import { ReturnUnobserve } from '../database/observer';
|
||||
import { ObserveCallback } from './page-tree';
|
||||
|
||||
export class TOC extends ServiceBaseClass {
|
||||
private onActivePageChange?: () => void;
|
||||
|
||||
async observe(
|
||||
{ workspace, pageId }: { workspace: string; pageId: string },
|
||||
callback: ObserveCallback
|
||||
): Promise<ReturnUnobserve> {
|
||||
// not only use observe, but also addChildrenListener is OK 🎉🎉🎉
|
||||
// const pageBlock = await this.getBlock(workspace, pageId);
|
||||
//
|
||||
// this.onActivePageChange?.();
|
||||
// pageBlock?.addChildrenListener('onPageChildrenChange', () => {
|
||||
// callback();
|
||||
// });
|
||||
//
|
||||
// this.onActivePageChange = () => pageBlock?.removeChildrenListener('onPageChildrenChange');
|
||||
|
||||
const unobserve = await this._observe(workspace, pageId, callback);
|
||||
|
||||
return () => {
|
||||
unobserve();
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user