mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
refactor(core): new quick search service (#7214)
This commit is contained in:
@@ -6,5 +6,6 @@ export * from './error';
|
||||
export { createEvent, OnEvent } from './event';
|
||||
export { Framework } from './framework';
|
||||
export { createIdentifier } from './identifier';
|
||||
export type { FrameworkProvider, ResolveOptions } from './provider';
|
||||
export type { ResolveOptions } from './provider';
|
||||
export { FrameworkProvider } from './provider';
|
||||
export type { GeneralIdentifier } from './types';
|
||||
|
||||
@@ -9,6 +9,12 @@ export const FrameworkStackContext = React.createContext<FrameworkProvider[]>([
|
||||
Framework.EMPTY.provider(),
|
||||
]);
|
||||
|
||||
export function useFramework(): FrameworkProvider {
|
||||
const stack = useContext(FrameworkStackContext);
|
||||
|
||||
return stack[stack.length - 1]; // never null, because the default value
|
||||
}
|
||||
|
||||
export function useService<T extends Service>(
|
||||
identifier: GeneralIdentifier<T>
|
||||
): T {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user