diff --git a/apps/core/src/adapters/cloud/ui.tsx b/apps/core/src/adapters/cloud/ui.tsx index 7aeca09954..60ebf2198e 100644 --- a/apps/core/src/adapters/cloud/ui.tsx +++ b/apps/core/src/adapters/cloud/ui.tsx @@ -1,9 +1,9 @@ -import { initEmptyPage } from '@affine/env/blocksuite'; import { PageNotFoundError } from '@affine/env/constant'; import type { WorkspaceFlavour, WorkspaceUISchema, } from '@affine/env/workspace'; +import { initEmptyPage } from '@toeverything/infra/blocksuite'; import { lazy, useCallback } from 'react'; import { useIsWorkspaceOwner } from '../../hooks/affine/use-is-workspace-owner'; diff --git a/apps/core/src/adapters/local/index.tsx b/apps/core/src/adapters/local/index.tsx index 2f469d8562..fd3b0c72af 100644 --- a/apps/core/src/adapters/local/index.tsx +++ b/apps/core/src/adapters/local/index.tsx @@ -1,5 +1,4 @@ import { DebugLogger } from '@affine/debug'; -import { initEmptyPage } from '@affine/env/blocksuite'; import { DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX, DEFAULT_WORKSPACE_NAME, @@ -21,6 +20,7 @@ import { createIndexedDBDownloadProvider } from '@affine/workspace/providers'; import { nanoid } from '@blocksuite/store'; import { useStaticBlockSuiteWorkspace } from '@toeverything/infra/__internal__/react'; import { getCurrentStore } from '@toeverything/infra/atom'; +import { initEmptyPage } from '@toeverything/infra/blocksuite'; import { buildShowcaseWorkspace } from '@toeverything/infra/blocksuite'; import { useCallback } from 'react'; diff --git a/apps/core/src/adapters/public-cloud/ui.tsx b/apps/core/src/adapters/public-cloud/ui.tsx index 626abb7637..03051bf5ed 100644 --- a/apps/core/src/adapters/public-cloud/ui.tsx +++ b/apps/core/src/adapters/public-cloud/ui.tsx @@ -1,7 +1,7 @@ -import { initEmptyPage } from '@affine/env/blocksuite'; import { PageNotFoundError } from '@affine/env/constant'; import type { WorkspaceFlavour } from '@affine/env/workspace'; import { type WorkspaceUISchema } from '@affine/env/workspace'; +import { initEmptyPage } from '@toeverything/infra/blocksuite'; import { useCallback } from 'react'; import { useWorkspace } from '../../hooks/use-workspace'; diff --git a/apps/core/src/components/blocksuite/block-suite-page-list/utils.tsx b/apps/core/src/components/blocksuite/block-suite-page-list/utils.tsx index 54cb82bbcd..4ccec34e73 100644 --- a/apps/core/src/components/blocksuite/block-suite-page-list/utils.tsx +++ b/apps/core/src/components/blocksuite/block-suite-page-list/utils.tsx @@ -1,7 +1,7 @@ import { toast } from '@affine/component'; -import { initEmptyPage } from '@affine/env/blocksuite'; import { WorkspaceSubPath } from '@affine/env/workspace'; import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper'; +import { initEmptyPage } from '@toeverything/infra/blocksuite'; import { useAtomValue, useSetAtom } from 'jotai'; import { useCallback } from 'react'; diff --git a/apps/core/src/components/pure/quick-search-modal/footer.tsx b/apps/core/src/components/pure/quick-search-modal/footer.tsx index 27f40029cf..1764ecd0e0 100644 --- a/apps/core/src/components/pure/quick-search-modal/footer.tsx +++ b/apps/core/src/components/pure/quick-search-modal/footer.tsx @@ -1,9 +1,9 @@ -import { initEmptyPage } from '@affine/env/blocksuite'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { assertEquals } from '@blocksuite/global/utils'; import { PlusIcon } from '@blocksuite/icons'; import { nanoid } from '@blocksuite/store'; import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper'; +import { initEmptyPage } from '@toeverything/infra/blocksuite'; import { Command } from 'cmdk'; import { useCallback } from 'react'; diff --git a/apps/storybook/src/stories/image-preview-modal.stories.tsx b/apps/storybook/src/stories/image-preview-modal.stories.tsx index 47b7b8f589..2de7f1bd8f 100644 --- a/apps/storybook/src/stories/image-preview-modal.stories.tsx +++ b/apps/storybook/src/stories/image-preview-modal.stories.tsx @@ -1,12 +1,12 @@ import { BlockHubWrapper } from '@affine/component/block-hub'; import { BlockSuiteEditor } from '@affine/component/block-suite-editor'; -import { initEmptyPage } from '@affine/env/blocksuite'; import { WorkspaceFlavour } from '@affine/env/workspace'; // eslint-disable-next-line @typescript-eslint/no-restricted-imports import { ImagePreviewModal } from '@affine/image-preview-plugin/src/component'; import { rootBlockHubAtom } from '@affine/workspace/atom'; import { getOrCreateWorkspace } from '@affine/workspace/manager'; import type { Meta } from '@storybook/react'; +import { initEmptyPage } from '@toeverything/infra/blocksuite'; import { useCallback } from 'react'; import { createPortal } from 'react-dom'; diff --git a/packages/env/src/blocksuite/index.ts b/packages/env/src/blocksuite/index.ts deleted file mode 100644 index e95e658291..0000000000 --- a/packages/env/src/blocksuite/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { Page } from '@blocksuite/store'; - -/** - * @deprecated - */ -export async function initEmptyPage(page: Page, title?: string) { - await page.waitForLoaded(); - const pageBlockId = page.addBlock('affine:page', { - title: new page.Text(title || ''), - }); - page.addBlock('affine:surface', {}, pageBlockId); - const noteBlockId = page.addBlock('affine:note', {}, pageBlockId); - page.addBlock('affine:paragraph', {}, noteBlockId); -} diff --git a/packages/hooks/src/__tests__/use-block-suite-workspace-helper.spec.ts b/packages/hooks/src/__tests__/use-block-suite-workspace-helper.spec.ts index 94887c2f58..1592bf85e2 100644 --- a/packages/hooks/src/__tests__/use-block-suite-workspace-helper.spec.ts +++ b/packages/hooks/src/__tests__/use-block-suite-workspace-helper.spec.ts @@ -3,10 +3,10 @@ */ import 'fake-indexeddb/auto'; -import { initEmptyPage } from '@affine/env/blocksuite'; import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models'; import { Schema, Workspace } from '@blocksuite/store'; import { renderHook } from '@testing-library/react'; +import { initEmptyPage } from '@toeverything/infra/blocksuite'; import { beforeEach, describe, expect, test } from 'vitest'; import { useBlockSuitePageMeta } from '../use-block-suite-page-meta'; diff --git a/packages/infra/src/blocksuite/index.ts b/packages/infra/src/blocksuite/index.ts index 8c6eb91cad..3c537096c3 100644 --- a/packages/infra/src/blocksuite/index.ts +++ b/packages/infra/src/blocksuite/index.ts @@ -1,8 +1,26 @@ -import type { PageMeta, Workspace } from '@blocksuite/store'; +import type { Page, PageMeta, Workspace } from '@blocksuite/store'; import { createIndexeddbStorage } from '@blocksuite/store'; import type { createStore, WritableAtom } from 'jotai/vanilla'; import { Array as YArray, Doc as YDoc, Map as YMap } from 'yjs'; +export async function initEmptyPage(page: Page, title?: string) { + await page.waitForLoaded(); + const pageBlockId = page.addBlock('affine:page', { + title: new page.Text(title ?? ''), + }); + page.addBlock('affine:surface', {}, pageBlockId); + const noteBlockId = page.addBlock('affine:note', {}, pageBlockId); + page.addBlock('affine:paragraph', {}, noteBlockId); +} + +export async function buildEmptyBlockSuite(workspace: Workspace) { + const page = workspace.createPage(); + await initEmptyPage(page); + workspace.setPageMeta(page.id, { + jumpOnce: true, + }); +} + export async function buildShowcaseWorkspace( workspace: Workspace, options: {