diff --git a/apps/core/.webpack/config.ts b/apps/core/.webpack/config.ts index f400430f6..f3a1a0765 100644 --- a/apps/core/.webpack/config.ts +++ b/apps/core/.webpack/config.ts @@ -111,6 +111,7 @@ export const createConfiguration: ( : 'eval-cheap-module-source-map', resolve: { + symlinks: true, extensionAlias: { '.js': ['.js', '.tsx', '.ts'], '.mjs': ['.mjs', '.mts'], diff --git a/apps/core/src/atoms/mode.ts b/apps/core/src/atoms/mode.ts index bb883df6b..9bb8fdb23 100644 --- a/apps/core/src/atoms/mode.ts +++ b/apps/core/src/atoms/mode.ts @@ -1,4 +1,4 @@ -import { currentPageIdAtom } from '@toeverything/plugin-infra/manager'; +import { currentPageIdAtom } from '@toeverything/plugin-infra/atom'; import { atom } from 'jotai/vanilla'; import { pageSettingFamily } from './index'; diff --git a/apps/core/src/bootstrap/before-app.ts b/apps/core/src/bootstrap/before-app.ts index 526faef85..90c32168b 100644 --- a/apps/core/src/bootstrap/before-app.ts +++ b/apps/core/src/bootstrap/before-app.ts @@ -17,7 +17,7 @@ import { } from '@affine/workspace/migration'; import { createIndexedDBDownloadProvider } from '@affine/workspace/providers'; import { assertExists } from '@blocksuite/global/utils'; -import { rootStore } from '@toeverything/plugin-infra/manager'; +import { rootStore } from '@toeverything/plugin-infra/atom'; import { WorkspaceAdapters } from '../adapters/workspace'; diff --git a/apps/core/src/bootstrap/register-plugins.ts b/apps/core/src/bootstrap/register-plugins.ts index ca7cdf1db..a4b85455d 100644 --- a/apps/core/src/bootstrap/register-plugins.ts +++ b/apps/core/src/bootstrap/register-plugins.ts @@ -6,18 +6,18 @@ import * as BlockSuiteBlocksStd from '@blocksuite/blocks/std'; import { DisposableGroup } from '@blocksuite/global/utils'; import * as BlockSuiteGlobalUtils from '@blocksuite/global/utils'; import * as Icons from '@blocksuite/icons'; -import type { - CallbackMap, - PluginContext, -} from '@toeverything/plugin-infra/entry'; -import * as Manager from '@toeverything/plugin-infra/manager'; +import * as Manager from '@toeverything/plugin-infra/atom'; import { editorItemsAtom, headerItemsAtom, registeredPluginAtom, rootStore, windowItemsAtom, -} from '@toeverything/plugin-infra/manager'; +} from '@toeverything/plugin-infra/atom'; +import type { + CallbackMap, + PluginContext, +} from '@toeverything/plugin-infra/entry'; import * as Jotai from 'jotai'; import { Provider } from 'jotai/react'; import * as JotaiUtils from 'jotai/utils'; @@ -96,6 +96,8 @@ const createGlobalThis = () => { document, navigator, userAgent: navigator.userAgent, + // todo: permission control + fetch: globalThis.fetch, // fixme: use our own db api indexedDB: globalThis.indexedDB, @@ -135,20 +137,19 @@ await Promise.all( return fetch(entryURL).then(async res => { if (assets.length > 0) { await Promise.all( - assets.map(asset => { + assets.map(async asset => { if (asset.endsWith('.css')) { - return fetch(new URL(asset, baseURL)).then(res => { - if (res.ok) { - // todo: how to put css file into sandbox? - return res.text().then(text => { - const style = document.createElement('style'); - style.setAttribute('plugin-id', plugin); - style.textContent = text; - document.head.appendChild(style); - }); - } - return null; - }); + const res = await fetch(new URL(asset, baseURL)); + if (res.ok) { + // todo: how to put css file into sandbox? + return res.text().then(text => { + const style = document.createElement('style'); + style.setAttribute('plugin-id', plugin); + style.textContent = text; + document.head.appendChild(style); + }); + } + return null; } else { return Promise.resolve(); } diff --git a/apps/core/src/components/affine/affine-error-eoundary.tsx b/apps/core/src/components/affine/affine-error-eoundary.tsx index 41d39385d..9f311b788 100644 --- a/apps/core/src/components/affine/affine-error-eoundary.tsx +++ b/apps/core/src/components/affine/affine-error-eoundary.tsx @@ -9,7 +9,7 @@ import { currentPageIdAtom, currentWorkspaceIdAtom, rootStore, -} from '@toeverything/plugin-infra/manager'; +} from '@toeverything/plugin-infra/atom'; import { useAtomValue } from 'jotai/react'; import { Provider } from 'jotai/react'; import type { ErrorInfo, ReactElement, ReactNode } from 'react'; diff --git a/apps/core/src/components/affine/setting-modal/general-setting/plugins/index.tsx b/apps/core/src/components/affine/setting-modal/general-setting/plugins/index.tsx index 8ad3e9acd..e803fc5ed 100644 --- a/apps/core/src/components/affine/setting-modal/general-setting/plugins/index.tsx +++ b/apps/core/src/components/affine/setting-modal/general-setting/plugins/index.tsx @@ -3,7 +3,7 @@ import { SettingWrapper, } from '@affine/component/setting-components'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; -import { registeredPluginAtom } from '@toeverything/plugin-infra/manager'; +import { registeredPluginAtom } from '@toeverything/plugin-infra/atom'; import { useAtomValue } from 'jotai'; export const Plugins = () => { diff --git a/apps/core/src/components/blocksuite/workspace-header/header-right-items/editor-option-menu.tsx b/apps/core/src/components/blocksuite/workspace-header/header-right-items/editor-option-menu.tsx index 714688b5a..a76725433 100644 --- a/apps/core/src/components/blocksuite/workspace-header/header-right-items/editor-option-menu.tsx +++ b/apps/core/src/components/blocksuite/workspace-header/header-right-items/editor-option-menu.tsx @@ -14,7 +14,7 @@ import { useBlockSuitePageMeta, usePageMetaHelper, } from '@toeverything/hooks/use-block-suite-page-meta'; -import { currentPageIdAtom } from '@toeverything/plugin-infra/manager'; +import { currentPageIdAtom } from '@toeverything/plugin-infra/atom'; import { useAtom, useAtomValue } from 'jotai'; import { useState } from 'react'; import { useParams } from 'react-router-dom'; diff --git a/apps/core/src/components/blocksuite/workspace-header/header-right-items/trash-button-group.tsx b/apps/core/src/components/blocksuite/workspace-header/header-right-items/trash-button-group.tsx index 801345811..bf42b0c52 100644 --- a/apps/core/src/components/blocksuite/workspace-header/header-right-items/trash-button-group.tsx +++ b/apps/core/src/components/blocksuite/workspace-header/header-right-items/trash-button-group.tsx @@ -3,7 +3,7 @@ import { WorkspaceSubPath } from '@affine/env/workspace'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { assertExists } from '@blocksuite/global/utils'; import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta'; -import { currentPageIdAtom } from '@toeverything/plugin-infra/manager'; +import { currentPageIdAtom } from '@toeverything/plugin-infra/atom'; import { useAtomValue } from 'jotai'; import { useCallback, useState } from 'react'; diff --git a/apps/core/src/components/blocksuite/workspace-header/header.tsx b/apps/core/src/components/blocksuite/workspace-header/header.tsx index dcbd1967f..9416f0016 100644 --- a/apps/core/src/components/blocksuite/workspace-header/header.tsx +++ b/apps/core/src/components/blocksuite/workspace-header/header.tsx @@ -7,7 +7,7 @@ import { SidebarSwitch } from '@affine/component/app-sidebar/sidebar-header'; import { isDesktop } from '@affine/env/constant'; import { CloseIcon, MinusIcon, RoundedRectangleIcon } from '@blocksuite/icons'; import type { Page } from '@blocksuite/store'; -import { headerItemsAtom } from '@toeverything/plugin-infra/manager'; +import { headerItemsAtom } from '@toeverything/plugin-infra/atom'; import { useAtomValue } from 'jotai'; import type { FC, HTMLAttributes, PropsWithChildren, ReactNode } from 'react'; import { diff --git a/apps/core/src/components/page-detail-editor.tsx b/apps/core/src/components/page-detail-editor.tsx index 2fb3d78b2..aadcfb8ca 100644 --- a/apps/core/src/components/page-detail-editor.tsx +++ b/apps/core/src/components/page-detail-editor.tsx @@ -7,13 +7,13 @@ import { assertExists } from '@blocksuite/global/utils'; import type { Page, Workspace } from '@blocksuite/store'; import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta'; import { useBlockSuiteWorkspacePage } from '@toeverything/hooks/use-block-suite-workspace-page'; -import type { CallbackMap } from '@toeverything/plugin-infra/entry'; import { contentLayoutAtom, editorItemsAtom, rootStore, windowItemsAtom, -} from '@toeverything/plugin-infra/manager'; +} from '@toeverything/plugin-infra/atom'; +import type { CallbackMap } from '@toeverything/plugin-infra/entry'; import type { LayoutNode } from '@toeverything/plugin-infra/type'; import clsx from 'clsx'; import { useAtomValue, useSetAtom } from 'jotai'; diff --git a/apps/core/src/hooks/current/use-current-workspace.ts b/apps/core/src/hooks/current/use-current-workspace.ts index a5915644c..4d782f27f 100644 --- a/apps/core/src/hooks/current/use-current-workspace.ts +++ b/apps/core/src/hooks/current/use-current-workspace.ts @@ -2,7 +2,7 @@ import { assertExists } from '@blocksuite/global/utils'; import { currentPageIdAtom, currentWorkspaceIdAtom, -} from '@toeverything/plugin-infra/manager'; +} from '@toeverything/plugin-infra/atom'; import { useAtom, useSetAtom } from 'jotai'; import { useCallback, useEffect } from 'react'; diff --git a/apps/core/src/hooks/root/use-on-transform-workspace.ts b/apps/core/src/hooks/root/use-on-transform-workspace.ts index f9766dd15..b875bf037 100644 --- a/apps/core/src/hooks/root/use-on-transform-workspace.ts +++ b/apps/core/src/hooks/root/use-on-transform-workspace.ts @@ -1,6 +1,6 @@ import type { WorkspaceRegistry } from '@affine/env/workspace'; import type { WorkspaceFlavour } from '@affine/env/workspace'; -import { currentPageIdAtom } from '@toeverything/plugin-infra/manager'; +import { currentPageIdAtom } from '@toeverything/plugin-infra/atom'; import { useSetAtom } from 'jotai'; import { useCallback } from 'react'; diff --git a/apps/core/src/layouts/workspace-layout.tsx b/apps/core/src/layouts/workspace-layout.tsx index 36e0d2c0e..97978f819 100644 --- a/apps/core/src/layouts/workspace-layout.tsx +++ b/apps/core/src/layouts/workspace-layout.tsx @@ -28,7 +28,7 @@ import { useSensors, } from '@dnd-kit/core'; import { usePassiveWorkspaceEffect } from '@toeverything/plugin-infra/__internal__/react'; -import { currentWorkspaceIdAtom } from '@toeverything/plugin-infra/manager'; +import { currentWorkspaceIdAtom } from '@toeverything/plugin-infra/atom'; import { useAtom, useAtomValue, useSetAtom } from 'jotai'; import type { FC, PropsWithChildren, ReactElement } from 'react'; import { lazy, Suspense, useCallback, useMemo } from 'react'; diff --git a/apps/core/src/pages/index.tsx b/apps/core/src/pages/index.tsx index c2437e955..f53b29123 100644 --- a/apps/core/src/pages/index.tsx +++ b/apps/core/src/pages/index.tsx @@ -1,7 +1,7 @@ import { DebugLogger } from '@affine/debug'; import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom'; import { getWorkspace } from '@toeverything/plugin-infra/__internal__/workspace'; -import { rootStore } from '@toeverything/plugin-infra/manager'; +import { rootStore } from '@toeverything/plugin-infra/atom'; import { lazy } from 'react'; import type { LoaderFunction } from 'react-router-dom'; import { redirect } from 'react-router-dom'; diff --git a/apps/core/src/pages/workspace/all-page.tsx b/apps/core/src/pages/workspace/all-page.tsx index b501c8131..fea5b8e30 100644 --- a/apps/core/src/pages/workspace/all-page.tsx +++ b/apps/core/src/pages/workspace/all-page.tsx @@ -3,10 +3,7 @@ import { DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX } from '@affine/env/constant'; import { WorkspaceSubPath } from '@affine/env/workspace'; import { assertExists } from '@blocksuite/global/utils'; import { getActiveBlockSuiteWorkspaceAtom } from '@toeverything/plugin-infra/__internal__/workspace'; -import { - currentPageIdAtom, - rootStore, -} from '@toeverything/plugin-infra/manager'; +import { currentPageIdAtom, rootStore } from '@toeverything/plugin-infra/atom'; import { useAtom } from 'jotai/react'; import { useCallback, useEffect } from 'react'; import type { LoaderFunction } from 'react-router-dom'; diff --git a/apps/core/src/pages/workspace/detail-page.tsx b/apps/core/src/pages/workspace/detail-page.tsx index e830175bf..62f803666 100644 --- a/apps/core/src/pages/workspace/detail-page.tsx +++ b/apps/core/src/pages/workspace/detail-page.tsx @@ -7,10 +7,7 @@ import { WorkspaceSubPath } from '@affine/env/workspace'; import type { EditorContainer } from '@blocksuite/editor'; import { assertExists } from '@blocksuite/global/utils'; import type { Page } from '@blocksuite/store'; -import { - currentPageIdAtom, - rootStore, -} from '@toeverything/plugin-infra/manager'; +import { currentPageIdAtom, rootStore } from '@toeverything/plugin-infra/atom'; import { useAtomValue } from 'jotai'; import { useAtom } from 'jotai/react'; import { type ReactElement, useCallback, useEffect } from 'react'; diff --git a/apps/core/src/pages/workspace/index.tsx b/apps/core/src/pages/workspace/index.tsx index f2406b7c7..aa8f68b36 100644 --- a/apps/core/src/pages/workspace/index.tsx +++ b/apps/core/src/pages/workspace/index.tsx @@ -2,7 +2,7 @@ import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom'; import { currentWorkspaceIdAtom, rootStore, -} from '@toeverything/plugin-infra/manager'; +} from '@toeverything/plugin-infra/atom'; import type { ReactElement } from 'react'; import { type LoaderFunction, Outlet, redirect } from 'react-router-dom'; diff --git a/apps/core/src/providers/modal-provider.tsx b/apps/core/src/providers/modal-provider.tsx index e3a2b5588..3e6709d24 100644 --- a/apps/core/src/providers/modal-provider.tsx +++ b/apps/core/src/providers/modal-provider.tsx @@ -5,7 +5,7 @@ import { arrayMove } from '@dnd-kit/sortable'; import { currentPageIdAtom, currentWorkspaceIdAtom, -} from '@toeverything/plugin-infra/manager'; +} from '@toeverything/plugin-infra/atom'; import { useAtom, useAtomValue, useSetAtom } from 'jotai'; import type { FC, ReactElement } from 'react'; import { lazy, Suspense, useCallback, useTransition } from 'react'; diff --git a/packages/cli/src/bin/build-core.ts b/packages/cli/src/bin/build-core.ts index cff680a08..c0c9d16c0 100644 --- a/packages/cli/src/bin/build-core.ts +++ b/packages/cli/src/bin/build-core.ts @@ -4,6 +4,7 @@ import path from 'node:path'; import type { BuildFlags } from '../config/index.js'; import { projectRoot } from '../config/index.js'; import { buildI18N } from '../util/i18n.js'; +import { buildInfra } from '../util/infra.js'; const cwd = path.resolve(projectRoot, 'apps', 'core'); @@ -45,6 +46,7 @@ const flags = { } satisfies BuildFlags; buildI18N(); +await buildInfra(); spawn( 'node', [ diff --git a/packages/cli/src/bin/dev-core.ts b/packages/cli/src/bin/dev-core.ts index 6b5d8c347..0cd87dbbe 100644 --- a/packages/cli/src/bin/dev-core.ts +++ b/packages/cli/src/bin/dev-core.ts @@ -7,6 +7,7 @@ import { config } from 'dotenv'; import { type BuildFlags, projectRoot } from '../config/index.js'; import { watchI18N } from '../util/i18n.js'; +import { watchInfra } from '../util/infra.js'; const files = ['.env', '.env.local']; @@ -93,6 +94,7 @@ flags.channel = buildFlags.channel as any; flags.coverage = buildFlags.coverage; watchI18N(); +await watchInfra(); spawn( 'node', [ diff --git a/packages/cli/src/util/infra.ts b/packages/cli/src/util/infra.ts new file mode 100644 index 000000000..3b9cd07b9 --- /dev/null +++ b/packages/cli/src/util/infra.ts @@ -0,0 +1,41 @@ +import { spawn } from 'node:child_process'; +import { resolve } from 'node:path'; + +import { build } from 'vite'; + +import { projectRoot } from '../config/index.js'; + +const infraFilePath = resolve( + projectRoot, + 'packages', + 'infra', + 'vite.config.ts' +); +const pluginInfraFilePath = resolve( + projectRoot, + 'packages', + 'plugin-infra', + 'vite.config.ts' +); + +export const buildInfra = async () => { + await build({ + configFile: infraFilePath, + }); + await build({ + configFile: pluginInfraFilePath, + }); +}; + +export const watchInfra = async () => { + spawn('vite', ['build', '--watch'], { + cwd: resolve(projectRoot, 'packages', 'infra'), + shell: true, + stdio: 'inherit', + }); + spawn('vite', ['build', '--watch'], { + cwd: resolve(projectRoot, 'packages', 'plugin-infra'), + shell: true, + stdio: 'inherit', + }); +}; diff --git a/packages/component/src/components/context/index.tsx b/packages/component/src/components/context/index.tsx index 750a11517..40444e322 100644 --- a/packages/component/src/components/context/index.tsx +++ b/packages/component/src/components/context/index.tsx @@ -1,6 +1,6 @@ import { ProviderComposer } from '@affine/component/provider-composer'; import { ThemeProvider } from '@affine/component/theme-provider'; -import { rootStore } from '@toeverything/plugin-infra/manager'; +import { rootStore } from '@toeverything/plugin-infra/atom'; import { Provider } from 'jotai'; import type { PropsWithChildren } from 'react'; import { useMemo } from 'react'; diff --git a/packages/plugin-infra/package.json b/packages/plugin-infra/package.json index d907d33ff..3b4de83ab 100644 --- a/packages/plugin-infra/package.json +++ b/packages/plugin-infra/package.json @@ -14,10 +14,10 @@ "import": "./dist/entry.js", "require": "./dist/entry.cjs" }, - "./manager": { - "type": "./dist/manager.d.ts", - "import": "./dist/manager.js", - "require": "./dist/manager.cjs" + "./atom": { + "type": "./dist/atom.d.ts", + "import": "./dist/atom.js", + "require": "./dist/atom.cjs" }, "./type": { "type": "./dist/type.d.ts", diff --git a/packages/plugin-infra/src/manager.ts b/packages/plugin-infra/src/atom.ts similarity index 100% rename from packages/plugin-infra/src/manager.ts rename to packages/plugin-infra/src/atom.ts diff --git a/packages/plugin-infra/vite.config.ts b/packages/plugin-infra/vite.config.ts index 549830ebf..f088ee3ae 100644 --- a/packages/plugin-infra/vite.config.ts +++ b/packages/plugin-infra/vite.config.ts @@ -13,7 +13,7 @@ export default defineConfig({ entry: { entry: resolve(root, 'src/entry.ts'), type: resolve(root, 'src/type.ts'), - manager: resolve(root, 'src/manager.ts'), + atom: resolve(root, 'src/atom.ts'), '__internal__/workspace': resolve( root, 'src/__internal__/workspace.ts' diff --git a/plugins/copilot/src/UI/detail-content.tsx b/plugins/copilot/src/UI/detail-content.tsx index f28f4007f..60136a22d 100644 --- a/plugins/copilot/src/UI/detail-content.tsx +++ b/plugins/copilot/src/UI/detail-content.tsx @@ -1,6 +1,6 @@ import { IconButton } from '@affine/component'; import { SendIcon } from '@blocksuite/icons'; -import { contentLayoutAtom } from '@toeverything/plugin-infra/manager'; +import { contentLayoutAtom } from '@toeverything/plugin-infra/atom'; import { useAtomValue, useSetAtom } from 'jotai'; import type { ReactElement } from 'react'; import { Suspense, useCallback, useState } from 'react'; diff --git a/plugins/copilot/src/UI/header-item.tsx b/plugins/copilot/src/UI/header-item.tsx index 925867af2..b7b64b16e 100644 --- a/plugins/copilot/src/UI/header-item.tsx +++ b/plugins/copilot/src/UI/header-item.tsx @@ -1,5 +1,5 @@ import { IconButton, Tooltip } from '@affine/component'; -import { contentLayoutAtom } from '@toeverything/plugin-infra/manager'; +import { contentLayoutAtom } from '@toeverything/plugin-infra/atom'; import { useSetAtom } from 'jotai'; import type { ReactElement } from 'react'; import { useCallback } from 'react'; diff --git a/plugins/hello-world/src/index.ts b/plugins/hello-world/src/index.ts index b94b13eb7..abcc6cd4d 100644 --- a/plugins/hello-world/src/index.ts +++ b/plugins/hello-world/src/index.ts @@ -1,8 +1,8 @@ -import type { PluginContext } from '@toeverything/plugin-infra/entry'; import { currentWorkspaceIdAtom, rootStore, -} from '@toeverything/plugin-infra/manager'; +} from '@toeverything/plugin-infra/atom'; +import type { PluginContext } from '@toeverything/plugin-infra/entry'; import { createElement } from 'react'; import { createRoot } from 'react-dom/client';