refactor(core): move infra modules to core (#9207)

This commit is contained in:
EYHN
2024-12-23 04:53:59 +00:00
parent 2ea79d25ad
commit 129f94ee78
337 changed files with 908 additions and 1367 deletions

View File

@@ -0,0 +1,51 @@
import type { DocMode } from '@blocksuite/affine/blocks';
import { Entity, LiveData, MemoryMemento } from '@toeverything/infra';
export class GlobalContext extends Entity {
memento = new MemoryMemento();
workspaceId = this.define<string>('workspaceId');
workspaceFlavour = this.define<string>('workspaceFlavour');
serverId = this.define<string>('serverId');
/**
* is in doc page
*/
isDoc = this.define<boolean>('isDoc');
isTrashDoc = this.define<boolean>('isTrashDoc');
docId = this.define<string>('docId');
docMode = this.define<DocMode>('docMode');
/**
* is in collection page
*/
isCollection = this.define<boolean>('isCollection');
collectionId = this.define<string>('collectionId');
/**
* is in trash page
*/
isTrash = this.define<boolean>('isTrash');
/**
* is in tag page
*/
isTag = this.define<boolean>('isTag');
tagId = this.define<string>('tagId');
/**
* is in all docs page
*/
isAllDocs = this.define<boolean>('isAllDocs');
define<T>(key: string) {
this.memento.set(key, null);
const livedata$ = LiveData.from(this.memento.watch<T>(key), null);
return {
get: () => this.memento.get(key) as T | null,
set: (value: T | null) => this.memento.set(key, value),
$: livedata$,
};
}
}

View File

@@ -0,0 +1,10 @@
export { GlobalContextService } from './services/global-context';
import type { Framework } from '@toeverything/infra';
import { GlobalContext } from './entities/global-context';
import { GlobalContextService } from './services/global-context';
export function configureGlobalContextModule(framework: Framework) {
framework.service(GlobalContextService).entity(GlobalContext);
}

View File

@@ -0,0 +1,7 @@
import { Service } from '@toeverything/infra';
import { GlobalContext } from '../entities/global-context';
export class GlobalContextService extends Service {
globalContext = this.framework.createEntity(GlobalContext);
}