refactor(core): new quick search service (#7214)

This commit is contained in:
EYHN
2024-07-02 09:17:53 +00:00
parent 15e99c7819
commit 40e381e272
63 changed files with 1809 additions and 2007 deletions

View File

@@ -13,7 +13,6 @@ export type DocMode = 'edgeless' | 'page';
*/
export class DocRecord extends Entity<{ id: string }> {
id: string = this.props.id;
meta: Partial<DocMeta> | null = null;
constructor(private readonly docsStore: DocsStore) {
super();
}

View File

@@ -1,6 +1,10 @@
import { Unreachable } from '@affine/env/constant';
import { Service } from '../../../framework';
import { initEmptyPage } from '../../../initialization';
import { ObjectPool } from '../../../utils';
import type { Doc } from '../entities/doc';
import type { DocMode } from '../entities/record';
import { DocRecordList } from '../entities/record-list';
import { DocScope } from '../scopes/doc';
import type { DocsStore } from '../stores/docs';
@@ -46,4 +50,22 @@ export class DocsService extends Service {
return { doc: obj, release };
}
createDoc(
options: {
mode?: DocMode;
title?: string;
} = {}
) {
const doc = this.store.createBlockSuiteDoc();
initEmptyPage(doc, options.title);
const docRecord = this.list.doc$(doc.id).value;
if (!docRecord) {
throw new Unreachable();
}
if (options.mode) {
docRecord.setMode(options.mode);
}
return docRecord;
}
}

View File

@@ -18,6 +18,10 @@ export class DocsStore extends Store {
return this.workspaceService.workspace.docCollection.getDoc(id);
}
createBlockSuiteDoc() {
return this.workspaceService.workspace.docCollection.createDoc();
}
watchDocIds() {
return new Observable<string[]>(subscriber => {
const emit = () => {