diff --git a/packages/common/infra/src/index.ts b/packages/common/infra/src/index.ts index 79d9f035f1..b7e8174a24 100644 --- a/packages/common/infra/src/index.ts +++ b/packages/common/infra/src/index.ts @@ -1,7 +1,6 @@ export * from './app-config-storage'; export * from './atom'; export * from './framework'; -export * from './initialization'; export * from './livedata'; export * from './orm'; export * from './storage'; diff --git a/packages/common/infra/src/sync/blob/blob.ts b/packages/common/infra/src/sync/blob/blob.ts index 7e7b35a0a6..b289c968dd 100644 --- a/packages/common/infra/src/sync/blob/blob.ts +++ b/packages/common/infra/src/sync/blob/blob.ts @@ -1,5 +1,5 @@ import { DebugLogger } from '@affine/debug'; -import { Slot } from '@blocksuite/affine/global/utils'; +import EventEmitter2 from 'eventemitter2'; import { difference } from 'lodash-es'; import { LiveData } from '../../livedata'; @@ -32,13 +32,19 @@ export interface BlobStatus { export class BlobEngine { readonly name = 'blob-engine'; readonly readonly = this.local.readonly; + readonly event = new EventEmitter2(); private abort: AbortController | null = null; readonly isStorageOverCapacity$ = new LiveData(false); singleBlobSizeLimit: number = 100 * 1024 * 1024; - onAbortLargeBlob = new Slot(); + onAbortLargeBlob = (callback: (blob: Blob) => void) => { + this.event.on('abort-large-blob', callback); + return () => { + this.event.off('abort-large-blob', callback); + }; + }; constructor( private readonly local: BlobStorage, @@ -153,7 +159,7 @@ export class BlobEngine { } if (value.size > this.singleBlobSizeLimit) { - this.onAbortLargeBlob.emit(value); + this.event.emit('abort-large-blob', value); logger.error('blob over limit, abort set'); return key; } diff --git a/packages/common/infra/tsconfig.json b/packages/common/infra/tsconfig.json index ee7b751d96..a4ea7715ed 100644 --- a/packages/common/infra/tsconfig.json +++ b/packages/common/infra/tsconfig.json @@ -12,9 +12,6 @@ }, { "path": "../debug" - }, - { - "path": "../../../blocksuite/affine/all" } ] } diff --git a/packages/common/nbstore/tsconfig.json b/packages/common/nbstore/tsconfig.json index e5276f5627..183d9103b4 100644 --- a/packages/common/nbstore/tsconfig.json +++ b/packages/common/nbstore/tsconfig.json @@ -15,6 +15,9 @@ }, { "path": "../infra" + }, + { + "path": "../../../blocksuite/affine/all" } ] } diff --git a/packages/common/infra/src/initialization/index.ts b/packages/frontend/core/src/blocksuite/initialization/index.ts similarity index 100% rename from packages/common/infra/src/initialization/index.ts rename to packages/frontend/core/src/blocksuite/initialization/index.ts diff --git a/packages/frontend/core/src/components/affine/quota-reached-modal/cloud-quota-modal.tsx b/packages/frontend/core/src/components/affine/quota-reached-modal/cloud-quota-modal.tsx index 0c375e0155..232eaed073 100644 --- a/packages/frontend/core/src/components/affine/quota-reached-modal/cloud-quota-modal.tsx +++ b/packages/frontend/core/src/components/affine/quota-reached-modal/cloud-quota-modal.tsx @@ -88,9 +88,9 @@ export const CloudQuotaModal = () => { currentWorkspace.engine.blob.singleBlobSizeLimit = workspaceQuota.blobLimit; const disposable = - currentWorkspace.engine.blob.onAbortLargeBlob.on(onAbortLargeBlob); + currentWorkspace.engine.blob.onAbortLargeBlob(onAbortLargeBlob); return () => { - disposable?.dispose(); + disposable(); }; }, [currentWorkspace.engine.blob, onAbortLargeBlob, workspaceQuota]); diff --git a/packages/frontend/core/src/components/affine/quota-reached-modal/local-quota-modal.tsx b/packages/frontend/core/src/components/affine/quota-reached-modal/local-quota-modal.tsx index 9703c672fc..06f7d83333 100644 --- a/packages/frontend/core/src/components/affine/quota-reached-modal/local-quota-modal.tsx +++ b/packages/frontend/core/src/components/affine/quota-reached-modal/local-quota-modal.tsx @@ -16,13 +16,13 @@ export const LocalQuotaModal = () => { }, [setOpen]); useEffect(() => { - const disposable = currentWorkspace.engine.blob.onAbortLargeBlob.on(() => { + const disposable = currentWorkspace.engine.blob.onAbortLargeBlob(() => { setOpen(true); }); return () => { - disposable?.dispose(); + disposable(); }; - }, [currentWorkspace.engine.blob.onAbortLargeBlob, setOpen]); + }, [currentWorkspace.engine.blob, setOpen]); return ( { diff --git a/packages/frontend/core/src/modules/doc/services/docs.ts b/packages/frontend/core/src/modules/doc/services/docs.ts index 37fbfd3a80..ed10a53ac4 100644 --- a/packages/frontend/core/src/modules/doc/services/docs.ts +++ b/packages/frontend/core/src/modules/doc/services/docs.ts @@ -3,13 +3,12 @@ import { Unreachable } from '@affine/env/constant'; import type { DocMode } from '@blocksuite/affine/blocks'; import type { DeltaInsert } from '@blocksuite/affine/inline'; import type { AffineTextAttributes } from '@blocksuite/affine-shared/types'; +import { ObjectPool, Service } from '@toeverything/infra'; + import { type DocProps, initDocFromProps, - ObjectPool, - Service, -} from '@toeverything/infra'; - +} from '../../../blocksuite/initialization'; import type { Doc } from '../entities/doc'; import { DocPropertyList } from '../entities/property-list'; import { DocRecordList } from '../entities/record-list'; diff --git a/packages/frontend/core/src/modules/journal/services/journal.ts b/packages/frontend/core/src/modules/journal/services/journal.ts index 6796d66846..6a21c70407 100644 --- a/packages/frontend/core/src/modules/journal/services/journal.ts +++ b/packages/frontend/core/src/modules/journal/services/journal.ts @@ -1,8 +1,11 @@ import { Text } from '@blocksuite/affine/store'; -import type { DocProps } from '@toeverything/infra'; -import { initDocFromProps, LiveData, Service } from '@toeverything/infra'; +import { LiveData, Service } from '@toeverything/infra'; import dayjs from 'dayjs'; +import { + type DocProps, + initDocFromProps, +} from '../../../blocksuite/initialization'; import type { DocsService } from '../../doc'; import type { EditorSettingService } from '../../editor-setting'; import type { JournalStore } from '../store/journal'; diff --git a/packages/frontend/core/src/modules/quicksearch/services/cmdk.ts b/packages/frontend/core/src/modules/quicksearch/services/cmdk.ts index f64d5a52f7..bfbc28e3ce 100644 --- a/packages/frontend/core/src/modules/quicksearch/services/cmdk.ts +++ b/packages/frontend/core/src/modules/quicksearch/services/cmdk.ts @@ -1,8 +1,8 @@ import { track } from '@affine/track'; import { Text } from '@blocksuite/affine/store'; -import type { DocProps } from '@toeverything/infra'; import { Service } from '@toeverything/infra'; +import type { DocProps } from '../../../blocksuite/initialization'; import type { DocsService } from '../../doc'; import { EditorSettingService } from '../../editor-setting'; import type { WorkbenchService } from '../../workbench';