From 47f12f77f27d70c78acfe2c760aa93e9017999c4 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Wed, 19 Jul 2023 00:53:10 +0800 Subject: [PATCH] refactor!: remove `next.js` (#3267) --- .codesandbox/task.json | 2 +- .github/deployment/front/Dockerfile | 2 +- .github/workflows/build.yml | 42 +- .github/workflows/nightly-build.yml | 4 +- .github/workflows/release-desktop-app.yml | 6 +- .gitignore | 1 + apps/core/.webpack/cache-group.ts | 84 + apps/core/.webpack/config.ts | 306 ++ apps/core/.webpack/postcss.config.cjs | 20 + apps/core/.webpack/runtime-config.ts | 115 + apps/core/.webpack/template.html | 45 + apps/core/.webpack/utils.ts | 18 + apps/core/.webpack/webpack.config.ts | 23 + apps/{web => core}/package.json | 58 +- apps/{web => core}/project.json | 15 +- apps/{web => core}/public/.gitignore | 0 .../{web => core}/public/apple-touch-icon.png | Bin apps/{web => core}/public/editingVideo.mp4 | Bin apps/{web => core}/public/favicon-144.png | Bin apps/{web => core}/public/favicon-192.png | Bin apps/{web => core}/public/favicon-36.png | Bin apps/{web => core}/public/favicon-48.png | Bin apps/{web => core}/public/favicon-72.png | Bin apps/{web => core}/public/favicon-96.png | Bin apps/{web => core}/public/favicon.ico | Bin .../inter/Inter-VariableFont_slnt,wght.ttf | Bin apps/{web => core}/public/fonts/inter/OFL.txt | 0 .../public/fonts/kalam/Kalam-Bold.ttf | Bin .../public/fonts/kalam/Kalam-Light.ttf | Bin .../public/fonts/kalam/Kalam-Regular.ttf | Bin apps/{web => core}/public/fonts/kalam/OFL.txt | 0 .../public/fonts/source-code-pro/OFL.txt | 0 ...SourceCodePro-Italic-VariableFont_wght.ttf | Bin .../SourceCodePro-VariableFont_wght.ttf | Bin .../public/fonts/source-serif-4/OFL.txt | 0 .../source-serif-4/SourceSerif4-Bold.ttf | Bin .../SourceSerif4-BoldItalic.ttf | Bin ...ceSerif4-Italic-VariableFont_opsz,wght.ttf | Bin .../source-serif-4/SourceSerif4-Italic.ttf | Bin .../source-serif-4/SourceSerif4-Light.ttf | Bin .../SourceSerif4-LightItalic.ttf | Bin .../source-serif-4/SourceSerif4-Medium.ttf | Bin .../SourceSerif4-MediumItalic.ttf | Bin .../source-serif-4/SourceSerif4-Regular.ttf | Bin .../source-serif-4/SourceSerif4-SemiBold.ttf | Bin .../SourceSerif4-SemiBoldItalic.ttf | Bin .../SourceSerif4-VariableFont_opsz,wght.ttf | Bin .../public/fonts/space-mono/OFL.txt | 0 .../fonts/space-mono/SpaceMono-Bold.ttf | Bin .../fonts/space-mono/SpaceMono-BoldItalic.ttf | Bin .../fonts/space-mono/SpaceMono-Italic.ttf | Bin .../fonts/space-mono/SpaceMono-Regular.ttf | Bin .../public/imgs/affine-text-logo.png | Bin .../public/imgs/invite-error.svg | 0 .../public/imgs/invite-success.svg | 0 apps/{web => core}/public/imgs/no-result.svg | 0 apps/{web => core}/public/manifest.json | 0 ...21c2ea5e6140ff7732ef9e28a9f944e9bf3ca4.png | Bin ...56d9ee1b30a0dfdda26222fc2d2c872b14e609.gif | Bin ...10ee0b51c00c3c7665236a1a82406370d46e0a.gif | Bin ...8729ff46be6595711898bab3dc43302319a987.gif | Bin ...d9d7b43e01eac948337fe57571443e87bc3a60.png | Bin ...4e05dbb69a22742372b3534442607a2d6a9998.gif | Bin ...1883903f5bb0b96bf523c9a6b3ce5868f03db5.gif | Bin ...6d43bf0793fdef24e60044d174f0abdefebe08.gif | Bin apps/{web => core}/public/switchVideo.mp4 | Bin apps/core/server.mts | 15 + .../src/adapters/local/index.tsx | 0 apps/{web => core}/src/adapters/shared.ts | 0 apps/{web => core}/src/adapters/workspace.ts | 0 apps/core/src/app.tsx | 158 + .../src/atoms/__tests__/atom.spec.ts | 0 apps/{web => core}/src/atoms/guide.ts | 0 apps/core/src/atoms/history.ts | 52 + apps/{web => core}/src/atoms/index.ts | 0 apps/{web => core}/src/atoms/layout.ts | 0 apps/{web => core}/src/atoms/mode.ts | 0 apps/{web => core}/src/atoms/settings.ts | 0 .../components/__debug__/client/editor.tsx | 0 .../src/components/affine/README.md | 0 .../affine/affine-error-eoundary.tsx | 35 +- .../src/components/affine/app-container.tsx | 0 .../create-workspace-modal/index.css.ts | 0 .../affine/create-workspace-modal/index.tsx | 0 .../enable-affine-cloud-modal/index.tsx | 0 .../affine/enable-affine-cloud-modal/style.ts | 0 .../components/affine/language-menu/index.tsx | 0 .../delete-leave-workspace/delete/index.tsx | 0 .../delete-leave-workspace/delete/style.ts | 0 .../delete-leave-workspace/index.tsx | 0 .../delete-leave-workspace/leave/index.tsx | 0 .../delete-leave-workspace/leave/style.ts | 0 .../new-workspace-setting-detail/export.tsx | 0 .../new-workspace-setting-detail/index.tsx | 0 .../new-workspace-setting-detail/profile.tsx | 0 .../new-workspace-setting-detail/publish.tsx | 0 .../new-workspace-setting-detail/storage.tsx | 0 .../new-workspace-setting-detail/style.css.ts | 0 .../components/affine/onboarding-modal.tsx | 0 .../setting-modal/account-setting/index.tsx | 0 .../general-setting/about/config.tsx | 0 .../general-setting/about/icons.tsx | 0 .../general-setting/about/index.tsx | 28 +- .../general-setting/about/style.css.ts | 0 .../appearance/date-format-setting.tsx | 0 .../general-setting/appearance/index.tsx | 0 .../general-setting/appearance/style.css.ts | 0 .../setting-modal/general-setting/index.tsx | 0 .../general-setting/plugins/index.tsx | 0 .../general-setting/plugins/style.css.ts | 0 .../general-setting/shortcuts/index.tsx | 0 .../general-setting/shortcuts/style.css.ts | 0 .../components/affine/setting-modal/index.tsx | 6 +- .../setting-modal/setting-sidebar/index.tsx | 0 .../setting-sidebar/style.css.ts | 0 .../affine/setting-modal/style.css.ts | 0 .../setting-modal/workspace-setting/index.tsx | 11 +- .../tmp-disable-affine-cloud-modal/index.tsx | 1 + .../tmp-disable-affine-cloud-modal/style.ts | 0 .../index.tsx | 0 .../style.ts | 0 .../panel/general/icons.tsx | 0 .../blocksuite/block-suite-editor/index.tsx | 0 .../block-suite-page-list/index.css.ts | 0 .../block-suite-page-list/index.tsx | 0 .../block-suite-page-list/utils.tsx | 6 +- .../workspace-header/download-tips.tsx | 0 .../animation-data/edgeless-hover.json | 0 .../animation-data/page-hover.json | 0 .../editor-mode-switch/index.tsx | 0 .../editor-mode-switch/style.ts | 0 .../editor-mode-switch/switch-items.tsx | 0 .../header-right-items/editor-option-menu.tsx | 6 +- .../header-right-items/language-menu.tsx | 0 .../theme-mode-switch/icons.tsx | 0 .../theme-mode-switch/index.tsx | 0 .../theme-mode-switch/style.ts | 0 .../header-right-items/trash-button-group.tsx | 23 +- .../header-right-items/user-avatar.tsx | 0 .../blocksuite/workspace-header/header.tsx | 52 +- .../blocksuite/workspace-header/index.tsx | 0 .../blocksuite/workspace-header/styles.css.ts | 0 .../blocksuite/workspace-header/utils.tsx | 3 +- .../src/components/filter-container.css.ts | 0 .../src/components/page-detail-editor.css.ts | 0 .../src/components/page-detail-editor.tsx | 6 - .../src/components/pure/file-upload/index.tsx | 0 .../src/components/pure/footer/index.tsx | 0 .../src/components/pure/footer/styles.ts | 0 .../src/components/pure/help-island/icons.tsx | 0 .../src/components/pure/help-island/index.tsx | 0 .../src/components/pure/help-island/style.ts | 0 .../src/components/pure/icons/index.tsx | 0 .../pure/quick-search-button/index.tsx | 0 .../pure/quick-search-modal/config.ts | 0 .../pure/quick-search-modal/footer.tsx | 11 +- .../pure/quick-search-modal/index.tsx | 58 +- .../pure/quick-search-modal/results.tsx | 27 +- .../pure/quick-search-modal/search-input.tsx | 0 .../pure/quick-search-modal/style.ts | 0 .../components/pure/shortcuts-modal/icons.tsx | 0 .../components/pure/shortcuts-modal/index.tsx | 0 .../components/pure/shortcuts-modal/style.ts | 0 .../pure/workspace-list-modal/index.tsx | 0 .../pure/workspace-list-modal/styles.ts | 0 .../WorkspaceSelector/index.css.ts | 0 .../WorkspaceSelector/index.ts | 0 .../WorkspaceSelector/styles.ts | 0 .../WorkspaceSelector/workspace-selector.tsx | 0 .../collections/collections-list.tsx | 17 +- .../collections/index.tsx | 0 .../workspace-slider-bar/collections/page.tsx | 12 +- .../collections/styles.css.ts | 0 .../components/reference-page.tsx | 8 +- .../favorite/empty-item.tsx | 0 .../favorite/favorite-list.tsx | 0 .../workspace-slider-bar/favorite/index.tsx | 0 .../favorite/styles.css.ts | 0 .../pure/workspace-slider-bar/index.tsx | 0 .../workspace-slider-bar/shared-styles.ts | 0 .../pure/workspace-slider-bar/style.ts | 0 .../components/pure/workspace-title/index.tsx | 0 .../root-app-sidebar/import-page.tsx | 0 .../src/components/root-app-sidebar/index.tsx | 0 .../src/components/workspace-header.tsx | 0 .../hooks/__tests__/use-system-online.spec.ts | 0 apps/{web => core}/src/hooks/affine/README.md | 0 .../affine/use-block-suite-meta-helper.ts | 0 .../hooks/affine/use-reference-link-helper.ts | 0 .../src/hooks/affine/use-shortcuts.ts | 0 .../hooks/current/use-current-workspace.ts | 0 .../hooks/root/use-on-transform-workspace.ts | 0 .../src/hooks/use-get-page-info.ts | 0 apps/core/src/hooks/use-location-title.ts | 4 + apps/core/src/hooks/use-navigate-helper.ts | 88 + .../src/hooks/use-system-online.ts | 0 .../src/hooks/use-transform-workspace.ts | 0 .../src/hooks/use-workspace-blob.ts | 0 apps/{web => core}/src/hooks/use-workspace.ts | 0 .../{web => core}/src/hooks/use-workspaces.ts | 0 apps/core/src/index.tsx | 106 + .../src/layouts/workspace-layout.tsx | 74 +- apps/{web => core}/src/pages/404.tsx | 29 +- apps/core/src/pages/index.tsx | 130 + apps/core/src/pages/workspace/all-page.tsx | 50 + .../src/pages/workspace/detail-page.tsx} | 63 +- apps/core/src/pages/workspace/trash-page.tsx | 52 + .../src/providers/modal-provider.tsx | 10 +- .../src/shared/__tests__/gql.spec.tsx | 0 apps/{web => core}/src/shared/gql.ts | 0 apps/{web => core}/src/shared/index.ts | 17 - apps/{web => core}/src/types/types.d.ts | 0 .../src/utils/create-emotion-cache.ts | 0 apps/{web => core}/src/utils/filter.ts | 0 apps/{web => core}/src/utils/index.ts | 0 apps/{web => core}/src/utils/string2color.ts | 0 apps/{web => core}/src/utils/toast.ts | 0 apps/{web => core}/tsconfig.json | 44 +- apps/core/tsconfig.node.json | 20 + .../tsconfig.server.json} | 2 +- apps/electron/scripts/generate-assets.mjs | 16 +- apps/electron/src/main/main-window.ts | 2 +- apps/storybook/.storybook/main.ts | 15 +- apps/storybook/tsconfig.node.json | 3 + apps/web/.env.local.template | 8 - apps/web/.eslintrc | 5 - apps/web/README.md | 28 - apps/web/next-env.d.ts | 5 - apps/web/next.config.mjs | 241 -- apps/web/preset.config.mjs | 113 - apps/web/scripts/git-info.mjs | 36 - apps/web/sentry.client.config.ts | 11 - apps/web/sentry.edge.config.ts | 8 - apps/web/sentry.properties | 4 - apps/web/sentry.server.config.ts | 8 - apps/web/server.mts | 34 - apps/web/src/atoms/history.ts | 103 - apps/web/src/bootstrap/index.ts | 229 -- .../header-right-items/edit-page.tsx | 41 - .../header-right-items/share-menu.tsx | 120 - .../quick-search-modal/published-results.tsx | 104 - .../__snapshots__/index.spec.tsx.snap | 17 - apps/web/src/hooks/__tests__/index.spec.tsx | 130 - .../hooks/__tests__/use-router-helper.spec.ts | 88 - apps/web/src/hooks/use-router-helper.ts | 77 - apps/web/src/hooks/use-router-title.ts | 26 - .../src/layouts/public-workspace-layout.tsx | 63 - apps/web/src/pages/_app.tsx | 84 - apps/web/src/pages/_debug/README.md | 3 - apps/web/src/pages/_debug/init-page.dev.tsx | 34 - apps/web/src/pages/_debug/migration.tsx | 175 - apps/web/src/pages/_document.tsx | 87 - apps/web/src/pages/_error.tsx | 15 - apps/web/src/pages/index.tsx | 109 - .../src/pages/workspace/[workspaceId]/all.tsx | 62 - .../pages/workspace/[workspaceId]/shared.tsx | 57 - .../pages/workspace/[workspaceId]/trash.tsx | 61 - package.json | 9 +- packages/cli/package.json | 7 +- packages/cli/src/bin/build-core.mjs | 16 + packages/cli/src/bin/build-core.ts | 48 + .../cli/src/{dev.mjs => bin/dev-core.mjs} | 2 +- packages/cli/src/bin/dev-core.ts | 84 + packages/cli/src/config/index.ts | 12 + packages/cli/src/dev.ts | 85 - packages/cli/tsconfig.json | 10 + .../src/components/app-sidebar/index.jotai.ts | 5 +- .../src/components/app-sidebar/index.tsx | 11 +- packages/env/package.json | 1 + .../src/__tests__/is-valid-ip-address.spec.ts | 2 +- .../src/__tests__/subdoc-migration.spec.ts | 2 +- packages/env/src/blocksuite/index.ts | 8 +- packages/env/src/global.ts | 79 +- packages/env/src/workspace.ts | 2 +- packages/env/tsconfig.json | 1 + packages/hooks/package.json | 17 + packages/infra/package.json | 12 +- packages/infra/preload/electron.d.ts | 2 +- packages/infra/src/handler.ts | 4 +- packages/infra/src/index.ts | 4 +- packages/infra/src/type.ts | 2 +- packages/infra/tsconfig.json | 1 + packages/infra/vite.config.ts | 6 +- scripts/setup/global.ts | 8 + scripts/vitest/next-config-mock.ts | 21 - tests/affine-local/e2e/all-page.spec.ts | 7 - .../affine-local/e2e/debug-init-page.spec.ts | 12 - .../e2e/local-first-collections-items.spec.ts | 3 - tests/affine-local/e2e/open-affine.spec.ts | 2 +- tests/kit/playwright.ts | 12 + tests/kit/utils/page-logic.ts | 6 - tests/unit/compare-config.spec.ts | 25 - tests/unit/tsconfig.json | 8 - tsconfig.json | 13 +- tsconfig.node.json | 9 +- yarn.lock | 2987 +++++++++++++---- 296 files changed, 4115 insertions(+), 3617 deletions(-) create mode 100644 apps/core/.webpack/cache-group.ts create mode 100644 apps/core/.webpack/config.ts create mode 100644 apps/core/.webpack/postcss.config.cjs create mode 100644 apps/core/.webpack/runtime-config.ts create mode 100644 apps/core/.webpack/template.html create mode 100644 apps/core/.webpack/utils.ts create mode 100644 apps/core/.webpack/webpack.config.ts rename apps/{web => core}/package.json (60%) rename apps/{web => core}/project.json (74%) rename apps/{web => core}/public/.gitignore (100%) rename apps/{web => core}/public/apple-touch-icon.png (100%) rename apps/{web => core}/public/editingVideo.mp4 (100%) rename apps/{web => core}/public/favicon-144.png (100%) rename apps/{web => core}/public/favicon-192.png (100%) rename apps/{web => core}/public/favicon-36.png (100%) rename apps/{web => core}/public/favicon-48.png (100%) rename apps/{web => core}/public/favicon-72.png (100%) rename apps/{web => core}/public/favicon-96.png (100%) rename apps/{web => core}/public/favicon.ico (100%) rename apps/{web => core}/public/fonts/inter/Inter-VariableFont_slnt,wght.ttf (100%) rename apps/{web => core}/public/fonts/inter/OFL.txt (100%) rename apps/{web => core}/public/fonts/kalam/Kalam-Bold.ttf (100%) rename apps/{web => core}/public/fonts/kalam/Kalam-Light.ttf (100%) rename apps/{web => core}/public/fonts/kalam/Kalam-Regular.ttf (100%) rename apps/{web => core}/public/fonts/kalam/OFL.txt (100%) rename apps/{web => core}/public/fonts/source-code-pro/OFL.txt (100%) rename apps/{web => core}/public/fonts/source-code-pro/SourceCodePro-Italic-VariableFont_wght.ttf (100%) rename apps/{web => core}/public/fonts/source-code-pro/SourceCodePro-VariableFont_wght.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/OFL.txt (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-Bold.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-BoldItalic.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-Italic-VariableFont_opsz,wght.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-Italic.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-Light.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-LightItalic.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-Medium.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-MediumItalic.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-Regular.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-SemiBold.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-SemiBoldItalic.ttf (100%) rename apps/{web => core}/public/fonts/source-serif-4/SourceSerif4-VariableFont_opsz,wght.ttf (100%) rename apps/{web => core}/public/fonts/space-mono/OFL.txt (100%) rename apps/{web => core}/public/fonts/space-mono/SpaceMono-Bold.ttf (100%) rename apps/{web => core}/public/fonts/space-mono/SpaceMono-BoldItalic.ttf (100%) rename apps/{web => core}/public/fonts/space-mono/SpaceMono-Italic.ttf (100%) rename apps/{web => core}/public/fonts/space-mono/SpaceMono-Regular.ttf (100%) rename apps/{web => core}/public/imgs/affine-text-logo.png (100%) rename apps/{web => core}/public/imgs/invite-error.svg (100%) rename apps/{web => core}/public/imgs/invite-success.svg (100%) rename apps/{web => core}/public/imgs/no-result.svg (100%) rename apps/{web => core}/public/manifest.json (100%) rename apps/{web => core}/public/static/047ebf2c9a5c7c9d8521c2ea5e6140ff7732ef9e28a9f944e9bf3ca4.png (100%) rename apps/{web => core}/public/static/1326bc48553a572c6756d9ee1b30a0dfdda26222fc2d2c872b14e609.gif (100%) rename apps/{web => core}/public/static/27f983d0765289c19d10ee0b51c00c3c7665236a1a82406370d46e0a.gif (100%) rename apps/{web => core}/public/static/28516717d63e469cd98729ff46be6595711898bab3dc43302319a987.gif (100%) rename apps/{web => core}/public/static/6aa785ee927547ce9dd9d7b43e01eac948337fe57571443e87bc3a60.png (100%) rename apps/{web => core}/public/static/9288be57321c8772d04e05dbb69a22742372b3534442607a2d6a9998.gif (100%) rename apps/{web => core}/public/static/c820edeeba50006b531883903f5bb0b96bf523c9a6b3ce5868f03db5.gif (100%) rename apps/{web => core}/public/static/e93536e1be97e3b5206d43bf0793fdef24e60044d174f0abdefebe08.gif (100%) rename apps/{web => core}/public/switchVideo.mp4 (100%) create mode 100644 apps/core/server.mts rename apps/{web => core}/src/adapters/local/index.tsx (100%) rename apps/{web => core}/src/adapters/shared.ts (100%) rename apps/{web => core}/src/adapters/workspace.ts (100%) create mode 100644 apps/core/src/app.tsx rename apps/{web => core}/src/atoms/__tests__/atom.spec.ts (100%) rename apps/{web => core}/src/atoms/guide.ts (100%) create mode 100644 apps/core/src/atoms/history.ts rename apps/{web => core}/src/atoms/index.ts (100%) rename apps/{web => core}/src/atoms/layout.ts (100%) rename apps/{web => core}/src/atoms/mode.ts (100%) rename apps/{web => core}/src/atoms/settings.ts (100%) rename apps/{web => core}/src/components/__debug__/client/editor.tsx (100%) rename apps/{web => core}/src/components/affine/README.md (100%) rename apps/{web => core}/src/components/affine/affine-error-eoundary.tsx (73%) rename apps/{web => core}/src/components/affine/app-container.tsx (100%) rename apps/{web => core}/src/components/affine/create-workspace-modal/index.css.ts (100%) rename apps/{web => core}/src/components/affine/create-workspace-modal/index.tsx (100%) rename apps/{web => core}/src/components/affine/enable-affine-cloud-modal/index.tsx (100%) rename apps/{web => core}/src/components/affine/enable-affine-cloud-modal/style.ts (100%) rename apps/{web => core}/src/components/affine/language-menu/index.tsx (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/index.tsx (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/style.ts (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/index.tsx (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/index.tsx (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/style.ts (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/export.tsx (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/index.tsx (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/profile.tsx (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/publish.tsx (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/storage.tsx (100%) rename apps/{web => core}/src/components/affine/new-workspace-setting-detail/style.css.ts (100%) rename apps/{web => core}/src/components/affine/onboarding-modal.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/account-setting/index.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/about/config.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/about/icons.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/about/index.tsx (87%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/about/style.css.ts (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/appearance/date-format-setting.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/appearance/index.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/appearance/style.css.ts (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/index.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/plugins/index.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/plugins/style.css.ts (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/shortcuts/index.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/general-setting/shortcuts/style.css.ts (100%) rename apps/{web => core}/src/components/affine/setting-modal/index.tsx (95%) rename apps/{web => core}/src/components/affine/setting-modal/setting-sidebar/index.tsx (100%) rename apps/{web => core}/src/components/affine/setting-modal/setting-sidebar/style.css.ts (100%) rename apps/{web => core}/src/components/affine/setting-modal/style.css.ts (100%) rename apps/{web => core}/src/components/affine/setting-modal/workspace-setting/index.tsx (86%) rename apps/{web => core}/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx (98%) rename apps/{web => core}/src/components/affine/tmp-disable-affine-cloud-modal/style.ts (100%) rename apps/{web => core}/src/components/affine/transform-workspace-to-affine-modal/index.tsx (100%) rename apps/{web => core}/src/components/affine/transform-workspace-to-affine-modal/style.ts (100%) rename apps/{web => core}/src/components/affine/workspace-setting-detail/panel/general/icons.tsx (100%) rename apps/{web => core}/src/components/blocksuite/block-suite-editor/index.tsx (100%) rename apps/{web => core}/src/components/blocksuite/block-suite-page-list/index.css.ts (100%) rename apps/{web => core}/src/components/blocksuite/block-suite-page-list/index.tsx (100%) rename apps/{web => core}/src/components/blocksuite/block-suite-page-list/utils.tsx (89%) rename apps/{web => core}/src/components/blocksuite/workspace-header/download-tips.tsx (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/edgeless-hover.json (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/page-hover.json (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/editor-mode-switch/style.ts (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/editor-mode-switch/switch-items.tsx (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/header-right-items/editor-option-menu.tsx (97%) rename apps/{web => core}/src/components/blocksuite/workspace-header/header-right-items/language-menu.tsx (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/icons.tsx (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/index.tsx (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/style.ts (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/header-right-items/trash-button-group.tsx (80%) rename apps/{web => core}/src/components/blocksuite/workspace-header/header-right-items/user-avatar.tsx (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/header.tsx (82%) rename apps/{web => core}/src/components/blocksuite/workspace-header/index.tsx (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/styles.css.ts (100%) rename apps/{web => core}/src/components/blocksuite/workspace-header/utils.tsx (93%) rename apps/{web => core}/src/components/filter-container.css.ts (100%) rename apps/{web => core}/src/components/page-detail-editor.css.ts (100%) rename apps/{web => core}/src/components/page-detail-editor.tsx (95%) rename apps/{web => core}/src/components/pure/file-upload/index.tsx (100%) rename apps/{web => core}/src/components/pure/footer/index.tsx (100%) rename apps/{web => core}/src/components/pure/footer/styles.ts (100%) rename apps/{web => core}/src/components/pure/help-island/icons.tsx (100%) rename apps/{web => core}/src/components/pure/help-island/index.tsx (100%) rename apps/{web => core}/src/components/pure/help-island/style.ts (100%) rename apps/{web => core}/src/components/pure/icons/index.tsx (100%) rename apps/{web => core}/src/components/pure/quick-search-button/index.tsx (100%) rename apps/{web => core}/src/components/pure/quick-search-modal/config.ts (100%) rename apps/{web => core}/src/components/pure/quick-search-modal/footer.tsx (87%) rename apps/{web => core}/src/components/pure/quick-search-modal/index.tsx (75%) rename apps/{web => core}/src/components/pure/quick-search-modal/results.tsx (86%) rename apps/{web => core}/src/components/pure/quick-search-modal/search-input.tsx (100%) rename apps/{web => core}/src/components/pure/quick-search-modal/style.ts (100%) rename apps/{web => core}/src/components/pure/shortcuts-modal/icons.tsx (100%) rename apps/{web => core}/src/components/pure/shortcuts-modal/index.tsx (100%) rename apps/{web => core}/src/components/pure/shortcuts-modal/style.ts (100%) rename apps/{web => core}/src/components/pure/workspace-list-modal/index.tsx (100%) rename apps/{web => core}/src/components/pure/workspace-list-modal/styles.ts (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.css.ts (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.ts (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/WorkspaceSelector/styles.ts (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/WorkspaceSelector/workspace-selector.tsx (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/collections/collections-list.tsx (95%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/collections/index.tsx (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/collections/page.tsx (94%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/collections/styles.css.ts (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/components/reference-page.tsx (94%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/favorite/empty-item.tsx (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/favorite/favorite-list.tsx (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/favorite/index.tsx (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/favorite/styles.css.ts (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/index.tsx (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/shared-styles.ts (100%) rename apps/{web => core}/src/components/pure/workspace-slider-bar/style.ts (100%) rename apps/{web => core}/src/components/pure/workspace-title/index.tsx (100%) rename apps/{web => core}/src/components/root-app-sidebar/import-page.tsx (100%) rename apps/{web => core}/src/components/root-app-sidebar/index.tsx (100%) rename apps/{web => core}/src/components/workspace-header.tsx (100%) rename apps/{web => core}/src/hooks/__tests__/use-system-online.spec.ts (100%) rename apps/{web => core}/src/hooks/affine/README.md (100%) rename apps/{web => core}/src/hooks/affine/use-block-suite-meta-helper.ts (100%) rename apps/{web => core}/src/hooks/affine/use-reference-link-helper.ts (100%) rename apps/{web => core}/src/hooks/affine/use-shortcuts.ts (100%) rename apps/{web => core}/src/hooks/current/use-current-workspace.ts (100%) rename apps/{web => core}/src/hooks/root/use-on-transform-workspace.ts (100%) rename apps/{web => core}/src/hooks/use-get-page-info.ts (100%) create mode 100644 apps/core/src/hooks/use-location-title.ts create mode 100644 apps/core/src/hooks/use-navigate-helper.ts rename apps/{web => core}/src/hooks/use-system-online.ts (100%) rename apps/{web => core}/src/hooks/use-transform-workspace.ts (100%) rename apps/{web => core}/src/hooks/use-workspace-blob.ts (100%) rename apps/{web => core}/src/hooks/use-workspace.ts (100%) rename apps/{web => core}/src/hooks/use-workspaces.ts (100%) create mode 100644 apps/core/src/index.tsx rename apps/{web => core}/src/layouts/workspace-layout.tsx (85%) rename apps/{web => core}/src/pages/404.tsx (58%) create mode 100644 apps/core/src/pages/index.tsx create mode 100644 apps/core/src/pages/workspace/all-page.tsx rename apps/{web/src/pages/workspace/[workspaceId]/[pageId].tsx => core/src/pages/workspace/detail-page.tsx} (65%) create mode 100644 apps/core/src/pages/workspace/trash-page.tsx rename apps/{web => core}/src/providers/modal-provider.tsx (95%) rename apps/{web => core}/src/shared/__tests__/gql.spec.tsx (100%) rename apps/{web => core}/src/shared/gql.ts (100%) rename apps/{web => core}/src/shared/index.ts (67%) rename apps/{web => core}/src/types/types.d.ts (100%) rename apps/{web => core}/src/utils/create-emotion-cache.ts (100%) rename apps/{web => core}/src/utils/filter.ts (100%) rename apps/{web => core}/src/utils/index.ts (100%) rename apps/{web => core}/src/utils/string2color.ts (100%) rename apps/{web => core}/src/utils/toast.ts (100%) rename apps/{web => core}/tsconfig.json (71%) create mode 100644 apps/core/tsconfig.node.json rename apps/{web/tsconfig.node.json => core/tsconfig.server.json} (90%) delete mode 100644 apps/web/.env.local.template delete mode 100644 apps/web/.eslintrc delete mode 100644 apps/web/README.md delete mode 100644 apps/web/next-env.d.ts delete mode 100644 apps/web/next.config.mjs delete mode 100644 apps/web/preset.config.mjs delete mode 100644 apps/web/scripts/git-info.mjs delete mode 100644 apps/web/sentry.client.config.ts delete mode 100644 apps/web/sentry.edge.config.ts delete mode 100644 apps/web/sentry.properties delete mode 100644 apps/web/sentry.server.config.ts delete mode 100644 apps/web/server.mts delete mode 100644 apps/web/src/atoms/history.ts delete mode 100644 apps/web/src/bootstrap/index.ts delete mode 100644 apps/web/src/components/blocksuite/workspace-header/header-right-items/edit-page.tsx delete mode 100644 apps/web/src/components/blocksuite/workspace-header/header-right-items/share-menu.tsx delete mode 100644 apps/web/src/components/pure/quick-search-modal/published-results.tsx delete mode 100644 apps/web/src/hooks/__tests__/__snapshots__/index.spec.tsx.snap delete mode 100644 apps/web/src/hooks/__tests__/index.spec.tsx delete mode 100644 apps/web/src/hooks/__tests__/use-router-helper.spec.ts delete mode 100644 apps/web/src/hooks/use-router-helper.ts delete mode 100644 apps/web/src/hooks/use-router-title.ts delete mode 100644 apps/web/src/layouts/public-workspace-layout.tsx delete mode 100644 apps/web/src/pages/_app.tsx delete mode 100644 apps/web/src/pages/_debug/README.md delete mode 100644 apps/web/src/pages/_debug/init-page.dev.tsx delete mode 100644 apps/web/src/pages/_debug/migration.tsx delete mode 100644 apps/web/src/pages/_document.tsx delete mode 100644 apps/web/src/pages/_error.tsx delete mode 100644 apps/web/src/pages/index.tsx delete mode 100644 apps/web/src/pages/workspace/[workspaceId]/all.tsx delete mode 100644 apps/web/src/pages/workspace/[workspaceId]/shared.tsx delete mode 100644 apps/web/src/pages/workspace/[workspaceId]/trash.tsx create mode 100755 packages/cli/src/bin/build-core.mjs create mode 100644 packages/cli/src/bin/build-core.ts rename packages/cli/src/{dev.mjs => bin/dev-core.mjs} (83%) create mode 100644 packages/cli/src/bin/dev-core.ts create mode 100644 packages/cli/src/config/index.ts delete mode 100755 packages/cli/src/dev.ts create mode 100644 packages/cli/tsconfig.json delete mode 100644 scripts/vitest/next-config-mock.ts delete mode 100644 tests/affine-local/e2e/debug-init-page.spec.ts delete mode 100644 tests/unit/compare-config.spec.ts delete mode 100644 tests/unit/tsconfig.json diff --git a/.codesandbox/task.json b/.codesandbox/task.json index a90d7adb8..5ae39af70 100644 --- a/.codesandbox/task.json +++ b/.codesandbox/task.json @@ -10,7 +10,7 @@ "tasks": { "start-web": { "name": "Start Web", - "command": "yarn nx dev @affine/web --port 8080", + "command": "yarn dev-core", "runAtStart": true, "preview": { "port": 8080 diff --git a/.github/deployment/front/Dockerfile b/.github/deployment/front/Dockerfile index aa4c6f177..c35b031e0 100644 --- a/.github/deployment/front/Dockerfile +++ b/.github/deployment/front/Dockerfile @@ -1,6 +1,6 @@ FROM openresty/openresty:1.21.4.1-0-buster WORKDIR /app -COPY ./apps/web/out ./dist +COPY ./apps/core/dist ./dist COPY ./.github/deployment/front/nginx.conf /usr/local/openresty/nginx/conf/nginx.conf COPY ./.github/deployment/front/affine.nginx.conf /etc/nginx/conf.d/affine.nginx.conf diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 86583b53f..b4f6b5e7a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -101,8 +101,8 @@ jobs: path: ./apps/storybook/storybook-static if-no-files-found: error - build-web: - name: Build @affine/web + build-core: + name: Build @affine/core runs-on: ubuntu-latest environment: development @@ -110,13 +110,13 @@ jobs: - uses: actions/checkout@v3 - name: Setup Node.js uses: ./.github/actions/setup-node - - name: Build Web - run: yarn nx build @affine/web - - name: Upload artifact + - name: Build Core + run: yarn nx build @affine/core + - name: Upload core artifact uses: actions/upload-artifact@v3 with: - name: next-js-static - path: ./apps/web/out + name: core + path: ./apps/core/dist if-no-files-found: error server-test: @@ -215,7 +215,7 @@ jobs: matrix: shard: [1, 2, 3, 4, 5] environment: development - needs: build-web + needs: build-core steps: - uses: actions/checkout@v3 @@ -224,11 +224,11 @@ jobs: with: playwright-install: true electron-install: false - - name: Download artifact + - name: Download core artifact uses: actions/download-artifact@v3 with: - name: next-js-static - path: ./apps/web/out + name: core + path: ./apps/core/dist - name: Run playwright tests run: yarn e2e --forbid-only --shard=${{ matrix.shard }}/${{ strategy.job-total }} @@ -260,7 +260,7 @@ jobs: name: E2E Migration Test runs-on: ubuntu-latest environment: development - needs: [build-web] + needs: build-core steps: - uses: actions/checkout@v3 @@ -270,11 +270,11 @@ jobs: playwright-install: true electron-install: false - - name: Download next static + - name: Download core artifact uses: actions/download-artifact@v3 with: - name: next-js-static - path: ./apps/web/out + name: core + path: ./apps/core/dist - name: Unzip run: yarn unzip @@ -333,7 +333,7 @@ jobs: target: x86_64-pc-windows-msvc, test: true, } - needs: [build-web] + needs: build-core steps: - uses: actions/checkout@v3 - name: Setup Node.js @@ -353,10 +353,10 @@ jobs: env: NATIVE_TEST: 'true' - - name: Download static resource artifact + - name: Download core artifact uses: actions/download-artifact@v3 with: - name: next-js-static + name: core path: apps/electron/resources/web-static - name: Build Plugins @@ -443,11 +443,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Download next static + - name: Download core artifact uses: actions/download-artifact@v3 with: - name: next-js-static - path: ./apps/web/out + name: core + path: ./apps/core/dist - name: Download server dist uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 79710173d..0a08c15bf 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -62,10 +62,10 @@ jobs: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} RELEASE_VERSION: ${{ needs.set-build-version.outputs.version }} - - name: Upload Artifact (web-static) + - name: Upload core artifact uses: actions/upload-artifact@v3 with: - name: before-make-web-static + name: core path: apps/electron/resources/web-static make-distribution: diff --git a/.github/workflows/release-desktop-app.yml b/.github/workflows/release-desktop-app.yml index 866a0ee80..4311fb1b9 100644 --- a/.github/workflows/release-desktop-app.yml +++ b/.github/workflows/release-desktop-app.yml @@ -66,10 +66,10 @@ jobs: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} RELEASE_VERSION: ${{ github.event.inputs.version || steps.get-canary-version.outputs.RELEASE_VERSION }} - - name: Upload Artifact (web-static) + - name: Upload core artifact uses: actions/upload-artifact@v3 with: - name: before-make-web-static + name: core path: apps/electron/resources/web-static make-distribution: @@ -120,7 +120,7 @@ jobs: nx_token: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} - uses: actions/download-artifact@v3 with: - name: before-make-web-static + name: core path: apps/electron/resources/web-static - name: Build Plugins diff --git a/.gitignore b/.gitignore index 58007be8c..3fb3b199d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ /out-tsc .nyc_output .coverage +.swc # dependencies node_modules diff --git a/apps/core/.webpack/cache-group.ts b/apps/core/.webpack/cache-group.ts new file mode 100644 index 000000000..dfca9b2b6 --- /dev/null +++ b/apps/core/.webpack/cache-group.ts @@ -0,0 +1,84 @@ +import { hash } from './utils.js'; + +function testPackageName(regexp: RegExp): (module: any) => boolean { + return (module: any) => + module.nameForCondition && regexp.test(module.nameForCondition()); +} + +export const productionCacheGroups = { + asyncVendor: { + test: /[\\/]node_modules[\\/]/, + name(module: any) { + // https://hackernoon.com/the-100-correct-way-to-split-your-chunks-with-webpack-f8a9df5b7758 + const name = + module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)?.[1] ?? + 'unknown'; + return `npm-async-${hash(name)}`; + }, + priority: Number.MAX_SAFE_INTEGER, + chunks: 'async' as const, + }, + mui: { + name: `npm-mui`, + test: testPackageName(/[\\/]node_modules[\\/](mui|@mui)[\\/]/), + priority: 200, + enforce: true, + }, + blocksuite: { + name: `npm-blocksuite`, + test: testPackageName(/[\\/]node_modules[\\/](@blocksuite)[\\/]/), + priority: 200, + enforce: true, + }, + react: { + name: `npm-react`, + test: testPackageName( + /[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/ + ), + priority: 200, + enforce: true, + }, + jotai: { + name: `npm-jotai`, + test: testPackageName(/[\\/]node_modules[\\/](jotai)[\\/]/), + priority: 200, + enforce: true, + }, + rxjs: { + name: `npm-rxjs`, + test: testPackageName(/[\\/]node_modules[\\/]rxjs[\\/]/), + priority: 200, + enforce: true, + }, + lodash: { + name: `npm-lodash`, + test: testPackageName(/[\\/]node_modules[\\/]lodash[\\/]/), + priority: 200, + enforce: true, + }, + emotion: { + name: `npm-emotion`, + test: testPackageName(/[\\/]node_modules[\\/](@emotion)[\\/]/), + priority: 200, + enforce: true, + }, + vendor: { + name: 'vendor', + test: /[\\/]node_modules[\\/]/, + priority: 190, + enforce: true, + }, + styles: { + name: 'styles', + test: (module: any) => + module.nameForCondition && + /\.css$/.test(module.nameForCondition()) && + !/^javascript/.test(module.type), + chunks: 'all' as const, + minSize: 1, + minChunks: 1, + reuseExistingChunk: true, + priority: 1000, + enforce: true, + }, +}; diff --git a/apps/core/.webpack/config.ts b/apps/core/.webpack/config.ts new file mode 100644 index 000000000..4546194ce --- /dev/null +++ b/apps/core/.webpack/config.ts @@ -0,0 +1,306 @@ +import { join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { createRequire } from 'node:module'; +import HTMLPlugin from 'html-webpack-plugin'; +import type { Configuration as DevServerConfiguration } from 'webpack-dev-server'; +import { PerfseePlugin } from '@perfsee/webpack'; +import { sentryWebpackPlugin } from '@sentry/webpack-plugin'; + +import CopyPlugin from 'copy-webpack-plugin'; +import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'; +import TerserPlugin from 'terser-webpack-plugin'; +import webpack from 'webpack'; +import MiniCssExtractPlugin from 'mini-css-extract-plugin'; + +import { productionCacheGroups } from './cache-group.js'; +import type { BuildFlags } from '@affine/cli/config'; +import { projectRoot } from '@affine/cli/config'; +import { VanillaExtractPlugin } from '@vanilla-extract/webpack-plugin'; +import { computeCacheKey } from './utils.js'; +import type { RuntimeConfig } from '@affine/env/global'; + +const IN_CI = !!process.env.CI; + +export const rootPath = fileURLToPath(new URL('..', import.meta.url)); + +const require = createRequire(rootPath); + +const OptimizeOptionOptions: ( + buildFlags: BuildFlags +) => webpack.Configuration['optimization'] = buildFlags => ({ + minimize: buildFlags.mode === 'production', + minimizer: [ + new TerserPlugin({ + minify: TerserPlugin.swcMinify, + parallel: true, + extractComments: true, + terserOptions: { + ecma: 2020, + compress: { + unused: true, + }, + mangle: true, + }, + }), + ], + removeEmptyChunks: true, + providedExports: true, + usedExports: true, + sideEffects: true, + removeAvailableModules: true, + runtimeChunk: { + name: 'runtime', + }, + splitChunks: { + chunks: 'all', + minSize: 1, + minChunks: 1, + maxInitialRequests: Number.MAX_SAFE_INTEGER, + maxAsyncRequests: Number.MAX_SAFE_INTEGER, + cacheGroups: + buildFlags.mode === 'production' + ? productionCacheGroups + : { + default: false, + vendors: false, + }, + }, +}); + +export const createConfiguration: ( + buildFlags: BuildFlags, + runtimeConfig: RuntimeConfig +) => webpack.Configuration = (buildFlags, runtimeConfig) => { + let publicPath = process.env.PUBLIC_PATH ?? '/'; + + const cacheKey = computeCacheKey(buildFlags); + + const config = { + name: 'affine', + // to set a correct base path for the source map + context: projectRoot, + output: { + environment: { + module: true, + dynamicImport: true, + }, + filename: 'js/[name].js', + // In some cases webpack will emit files starts with "_" which is reserved in web extension. + chunkFilename: 'js/chunk.[name].js', + assetModuleFilename: 'assets/[hash][ext][query]', + devtoolModuleFilenameTemplate: 'webpack://[namespace]/[resource-path]', + hotUpdateChunkFilename: 'hot/[id].[fullhash].js', + hotUpdateMainFilename: 'hot/[runtime].[fullhash].json', + path: join(rootPath, 'dist'), + clean: buildFlags.mode === 'production', + globalObject: 'globalThis', + publicPath, + }, + target: ['web', 'es2022'], + + mode: buildFlags.mode, + + devtool: + buildFlags.mode === 'production' + ? buildFlags.distribution === 'desktop' + ? 'inline-source-map' + : 'hidden-nosources-source-map' + : 'eval-cheap-module-source-map', + + resolve: { + extensionAlias: { + '.js': ['.js', '.tsx', '.ts'], + '.mjs': ['.mjs', '.mts'], + }, + extensions: ['.js', '.ts', '.tsx'], + }, + + cache: { + type: 'filesystem', + buildDependencies: { + config: [fileURLToPath(import.meta.url)], + }, + version: cacheKey, + }, + + module: { + parser: { + javascript: { + // Treat as missing export as error + strictExportPresence: true, + }, + }, + rules: [ + { + test: /\.m?js?$/, + resolve: { + fullySpecified: false, + }, + }, + { + oneOf: [ + { + test: /\.tsx?$/, + // Compile all ts files in the workspace + include: resolve(rootPath, '..', '..'), + loader: require.resolve('swc-loader'), + options: { + // https://swc.rs/docs/configuring-swc/ + jsc: { + preserveAllComments: true, + parser: { + syntax: 'typescript', + dynamicImport: true, + topLevelAwait: false, + tsx: true, + }, + target: 'es2022', + externalHelpers: true, + transform: { + react: { + runtime: 'automatic', + refresh: buildFlags.mode === 'development' && { + refreshReg: '$RefreshReg$', + refreshSig: '$RefreshSig$', + emitFullSignatures: true, + }, + }, + }, + experimental: { + keepImportAssertions: true, + plugins: [ + buildFlags.coverage && [ + 'swc-plugin-coverage-instrument', + {}, + ], + ].filter(Boolean), + }, + }, + }, + }, + { + test: /\.svg$/, + use: [ + 'thread-loader', + { + loader: '@svgr/webpack', + options: { + icon: true, + }, + }, + ], + exclude: [/node_modules/], + }, + { + test: /\.(png|jpg|gif|svg|webp)$/, + type: 'asset/resource', + }, + { + test: /\.(ttf|eot|woff|woff2)$/i, + type: 'asset/resource', + }, + { + test: /\.txt$/, + loader: 'raw-loader', + }, + { + test: /\.css$/, + use: [ + MiniCssExtractPlugin.loader, + { + loader: 'css-loader', + options: { + url: false, + sourceMap: false, + modules: false, + import: true, + importLoaders: 1, + }, + }, + { + loader: 'postcss-loader', + options: { + postcssOptions: { + config: resolve( + rootPath, + '.webpack', + 'postcss.config.cjs' + ), + }, + }, + }, + ], + }, + ], + }, + ], + }, + + plugins: [ + ...(IN_CI ? [] : [new webpack.ProgressPlugin({ percentBy: 'entries' })]), + ...(buildFlags.mode === 'development' + ? [new ReactRefreshWebpackPlugin({ overlay: false, esModule: true })] + : []), + new HTMLPlugin({ + template: join(rootPath, '.webpack', 'template.html'), + inject: 'body', + scriptLoading: 'defer', + minify: false, + chunks: ['index'], + filename: 'index.html', + }), + new MiniCssExtractPlugin({ + filename: `[name].[chunkhash:8].css`, + ignoreOrder: true, + }), + new VanillaExtractPlugin(), + new webpack.DefinePlugin({ + 'process.env': JSON.stringify({}), + runtimeConfig: JSON.stringify(runtimeConfig), + }), + new CopyPlugin({ + patterns: [ + { from: resolve(rootPath, 'public'), to: resolve(rootPath, 'dist') }, + ], + }), + ], + + optimization: OptimizeOptionOptions(buildFlags), + + devServer: { + hot: 'only', + liveReload: false, + client: undefined, + historyApiFallback: true, + static: { + directory: resolve(rootPath, 'public'), + publicPath: '/', + }, + } as DevServerConfiguration, + } satisfies webpack.Configuration; + + if (buildFlags.mode === 'production' && process.env.PERFSEE_TOKEN) { + config.devtool = 'hidden-nosources-source-map'; + config.plugins.push( + new PerfseePlugin({ + project: 'affine-toeverything', + }) + ); + } + + if ( + process.env.SENTRY_AUTH_TOKEN && + process.env.SENTRY_ORG && + process.env.SENTRY_PROJECT + ) { + config.plugins.push( + sentryWebpackPlugin({ + org: process.env.SENTRY_ORG, + project: process.env.SENTRY_PROJECT, + authToken: process.env.SENTRY_AUTH_TOKEN, + }) + ); + } + + return config; +}; diff --git a/apps/core/.webpack/postcss.config.cjs b/apps/core/.webpack/postcss.config.cjs new file mode 100644 index 000000000..f27102db6 --- /dev/null +++ b/apps/core/.webpack/postcss.config.cjs @@ -0,0 +1,20 @@ +const cssnano = require('cssnano'); + +module.exports = function (context) { + const plugins = [ + cssnano({ + preset: [ + 'default', + { + convertValues: false, + }, + ], + }), + ]; + + return { + from: context.from, + plugins, + to: context.to, + }; +}; diff --git a/apps/core/.webpack/runtime-config.ts b/apps/core/.webpack/runtime-config.ts new file mode 100644 index 000000000..acaee1b2e --- /dev/null +++ b/apps/core/.webpack/runtime-config.ts @@ -0,0 +1,115 @@ +import type { BlockSuiteFeatureFlags, RuntimeConfig } from '@affine/env/global'; +import type { BuildFlags } from '@affine/cli/config'; +import { createRequire } from 'node:module'; + +const require = createRequire(import.meta.url); +const packageJson = require('../package.json'); + +const editorFlags: BlockSuiteFeatureFlags = { + enable_database: true, + enable_slash_menu: true, + enable_edgeless_toolbar: true, + enable_block_hub: true, + enable_drag_handle: true, + enable_surface: true, + enable_linked_page: true, + enable_bookmark_operation: false, +}; + +export function getRuntimeConfig(buildFlags: BuildFlags): RuntimeConfig { + const buildPreset: Record = { + stable: { + enablePlugin: false, + enableTestProperties: false, + enableBroadcastChannelProvider: true, + enableDebugPage: true, + changelogUrl: 'https://affine.pro/blog/what-is-new-affine-0717', + imageProxyUrl: 'https://workers.toeverything.workers.dev/proxy/image', + enablePreloading: true, + enableNewSettingModal: true, + enableNewSettingUnstableApi: false, + enableSQLiteProvider: true, + enableMoveDatabase: false, + enableNotificationCenter: false, + enableCloud: false, + serverAPI: 'https://localhost:3010', + editorFlags, + appVersion: packageJson.version, + editorVersion: packageJson.dependencies['@blocksuite/editor'], + }, + // canary will be aggressive and enable all features + canary: { + enablePlugin: true, + enableTestProperties: true, + enableBroadcastChannelProvider: true, + enableDebugPage: true, + changelogUrl: 'https://affine.pro/blog/what-is-new-affine-0717', + imageProxyUrl: 'https://workers.toeverything.workers.dev/proxy/image', + enablePreloading: true, + enableNewSettingModal: true, + enableNewSettingUnstableApi: false, + enableSQLiteProvider: true, + enableMoveDatabase: false, + enableNotificationCenter: true, + enableCloud: false, + serverAPI: 'https://localhost:3010', + editorFlags, + appVersion: packageJson.version, + editorVersion: packageJson.dependencies['@blocksuite/editor'], + }, + }; + + // beta and internal versions are the same as stable + buildPreset.beta = buildPreset.stable; + buildPreset.internal = buildPreset.stable; + + const currentBuild = buildFlags.channel; + + if (!(currentBuild in buildPreset)) { + throw new Error(`BUILD_TYPE ${currentBuild} is not supported`); + } + + const currentBuildPreset = buildPreset[currentBuild]; + + const environmentPreset = { + enablePlugin: process.env.ENABLE_PLUGIN + ? process.env.ENABLE_PLUGIN === 'true' + : currentBuildPreset.enablePlugin, + enableTestProperties: process.env.ENABLE_TEST_PROPERTIES + ? process.env.ENABLE_TEST_PROPERTIES === 'true' + : currentBuildPreset.enableTestProperties, + enableBroadcastChannelProvider: process.env.ENABLE_BC_PROVIDER + ? process.env.ENABLE_BC_PROVIDER !== 'false' + : currentBuildPreset.enableBroadcastChannelProvider, + changelogUrl: process.env.CHANGELOG_URL ?? currentBuildPreset.changelogUrl, + enablePreloading: process.env.ENABLE_PRELOADING + ? process.env.ENABLE_PRELOADING === 'true' + : currentBuildPreset.enablePreloading, + enableNewSettingModal: process.env.ENABLE_NEW_SETTING_MODAL + ? process.env.ENABLE_NEW_SETTING_MODAL === 'true' + : currentBuildPreset.enableNewSettingModal, + enableSQLiteProvider: process.env.ENABLE_SQLITE_PROVIDER + ? process.env.ENABLE_SQLITE_PROVIDER === 'true' + : currentBuildPreset.enableSQLiteProvider, + enableNewSettingUnstableApi: process.env.ENABLE_NEW_SETTING_UNSTABLE_API + ? process.env.ENABLE_NEW_SETTING_UNSTABLE_API === 'true' + : currentBuildPreset.enableNewSettingUnstableApi, + enableNotificationCenter: process.env.ENABLE_NOTIFICATION_CENTER + ? process.env.ENABLE_NOTIFICATION_CENTER === 'true' + : currentBuildPreset.enableNotificationCenter, + enableCloud: process.env.ENABLE_CLOUD + ? process.env.ENABLE_CLOUD === 'true' + : currentBuildPreset.enableCloud, + enableMoveDatabase: process.env.ENABLE_MOVE_DATABASE + ? process.env.ENABLE_MOVE_DATABASE === 'true' + : currentBuildPreset.enableMoveDatabase, + }; + + return { + ...currentBuildPreset, + // environment preset will overwrite current build preset + // this environment variable is for debug proposes only + // do not put them into CI + ...(process.env.CI ? {} : environmentPreset), + }; +} diff --git a/apps/core/.webpack/template.html b/apps/core/.webpack/template.html new file mode 100644 index 000000000..b7045d454 --- /dev/null +++ b/apps/core/.webpack/template.html @@ -0,0 +1,45 @@ + + + + + + AFFiNE + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/apps/core/.webpack/utils.ts b/apps/core/.webpack/utils.ts new file mode 100644 index 000000000..c3d6069a0 --- /dev/null +++ b/apps/core/.webpack/utils.ts @@ -0,0 +1,18 @@ +import { createHash } from 'node:crypto'; +import type { BuildFlags } from '@affine/cli/config'; + +export function hash(content: string): string { + const hash = createHash('sha512'); + hash.update(content); + const pkgHash = hash.digest('hex'); + return pkgHash.substring(0, 8); +} + +export function computeCacheKey(buildFlags: BuildFlags) { + return [ + '1', + 'node' + process.version, + buildFlags.mode, + buildFlags.distribution, + ].join('-'); +} diff --git a/apps/core/.webpack/webpack.config.ts b/apps/core/.webpack/webpack.config.ts new file mode 100644 index 000000000..5e43fb2c6 --- /dev/null +++ b/apps/core/.webpack/webpack.config.ts @@ -0,0 +1,23 @@ +import { createConfiguration, rootPath } from './config.js'; +import { merge } from 'webpack-merge'; +import { resolve } from 'node:path'; +import type { BuildFlags } from '@affine/cli/config'; +import { getRuntimeConfig } from './runtime-config.js'; + +export default async function (cli_env: any, _: any) { + const flags: BuildFlags = JSON.parse( + Buffer.from(cli_env.flags, 'hex').toString('utf-8') + ); + console.log('build flags', flags); + const runtimeConfig = getRuntimeConfig(flags); + console.log('runtime config', runtimeConfig); + const config = createConfiguration(flags, runtimeConfig); + return merge(config, { + entry: { + index: { + asyncChunks: true, + import: resolve(rootPath, 'src/index.tsx'), + }, + }, + }); +} diff --git a/apps/web/package.json b/apps/core/package.json similarity index 60% rename from apps/web/package.json rename to apps/core/package.json index 233b5f613..6efc67262 100644 --- a/apps/web/package.json +++ b/apps/core/package.json @@ -1,17 +1,16 @@ { - "name": "@affine/web", + "name": "@affine/core", + "type": "module", "private": true, "version": "0.7.0-canary.47", "scripts": { - "dev": "next dev", - "build": "next build && next export", - "start": "NODE_ENV=development next start", - "static-server": "ts-node-esm server.mts" + "build": "yarn -T run build-core", + "dev": "yarn -T run dev-core", + "static-server": "ts-node-esm ./server.mts" }, "dependencies": { "@affine-test/fixtures": "workspace:*", "@affine/component": "workspace:*", - "@affine/copilot": "workspace:*", "@affine/debug": "workspace:*", "@affine/env": "workspace:*", "@affine/graphql": "workspace:*", @@ -34,23 +33,23 @@ "@emotion/styled": "^11.11.0", "@mui/material": "^5.13.6", "@react-hookz/web": "^23.1.0", - "@sentry/nextjs": "^7.57.0", - "@toeverything/hooks": "workspace:*", - "@toeverything/infra": "workspace:*", - "@toeverything/plugin-infra": "workspace:*", "async-call-rpc": "^6.3.1", "cmdk": "^0.2.0", "css-spring": "^4.1.0", + "cssnano": "^6.0.1", "graphql": "^16.7.1", "jotai": "^2.2.2", "jotai-devtools": "^0.6.0", "lit": "^2.7.5", "lottie-web": "^5.12.2", + "mini-css-extract-plugin": "^2.7.6", "next-themes": "^0.2.1", + "postcss-loader": "^7.3.3", "react": "18.2.0", "react-dom": "18.2.0", - "react-is": "^18.2.0", + "react-is": "18.2.0", "react-resizable-panels": "^0.0.53", + "react-router-dom": "^6.14.1", "rxjs": "^7.8.1", "swr": "^2.1.5", "y-protocols": "^1.0.5", @@ -59,30 +58,23 @@ }, "devDependencies": { "@perfsee/webpack": "^1.8.2", - "@redux-devtools/extension": "^3.2.5", - "@rich-data/viewer": "^2.15.6", - "@sentry/webpack-plugin": "^1.20.1", - "@swc-jotai/debug-label": "^0.0.10", - "@swc-jotai/react-refresh": "^0.0.8", - "@types/react": "^18.2.14", - "@types/react-dom": "^18.2.6", + "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10", + "@sentry/webpack-plugin": "^2.4.0", + "@svgr/webpack": "^8.0.1", + "@swc/core": "^1.3.70", "@types/webpack-env": "^1.18.1", - "@vanilla-extract/css": "^1.12.0", - "@vanilla-extract/next-plugin": "=2.1.2", - "dotenv": "^16.3.1", - "eslint": "^8.44.0", - "eslint-config-next": "^13.4.7", - "eslint-plugin-unicorn": "^47.0.0", + "copy-webpack-plugin": "^11.0.0", + "css-loader": "^6.8.1", "express": "^4.18.2", - "next": "=13.4.2", - "next-debug-local": "^0.1.5", - "next-router-mock": "^0.9.7", + "html-webpack-plugin": "^5.5.3", "raw-loader": "^4.0.2", - "redux": "^4.2.1", - "swc-plugin-coverage-instrument": "^0.0.18", + "swc-loader": "^0.2.3", + "swc-plugin-coverage-instrument": "^0.0.19", + "thread-loader": "^4.0.2", "ts-node": "^10.9.1", - "typescript": "^5.1.6", - "webpack": "^5.88.1" - }, - "stableVersion": "0.0.0" + "webpack": "^5.88.1", + "webpack-cli": "^5.1.4", + "webpack-dev-server": "^4.15.1", + "webpack-merge": "^5.9.0" + } } diff --git a/apps/web/project.json b/apps/core/project.json similarity index 74% rename from apps/web/project.json rename to apps/core/project.json index e4235b369..ee5b19d34 100644 --- a/apps/web/project.json +++ b/apps/core/project.json @@ -1,9 +1,9 @@ { - "name": "@affine/web", + "name": "@affine/core", "$schema": "../../node_modules/nx/schemas/project-schema.json", "projectType": "application", - "root": "apps/web", - "sourceRoot": "apps/web/src", + "root": "apps/core", + "sourceRoot": "apps/core/src", "targets": { "build": { "executor": "nx:run-script", @@ -12,26 +12,29 @@ "{projectRoot}/**/*", "{workspaceRoot}/packages/component/src/**/*", "{workspaceRoot}/packages/debug/src/**/*", - "{workspaceRoot}/packages/debug/graphql/**/*", + "{workspaceRoot}/packages/graphql/src/**/*", "{workspaceRoot}/packages/hooks/src/**/*", "{workspaceRoot}/packages/jotai/src/**/*", "{workspaceRoot}/packages/templates/src/**/*", "{workspaceRoot}/packages/workspace/src/**/*", { "env": "BUILD_TYPE" + }, + { + "env": "PERFSEE_TOKEN" } ], "options": { "script": "build" }, - "outputs": ["{projectRoot}/out"] + "outputs": ["{projectRoot}/dist"] }, "dev": { "executor": "nx:run-script", "options": { "script": "dev" }, - "outputs": ["{projectRoot}/.next"] + "outputs": ["{projectRoot}/dist"] } } } diff --git a/apps/web/public/.gitignore b/apps/core/public/.gitignore similarity index 100% rename from apps/web/public/.gitignore rename to apps/core/public/.gitignore diff --git a/apps/web/public/apple-touch-icon.png b/apps/core/public/apple-touch-icon.png similarity index 100% rename from apps/web/public/apple-touch-icon.png rename to apps/core/public/apple-touch-icon.png diff --git a/apps/web/public/editingVideo.mp4 b/apps/core/public/editingVideo.mp4 similarity index 100% rename from apps/web/public/editingVideo.mp4 rename to apps/core/public/editingVideo.mp4 diff --git a/apps/web/public/favicon-144.png b/apps/core/public/favicon-144.png similarity index 100% rename from apps/web/public/favicon-144.png rename to apps/core/public/favicon-144.png diff --git a/apps/web/public/favicon-192.png b/apps/core/public/favicon-192.png similarity index 100% rename from apps/web/public/favicon-192.png rename to apps/core/public/favicon-192.png diff --git a/apps/web/public/favicon-36.png b/apps/core/public/favicon-36.png similarity index 100% rename from apps/web/public/favicon-36.png rename to apps/core/public/favicon-36.png diff --git a/apps/web/public/favicon-48.png b/apps/core/public/favicon-48.png similarity index 100% rename from apps/web/public/favicon-48.png rename to apps/core/public/favicon-48.png diff --git a/apps/web/public/favicon-72.png b/apps/core/public/favicon-72.png similarity index 100% rename from apps/web/public/favicon-72.png rename to apps/core/public/favicon-72.png diff --git a/apps/web/public/favicon-96.png b/apps/core/public/favicon-96.png similarity index 100% rename from apps/web/public/favicon-96.png rename to apps/core/public/favicon-96.png diff --git a/apps/web/public/favicon.ico b/apps/core/public/favicon.ico similarity index 100% rename from apps/web/public/favicon.ico rename to apps/core/public/favicon.ico diff --git a/apps/web/public/fonts/inter/Inter-VariableFont_slnt,wght.ttf b/apps/core/public/fonts/inter/Inter-VariableFont_slnt,wght.ttf similarity index 100% rename from apps/web/public/fonts/inter/Inter-VariableFont_slnt,wght.ttf rename to apps/core/public/fonts/inter/Inter-VariableFont_slnt,wght.ttf diff --git a/apps/web/public/fonts/inter/OFL.txt b/apps/core/public/fonts/inter/OFL.txt similarity index 100% rename from apps/web/public/fonts/inter/OFL.txt rename to apps/core/public/fonts/inter/OFL.txt diff --git a/apps/web/public/fonts/kalam/Kalam-Bold.ttf b/apps/core/public/fonts/kalam/Kalam-Bold.ttf similarity index 100% rename from apps/web/public/fonts/kalam/Kalam-Bold.ttf rename to apps/core/public/fonts/kalam/Kalam-Bold.ttf diff --git a/apps/web/public/fonts/kalam/Kalam-Light.ttf b/apps/core/public/fonts/kalam/Kalam-Light.ttf similarity index 100% rename from apps/web/public/fonts/kalam/Kalam-Light.ttf rename to apps/core/public/fonts/kalam/Kalam-Light.ttf diff --git a/apps/web/public/fonts/kalam/Kalam-Regular.ttf b/apps/core/public/fonts/kalam/Kalam-Regular.ttf similarity index 100% rename from apps/web/public/fonts/kalam/Kalam-Regular.ttf rename to apps/core/public/fonts/kalam/Kalam-Regular.ttf diff --git a/apps/web/public/fonts/kalam/OFL.txt b/apps/core/public/fonts/kalam/OFL.txt similarity index 100% rename from apps/web/public/fonts/kalam/OFL.txt rename to apps/core/public/fonts/kalam/OFL.txt diff --git a/apps/web/public/fonts/source-code-pro/OFL.txt b/apps/core/public/fonts/source-code-pro/OFL.txt similarity index 100% rename from apps/web/public/fonts/source-code-pro/OFL.txt rename to apps/core/public/fonts/source-code-pro/OFL.txt diff --git a/apps/web/public/fonts/source-code-pro/SourceCodePro-Italic-VariableFont_wght.ttf b/apps/core/public/fonts/source-code-pro/SourceCodePro-Italic-VariableFont_wght.ttf similarity index 100% rename from apps/web/public/fonts/source-code-pro/SourceCodePro-Italic-VariableFont_wght.ttf rename to apps/core/public/fonts/source-code-pro/SourceCodePro-Italic-VariableFont_wght.ttf diff --git a/apps/web/public/fonts/source-code-pro/SourceCodePro-VariableFont_wght.ttf b/apps/core/public/fonts/source-code-pro/SourceCodePro-VariableFont_wght.ttf similarity index 100% rename from apps/web/public/fonts/source-code-pro/SourceCodePro-VariableFont_wght.ttf rename to apps/core/public/fonts/source-code-pro/SourceCodePro-VariableFont_wght.ttf diff --git a/apps/web/public/fonts/source-serif-4/OFL.txt b/apps/core/public/fonts/source-serif-4/OFL.txt similarity index 100% rename from apps/web/public/fonts/source-serif-4/OFL.txt rename to apps/core/public/fonts/source-serif-4/OFL.txt diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-Bold.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-Bold.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-Bold.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-Bold.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-BoldItalic.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-BoldItalic.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-BoldItalic.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-BoldItalic.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-Italic-VariableFont_opsz,wght.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-Italic-VariableFont_opsz,wght.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-Italic-VariableFont_opsz,wght.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-Italic-VariableFont_opsz,wght.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-Italic.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-Italic.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-Italic.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-Italic.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-Light.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-Light.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-Light.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-Light.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-LightItalic.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-LightItalic.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-LightItalic.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-LightItalic.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-Medium.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-Medium.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-Medium.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-Medium.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-MediumItalic.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-MediumItalic.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-MediumItalic.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-MediumItalic.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-Regular.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-Regular.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-Regular.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-Regular.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-SemiBold.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-SemiBold.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-SemiBold.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-SemiBold.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-SemiBoldItalic.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-SemiBoldItalic.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-SemiBoldItalic.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-SemiBoldItalic.ttf diff --git a/apps/web/public/fonts/source-serif-4/SourceSerif4-VariableFont_opsz,wght.ttf b/apps/core/public/fonts/source-serif-4/SourceSerif4-VariableFont_opsz,wght.ttf similarity index 100% rename from apps/web/public/fonts/source-serif-4/SourceSerif4-VariableFont_opsz,wght.ttf rename to apps/core/public/fonts/source-serif-4/SourceSerif4-VariableFont_opsz,wght.ttf diff --git a/apps/web/public/fonts/space-mono/OFL.txt b/apps/core/public/fonts/space-mono/OFL.txt similarity index 100% rename from apps/web/public/fonts/space-mono/OFL.txt rename to apps/core/public/fonts/space-mono/OFL.txt diff --git a/apps/web/public/fonts/space-mono/SpaceMono-Bold.ttf b/apps/core/public/fonts/space-mono/SpaceMono-Bold.ttf similarity index 100% rename from apps/web/public/fonts/space-mono/SpaceMono-Bold.ttf rename to apps/core/public/fonts/space-mono/SpaceMono-Bold.ttf diff --git a/apps/web/public/fonts/space-mono/SpaceMono-BoldItalic.ttf b/apps/core/public/fonts/space-mono/SpaceMono-BoldItalic.ttf similarity index 100% rename from apps/web/public/fonts/space-mono/SpaceMono-BoldItalic.ttf rename to apps/core/public/fonts/space-mono/SpaceMono-BoldItalic.ttf diff --git a/apps/web/public/fonts/space-mono/SpaceMono-Italic.ttf b/apps/core/public/fonts/space-mono/SpaceMono-Italic.ttf similarity index 100% rename from apps/web/public/fonts/space-mono/SpaceMono-Italic.ttf rename to apps/core/public/fonts/space-mono/SpaceMono-Italic.ttf diff --git a/apps/web/public/fonts/space-mono/SpaceMono-Regular.ttf b/apps/core/public/fonts/space-mono/SpaceMono-Regular.ttf similarity index 100% rename from apps/web/public/fonts/space-mono/SpaceMono-Regular.ttf rename to apps/core/public/fonts/space-mono/SpaceMono-Regular.ttf diff --git a/apps/web/public/imgs/affine-text-logo.png b/apps/core/public/imgs/affine-text-logo.png similarity index 100% rename from apps/web/public/imgs/affine-text-logo.png rename to apps/core/public/imgs/affine-text-logo.png diff --git a/apps/web/public/imgs/invite-error.svg b/apps/core/public/imgs/invite-error.svg similarity index 100% rename from apps/web/public/imgs/invite-error.svg rename to apps/core/public/imgs/invite-error.svg diff --git a/apps/web/public/imgs/invite-success.svg b/apps/core/public/imgs/invite-success.svg similarity index 100% rename from apps/web/public/imgs/invite-success.svg rename to apps/core/public/imgs/invite-success.svg diff --git a/apps/web/public/imgs/no-result.svg b/apps/core/public/imgs/no-result.svg similarity index 100% rename from apps/web/public/imgs/no-result.svg rename to apps/core/public/imgs/no-result.svg diff --git a/apps/web/public/manifest.json b/apps/core/public/manifest.json similarity index 100% rename from apps/web/public/manifest.json rename to apps/core/public/manifest.json diff --git a/apps/web/public/static/047ebf2c9a5c7c9d8521c2ea5e6140ff7732ef9e28a9f944e9bf3ca4.png b/apps/core/public/static/047ebf2c9a5c7c9d8521c2ea5e6140ff7732ef9e28a9f944e9bf3ca4.png similarity index 100% rename from apps/web/public/static/047ebf2c9a5c7c9d8521c2ea5e6140ff7732ef9e28a9f944e9bf3ca4.png rename to apps/core/public/static/047ebf2c9a5c7c9d8521c2ea5e6140ff7732ef9e28a9f944e9bf3ca4.png diff --git a/apps/web/public/static/1326bc48553a572c6756d9ee1b30a0dfdda26222fc2d2c872b14e609.gif b/apps/core/public/static/1326bc48553a572c6756d9ee1b30a0dfdda26222fc2d2c872b14e609.gif similarity index 100% rename from apps/web/public/static/1326bc48553a572c6756d9ee1b30a0dfdda26222fc2d2c872b14e609.gif rename to apps/core/public/static/1326bc48553a572c6756d9ee1b30a0dfdda26222fc2d2c872b14e609.gif diff --git a/apps/web/public/static/27f983d0765289c19d10ee0b51c00c3c7665236a1a82406370d46e0a.gif b/apps/core/public/static/27f983d0765289c19d10ee0b51c00c3c7665236a1a82406370d46e0a.gif similarity index 100% rename from apps/web/public/static/27f983d0765289c19d10ee0b51c00c3c7665236a1a82406370d46e0a.gif rename to apps/core/public/static/27f983d0765289c19d10ee0b51c00c3c7665236a1a82406370d46e0a.gif diff --git a/apps/web/public/static/28516717d63e469cd98729ff46be6595711898bab3dc43302319a987.gif b/apps/core/public/static/28516717d63e469cd98729ff46be6595711898bab3dc43302319a987.gif similarity index 100% rename from apps/web/public/static/28516717d63e469cd98729ff46be6595711898bab3dc43302319a987.gif rename to apps/core/public/static/28516717d63e469cd98729ff46be6595711898bab3dc43302319a987.gif diff --git a/apps/web/public/static/6aa785ee927547ce9dd9d7b43e01eac948337fe57571443e87bc3a60.png b/apps/core/public/static/6aa785ee927547ce9dd9d7b43e01eac948337fe57571443e87bc3a60.png similarity index 100% rename from apps/web/public/static/6aa785ee927547ce9dd9d7b43e01eac948337fe57571443e87bc3a60.png rename to apps/core/public/static/6aa785ee927547ce9dd9d7b43e01eac948337fe57571443e87bc3a60.png diff --git a/apps/web/public/static/9288be57321c8772d04e05dbb69a22742372b3534442607a2d6a9998.gif b/apps/core/public/static/9288be57321c8772d04e05dbb69a22742372b3534442607a2d6a9998.gif similarity index 100% rename from apps/web/public/static/9288be57321c8772d04e05dbb69a22742372b3534442607a2d6a9998.gif rename to apps/core/public/static/9288be57321c8772d04e05dbb69a22742372b3534442607a2d6a9998.gif diff --git a/apps/web/public/static/c820edeeba50006b531883903f5bb0b96bf523c9a6b3ce5868f03db5.gif b/apps/core/public/static/c820edeeba50006b531883903f5bb0b96bf523c9a6b3ce5868f03db5.gif similarity index 100% rename from apps/web/public/static/c820edeeba50006b531883903f5bb0b96bf523c9a6b3ce5868f03db5.gif rename to apps/core/public/static/c820edeeba50006b531883903f5bb0b96bf523c9a6b3ce5868f03db5.gif diff --git a/apps/web/public/static/e93536e1be97e3b5206d43bf0793fdef24e60044d174f0abdefebe08.gif b/apps/core/public/static/e93536e1be97e3b5206d43bf0793fdef24e60044d174f0abdefebe08.gif similarity index 100% rename from apps/web/public/static/e93536e1be97e3b5206d43bf0793fdef24e60044d174f0abdefebe08.gif rename to apps/core/public/static/e93536e1be97e3b5206d43bf0793fdef24e60044d174f0abdefebe08.gif diff --git a/apps/web/public/switchVideo.mp4 b/apps/core/public/switchVideo.mp4 similarity index 100% rename from apps/web/public/switchVideo.mp4 rename to apps/core/public/switchVideo.mp4 diff --git a/apps/core/server.mts b/apps/core/server.mts new file mode 100644 index 000000000..87d328f4f --- /dev/null +++ b/apps/core/server.mts @@ -0,0 +1,15 @@ +// static server for web app +import express from 'express'; +const app = express(); + +const PORT = process.env.PORT || 8080; + +app.use('/', express.static('dist')); + +app.get('/*', (req, res) => { + res.sendFile('index.html', { root: 'dist' }); +}); + +app.listen(PORT, () => { + console.log(`Server is running on port ${PORT}`); +}); diff --git a/apps/web/src/adapters/local/index.tsx b/apps/core/src/adapters/local/index.tsx similarity index 100% rename from apps/web/src/adapters/local/index.tsx rename to apps/core/src/adapters/local/index.tsx diff --git a/apps/web/src/adapters/shared.ts b/apps/core/src/adapters/shared.ts similarity index 100% rename from apps/web/src/adapters/shared.ts rename to apps/core/src/adapters/shared.ts diff --git a/apps/web/src/adapters/workspace.ts b/apps/core/src/adapters/workspace.ts similarity index 100% rename from apps/web/src/adapters/workspace.ts rename to apps/core/src/adapters/workspace.ts diff --git a/apps/core/src/app.tsx b/apps/core/src/app.tsx new file mode 100644 index 000000000..bd692d17c --- /dev/null +++ b/apps/core/src/app.tsx @@ -0,0 +1,158 @@ +import '@affine/component/theme/global.css'; +import '@affine/component/theme/theme.css'; + +import { AffineContext } from '@affine/component/context'; +import { WorkspaceFallback } from '@affine/component/workspace'; +import { createI18n, setUpLanguage } from '@affine/i18n'; +import { CacheProvider } from '@emotion/react'; +import type { RouterState } from '@remix-run/router'; +import { + currentPageIdAtom, + currentWorkspaceIdAtom, +} from '@toeverything/plugin-infra/manager'; +import type { PropsWithChildren, ReactElement } from 'react'; +import { lazy, memo, Suspense, useEffect } from 'react'; +import { createBrowserRouter, RouterProvider } from 'react-router-dom'; + +import { historyBaseAtom, MAX_HISTORY } from './atoms/history'; +import createEmotionCache from './utils/create-emotion-cache'; + +const router = createBrowserRouter([ + { + path: '/', + lazy: () => import('./pages/index'), + }, + { + path: '/404', + lazy: () => import('./pages/404'), + }, + { + path: '/workspace/:workspaceId/all', + lazy: () => import('./pages/workspace/all-page'), + }, + { + path: '/workspace/:workspaceId/trash', + lazy: () => import('./pages/workspace/trash-page'), + }, + { + path: '/workspace/:workspaceId/:pageId', + lazy: () => import('./pages/workspace/detail-page'), + }, +]); + +//#region atoms bootstrap + +currentWorkspaceIdAtom.onMount = set => { + const callback = (state: RouterState) => { + const value = state.location.pathname.split('/')[2]; + if (value) { + set(value); + localStorage.setItem('last_workspace_id', value); + } else { + set(null); + } + }; + callback(router.state); + + const unsubscribe = router.subscribe(callback); + return () => { + unsubscribe(); + }; +}; + +currentPageIdAtom.onMount = set => { + const callback = (state: RouterState) => { + const value = state.location.pathname.split('/')[3]; + if (value) { + set(value); + } else { + set(null); + } + }; + callback(router.state); + + const unsubscribe = router.subscribe(callback); + return () => { + unsubscribe(); + }; +}; + +historyBaseAtom.onMount = set => { + const unsubscribe = router.subscribe(state => { + set(prev => { + const url = state.location.pathname; + console.log('push', url, prev.skip, prev.stack.length, prev.current); + if (prev.skip) { + return { + stack: [...prev.stack], + current: prev.current, + skip: false, + }; + } else { + if (prev.current < prev.stack.length - 1) { + const newStack = prev.stack.slice(0, prev.current); + newStack.push(url); + if (newStack.length > MAX_HISTORY) { + newStack.shift(); + } + return { + stack: newStack, + current: newStack.length - 1, + skip: false, + }; + } else { + const newStack = [...prev.stack, url]; + if (newStack.length > MAX_HISTORY) { + newStack.shift(); + } + return { + stack: newStack, + current: newStack.length - 1, + skip: false, + }; + } + } + }); + }); + return () => { + unsubscribe(); + }; +}; +//#endregion + +const i18n = createI18n(); +const cache = createEmotionCache(); + +const DevTools = lazy(() => + import('jotai-devtools').then(m => ({ default: m.DevTools })) +); + +const DebugProvider = ({ children }: PropsWithChildren): ReactElement => { + return ( + <> + {process.env.DEBUG_JOTAI === 'true' && } + {children} + + ); +}; + +export const App = memo(function App() { + useEffect(() => { + document.documentElement.lang = i18n.language; + // todo(himself65): this is a hack, we should use a better way to set the language + setUpLanguage(i18n)?.catch(error => { + console.error(error); + }); + }, []); + return ( + + + + }> + + + + + + ); +}); diff --git a/apps/web/src/atoms/__tests__/atom.spec.ts b/apps/core/src/atoms/__tests__/atom.spec.ts similarity index 100% rename from apps/web/src/atoms/__tests__/atom.spec.ts rename to apps/core/src/atoms/__tests__/atom.spec.ts diff --git a/apps/web/src/atoms/guide.ts b/apps/core/src/atoms/guide.ts similarity index 100% rename from apps/web/src/atoms/guide.ts rename to apps/core/src/atoms/guide.ts diff --git a/apps/core/src/atoms/history.ts b/apps/core/src/atoms/history.ts new file mode 100644 index 000000000..592c72b41 --- /dev/null +++ b/apps/core/src/atoms/history.ts @@ -0,0 +1,52 @@ +import { useAtom } from 'jotai'; +import { atomWithStorage } from 'jotai/utils'; +import { useCallback } from 'react'; +import { useNavigate } from 'react-router-dom'; + +export type History = { + stack: string[]; + current: number; + skip: boolean; +}; + +export const MAX_HISTORY = 50; + +export const historyBaseAtom = atomWithStorage('router-history', { + stack: [], + current: 0, + skip: false, +}); + +export function useHistoryAtom() { + const navigate = useNavigate(); + const [base, setBase] = useAtom(historyBaseAtom); + return [ + base, + useCallback( + (forward: boolean) => { + setBase(prev => { + if (forward) { + const target = Math.min(prev.stack.length - 1, prev.current + 1); + const url = prev.stack[target]; + navigate(url); + return { + ...prev, + current: target, + skip: true, + }; + } else { + const target = Math.max(0, prev.current - 1); + const url = prev.stack[target]; + navigate(url); + return { + ...prev, + current: target, + skip: true, + }; + } + }); + }, + [setBase, navigate] + ), + ] as const; +} diff --git a/apps/web/src/atoms/index.ts b/apps/core/src/atoms/index.ts similarity index 100% rename from apps/web/src/atoms/index.ts rename to apps/core/src/atoms/index.ts diff --git a/apps/web/src/atoms/layout.ts b/apps/core/src/atoms/layout.ts similarity index 100% rename from apps/web/src/atoms/layout.ts rename to apps/core/src/atoms/layout.ts diff --git a/apps/web/src/atoms/mode.ts b/apps/core/src/atoms/mode.ts similarity index 100% rename from apps/web/src/atoms/mode.ts rename to apps/core/src/atoms/mode.ts diff --git a/apps/web/src/atoms/settings.ts b/apps/core/src/atoms/settings.ts similarity index 100% rename from apps/web/src/atoms/settings.ts rename to apps/core/src/atoms/settings.ts diff --git a/apps/web/src/components/__debug__/client/editor.tsx b/apps/core/src/components/__debug__/client/editor.tsx similarity index 100% rename from apps/web/src/components/__debug__/client/editor.tsx rename to apps/core/src/components/__debug__/client/editor.tsx diff --git a/apps/web/src/components/affine/README.md b/apps/core/src/components/affine/README.md similarity index 100% rename from apps/web/src/components/affine/README.md rename to apps/core/src/components/affine/README.md diff --git a/apps/web/src/components/affine/affine-error-eoundary.tsx b/apps/core/src/components/affine/affine-error-eoundary.tsx similarity index 73% rename from apps/web/src/components/affine/affine-error-eoundary.tsx rename to apps/core/src/components/affine/affine-error-eoundary.tsx index 1ea5743aa..41d39385d 100644 --- a/apps/web/src/components/affine/affine-error-eoundary.tsx +++ b/apps/core/src/components/affine/affine-error-eoundary.tsx @@ -12,14 +12,11 @@ import { } from '@toeverything/plugin-infra/manager'; import { useAtomValue } from 'jotai/react'; import { Provider } from 'jotai/react'; -import type { NextRouter } from 'next/router'; import type { ErrorInfo, ReactElement, ReactNode } from 'react'; import type React from 'react'; import { Component } from 'react'; - -export type AffineErrorBoundaryProps = React.PropsWithChildren<{ - router: NextRouter; -}>; +import { useLocation, useParams } from 'react-router-dom'; +export type AffineErrorBoundaryProps = React.PropsWithChildren; type AffineError = | QueryParamError @@ -32,13 +29,13 @@ interface AffineErrorBoundaryState { error: AffineError | null; } -export const DumpInfo = (props: Pick) => { - const router = props.router; +export const DumpInfo = () => { + const location = useLocation(); const metadata = useAtomValue(rootWorkspacesMetadataAtom); const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom); const currentPageId = useAtomValue(currentPageIdAtom); - const path = router.asPath; - const query = router.query; + const path = location.pathname; + const query = useParams(); return ( <>
@@ -91,24 +88,6 @@ export class AffineErrorBoundary extends Component< Cannot find page {error.pageId} in workspace{' '} {error.workspace.id} - ); @@ -124,7 +103,7 @@ export class AffineErrorBoundary extends Component< <> {errorDetail} - + ); diff --git a/apps/web/src/components/affine/app-container.tsx b/apps/core/src/components/affine/app-container.tsx similarity index 100% rename from apps/web/src/components/affine/app-container.tsx rename to apps/core/src/components/affine/app-container.tsx diff --git a/apps/web/src/components/affine/create-workspace-modal/index.css.ts b/apps/core/src/components/affine/create-workspace-modal/index.css.ts similarity index 100% rename from apps/web/src/components/affine/create-workspace-modal/index.css.ts rename to apps/core/src/components/affine/create-workspace-modal/index.css.ts diff --git a/apps/web/src/components/affine/create-workspace-modal/index.tsx b/apps/core/src/components/affine/create-workspace-modal/index.tsx similarity index 100% rename from apps/web/src/components/affine/create-workspace-modal/index.tsx rename to apps/core/src/components/affine/create-workspace-modal/index.tsx diff --git a/apps/web/src/components/affine/enable-affine-cloud-modal/index.tsx b/apps/core/src/components/affine/enable-affine-cloud-modal/index.tsx similarity index 100% rename from apps/web/src/components/affine/enable-affine-cloud-modal/index.tsx rename to apps/core/src/components/affine/enable-affine-cloud-modal/index.tsx diff --git a/apps/web/src/components/affine/enable-affine-cloud-modal/style.ts b/apps/core/src/components/affine/enable-affine-cloud-modal/style.ts similarity index 100% rename from apps/web/src/components/affine/enable-affine-cloud-modal/style.ts rename to apps/core/src/components/affine/enable-affine-cloud-modal/style.ts diff --git a/apps/web/src/components/affine/language-menu/index.tsx b/apps/core/src/components/affine/language-menu/index.tsx similarity index 100% rename from apps/web/src/components/affine/language-menu/index.tsx rename to apps/core/src/components/affine/language-menu/index.tsx diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/index.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/index.tsx similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/index.tsx rename to apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/index.tsx diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/style.ts b/apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/style.ts similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/style.ts rename to apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/delete/style.ts diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/index.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/index.tsx similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/index.tsx rename to apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/index.tsx diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/index.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/index.tsx similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/index.tsx rename to apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/index.tsx diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/style.ts b/apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/style.ts similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/style.ts rename to apps/core/src/components/affine/new-workspace-setting-detail/delete-leave-workspace/leave/style.ts diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/export.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/export.tsx similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/export.tsx rename to apps/core/src/components/affine/new-workspace-setting-detail/export.tsx diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/index.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/index.tsx similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/index.tsx rename to apps/core/src/components/affine/new-workspace-setting-detail/index.tsx diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/profile.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/profile.tsx similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/profile.tsx rename to apps/core/src/components/affine/new-workspace-setting-detail/profile.tsx diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/publish.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/publish.tsx similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/publish.tsx rename to apps/core/src/components/affine/new-workspace-setting-detail/publish.tsx diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/storage.tsx b/apps/core/src/components/affine/new-workspace-setting-detail/storage.tsx similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/storage.tsx rename to apps/core/src/components/affine/new-workspace-setting-detail/storage.tsx diff --git a/apps/web/src/components/affine/new-workspace-setting-detail/style.css.ts b/apps/core/src/components/affine/new-workspace-setting-detail/style.css.ts similarity index 100% rename from apps/web/src/components/affine/new-workspace-setting-detail/style.css.ts rename to apps/core/src/components/affine/new-workspace-setting-detail/style.css.ts diff --git a/apps/web/src/components/affine/onboarding-modal.tsx b/apps/core/src/components/affine/onboarding-modal.tsx similarity index 100% rename from apps/web/src/components/affine/onboarding-modal.tsx rename to apps/core/src/components/affine/onboarding-modal.tsx diff --git a/apps/web/src/components/affine/setting-modal/account-setting/index.tsx b/apps/core/src/components/affine/setting-modal/account-setting/index.tsx similarity index 100% rename from apps/web/src/components/affine/setting-modal/account-setting/index.tsx rename to apps/core/src/components/affine/setting-modal/account-setting/index.tsx diff --git a/apps/web/src/components/affine/setting-modal/general-setting/about/config.tsx b/apps/core/src/components/affine/setting-modal/general-setting/about/config.tsx similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/about/config.tsx rename to apps/core/src/components/affine/setting-modal/general-setting/about/config.tsx diff --git a/apps/web/src/components/affine/setting-modal/general-setting/about/icons.tsx b/apps/core/src/components/affine/setting-modal/general-setting/about/icons.tsx similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/about/icons.tsx rename to apps/core/src/components/affine/setting-modal/general-setting/about/icons.tsx diff --git a/apps/web/src/components/affine/setting-modal/general-setting/about/index.tsx b/apps/core/src/components/affine/setting-modal/general-setting/about/index.tsx similarity index 87% rename from apps/web/src/components/affine/setting-modal/general-setting/about/index.tsx rename to apps/core/src/components/affine/setting-modal/general-setting/about/index.tsx index d7529d246..e5f1ce828 100644 --- a/apps/web/src/components/affine/setting-modal/general-setting/about/index.tsx +++ b/apps/core/src/components/affine/setting-modal/general-setting/about/index.tsx @@ -73,11 +73,21 @@ export const AboutAffine = () => { ) : null} - + {t['Official Website']()} - + {t['AFFiNE Community']()} @@ -101,11 +111,21 @@ export const AboutAffine = () => {
- + {t['Privacy']()} - + {t['Terms of Use']()} diff --git a/apps/web/src/components/affine/setting-modal/general-setting/about/style.css.ts b/apps/core/src/components/affine/setting-modal/general-setting/about/style.css.ts similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/about/style.css.ts rename to apps/core/src/components/affine/setting-modal/general-setting/about/style.css.ts diff --git a/apps/web/src/components/affine/setting-modal/general-setting/appearance/date-format-setting.tsx b/apps/core/src/components/affine/setting-modal/general-setting/appearance/date-format-setting.tsx similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/appearance/date-format-setting.tsx rename to apps/core/src/components/affine/setting-modal/general-setting/appearance/date-format-setting.tsx diff --git a/apps/web/src/components/affine/setting-modal/general-setting/appearance/index.tsx b/apps/core/src/components/affine/setting-modal/general-setting/appearance/index.tsx similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/appearance/index.tsx rename to apps/core/src/components/affine/setting-modal/general-setting/appearance/index.tsx diff --git a/apps/web/src/components/affine/setting-modal/general-setting/appearance/style.css.ts b/apps/core/src/components/affine/setting-modal/general-setting/appearance/style.css.ts similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/appearance/style.css.ts rename to apps/core/src/components/affine/setting-modal/general-setting/appearance/style.css.ts diff --git a/apps/web/src/components/affine/setting-modal/general-setting/index.tsx b/apps/core/src/components/affine/setting-modal/general-setting/index.tsx similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/index.tsx rename to apps/core/src/components/affine/setting-modal/general-setting/index.tsx diff --git a/apps/web/src/components/affine/setting-modal/general-setting/plugins/index.tsx b/apps/core/src/components/affine/setting-modal/general-setting/plugins/index.tsx similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/plugins/index.tsx rename to apps/core/src/components/affine/setting-modal/general-setting/plugins/index.tsx diff --git a/apps/web/src/components/affine/setting-modal/general-setting/plugins/style.css.ts b/apps/core/src/components/affine/setting-modal/general-setting/plugins/style.css.ts similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/plugins/style.css.ts rename to apps/core/src/components/affine/setting-modal/general-setting/plugins/style.css.ts diff --git a/apps/web/src/components/affine/setting-modal/general-setting/shortcuts/index.tsx b/apps/core/src/components/affine/setting-modal/general-setting/shortcuts/index.tsx similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/shortcuts/index.tsx rename to apps/core/src/components/affine/setting-modal/general-setting/shortcuts/index.tsx diff --git a/apps/web/src/components/affine/setting-modal/general-setting/shortcuts/style.css.ts b/apps/core/src/components/affine/setting-modal/general-setting/shortcuts/style.css.ts similarity index 100% rename from apps/web/src/components/affine/setting-modal/general-setting/shortcuts/style.css.ts rename to apps/core/src/components/affine/setting-modal/general-setting/shortcuts/style.css.ts diff --git a/apps/web/src/components/affine/setting-modal/index.tsx b/apps/core/src/components/affine/setting-modal/index.tsx similarity index 95% rename from apps/web/src/components/affine/setting-modal/index.tsx rename to apps/core/src/components/affine/setting-modal/index.tsx index 32dd1d8b0..067eaebee 100644 --- a/apps/web/src/components/affine/setting-modal/index.tsx +++ b/apps/core/src/components/affine/setting-modal/index.tsx @@ -83,7 +83,11 @@ export const SettingModal: React.FC = ({
- + {t[ 'Need more customization options? You can suggest them to us in the community.' ]()} diff --git a/apps/web/src/components/affine/setting-modal/setting-sidebar/index.tsx b/apps/core/src/components/affine/setting-modal/setting-sidebar/index.tsx similarity index 100% rename from apps/web/src/components/affine/setting-modal/setting-sidebar/index.tsx rename to apps/core/src/components/affine/setting-modal/setting-sidebar/index.tsx diff --git a/apps/web/src/components/affine/setting-modal/setting-sidebar/style.css.ts b/apps/core/src/components/affine/setting-modal/setting-sidebar/style.css.ts similarity index 100% rename from apps/web/src/components/affine/setting-modal/setting-sidebar/style.css.ts rename to apps/core/src/components/affine/setting-modal/setting-sidebar/style.css.ts diff --git a/apps/web/src/components/affine/setting-modal/style.css.ts b/apps/core/src/components/affine/setting-modal/style.css.ts similarity index 100% rename from apps/web/src/components/affine/setting-modal/style.css.ts rename to apps/core/src/components/affine/setting-modal/style.css.ts diff --git a/apps/web/src/components/affine/setting-modal/workspace-setting/index.tsx b/apps/core/src/components/affine/setting-modal/workspace-setting/index.tsx similarity index 86% rename from apps/web/src/components/affine/setting-modal/workspace-setting/index.tsx rename to apps/core/src/components/affine/setting-modal/workspace-setting/index.tsx index 53d656c0a..c736c092a 100644 --- a/apps/web/src/components/affine/setting-modal/workspace-setting/index.tsx +++ b/apps/core/src/components/affine/setting-modal/workspace-setting/index.tsx @@ -1,12 +1,15 @@ import { WorkspaceDetailSkeleton } from '@affine/component/setting-components'; import { usePassiveWorkspaceEffect } from '@toeverything/plugin-infra/__internal__/react'; import { useSetAtom } from 'jotai'; -import { useRouter } from 'next/router'; import { Suspense, useCallback } from 'react'; import { getUIAdapter } from '../../../../adapters/workspace'; import { openSettingModalAtom } from '../../../../atoms'; import { useOnTransformWorkspace } from '../../../../hooks/root/use-on-transform-workspace'; +import { + RouteLogic, + useNavigateHelper, +} from '../../../../hooks/use-navigate-helper'; import { useWorkspace } from '../../../../hooks/use-workspace'; import { useAppHelper } from '../../../../hooks/use-workspaces'; @@ -15,7 +18,7 @@ export const WorkspaceSetting = ({ workspaceId }: { workspaceId: string }) => { usePassiveWorkspaceEffect(workspace.blockSuiteWorkspace); const setSettingModal = useSetAtom(openSettingModalAtom); const helper = useAppHelper(); - const router = useRouter(); + const { jumpToIndex } = useNavigateHelper(); const { NewSettingsDetail } = getUIAdapter(workspace.flavour); @@ -23,9 +26,9 @@ export const WorkspaceSetting = ({ workspaceId }: { workspaceId: string }) => { async (id: string) => { await helper.deleteWorkspace(id); setSettingModal(prev => ({ ...prev, open: false, workspaceId: null })); - router.push('/').catch(console.error); + jumpToIndex(RouteLogic.REPLACE); }, - [helper, setSettingModal, router] + [helper, jumpToIndex, setSettingModal] ); const onTransformWorkspace = useOnTransformWorkspace(); diff --git a/apps/web/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx b/apps/core/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx similarity index 98% rename from apps/web/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx rename to apps/core/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx index 9fb6e1b11..eae28e0ea 100644 --- a/apps/web/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx +++ b/apps/core/src/components/affine/tmp-disable-affine-cloud-modal/index.tsx @@ -46,6 +46,7 @@ export const TmpDisableAffineCloudModal: React.FC< progress and be notified on availability, you can fill out the { - const router = useRouter(); - const { openPage } = useRouterHelper(router); + const { openPage } = useNavigateHelper(); const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace); const pageSettings = useAtomValue(pageSettingsAtom); const isPreferredEdgeless = useCallback( diff --git a/apps/web/src/components/blocksuite/workspace-header/download-tips.tsx b/apps/core/src/components/blocksuite/workspace-header/download-tips.tsx similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/download-tips.tsx rename to apps/core/src/components/blocksuite/workspace-header/download-tips.tsx diff --git a/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/edgeless-hover.json b/apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/edgeless-hover.json similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/edgeless-hover.json rename to apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/edgeless-hover.json diff --git a/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/page-hover.json b/apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/page-hover.json similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/page-hover.json rename to apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/animation-data/page-hover.json diff --git a/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx b/apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx rename to apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/index.tsx diff --git a/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/style.ts b/apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/style.ts similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/style.ts rename to apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/style.ts diff --git a/apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/switch-items.tsx b/apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/switch-items.tsx similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/editor-mode-switch/switch-items.tsx rename to apps/core/src/components/blocksuite/workspace-header/editor-mode-switch/switch-items.tsx diff --git a/apps/web/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 similarity index 97% rename from apps/web/src/components/blocksuite/workspace-header/header-right-items/editor-option-menu.tsx rename to apps/core/src/components/blocksuite/workspace-header/header-right-items/editor-option-menu.tsx index 8fd863bda..63940bdc0 100644 --- a/apps/web/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 @@ -16,8 +16,8 @@ import { } from '@toeverything/hooks/use-block-suite-page-meta'; import { currentPageIdAtom } from '@toeverything/plugin-infra/manager'; import { useAtom, useAtomValue } from 'jotai'; -import { useRouter } from 'next/router'; import { useState } from 'react'; +import { useParams } from 'react-router-dom'; import { pageSettingFamily } from '../../../../atoms'; import { useBlockSuiteMetaHelper } from '../../../../hooks/affine/use-block-suite-meta-helper'; @@ -159,6 +159,6 @@ const PageMenu = () => { ); }; export const EditorOptionMenu = () => { - const router = useRouter(); - return router.query.pageId ? : ; + const { pageId } = useParams(); + return pageId ? : ; }; diff --git a/apps/web/src/components/blocksuite/workspace-header/header-right-items/language-menu.tsx b/apps/core/src/components/blocksuite/workspace-header/header-right-items/language-menu.tsx similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/header-right-items/language-menu.tsx rename to apps/core/src/components/blocksuite/workspace-header/header-right-items/language-menu.tsx diff --git a/apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/icons.tsx b/apps/core/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/icons.tsx similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/icons.tsx rename to apps/core/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/icons.tsx diff --git a/apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/index.tsx b/apps/core/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/index.tsx similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/index.tsx rename to apps/core/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/index.tsx diff --git a/apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/style.ts b/apps/core/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/style.ts similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/style.ts rename to apps/core/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/style.ts diff --git a/apps/web/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 similarity index 80% rename from apps/web/src/components/blocksuite/workspace-header/header-right-items/trash-button-group.tsx rename to apps/core/src/components/blocksuite/workspace-header/header-right-items/trash-button-group.tsx index 74884cc27..15880d384 100644 --- a/apps/web/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 @@ -1,14 +1,15 @@ import { Button, Confirm } from '@affine/component'; +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 { useAtomValue } from 'jotai'; -import { useRouter } from 'next/router'; -import { useState } from 'react'; +import { useCallback, useState } from 'react'; import { useBlockSuiteMetaHelper } from '../../../../hooks/affine/use-block-suite-meta-helper'; import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace'; +import { useNavigateHelper } from '../../../../hooks/use-navigate-helper'; export const TrashButtonGroup = () => { // fixme(himself65): remove these hooks ASAP @@ -22,7 +23,7 @@ export const TrashButtonGroup = () => { ); assertExists(pageMeta); const t = useAFFiNEI18N(); - const router = useRouter(); + const { jumpToSubPath } = useNavigateHelper(); const { restoreFromTrash } = useBlockSuiteMetaHelper(blockSuiteWorkspace); const [open, setOpen] = useState(false); @@ -55,20 +56,10 @@ export const TrashButtonGroup = () => { confirmText={t['Delete']()} confirmType="danger" open={open} - onConfirm={() => { - // fixme(himself65): remove these hooks ASAP - router - .push({ - pathname: '/workspace/[workspaceId]/all', - query: { - workspaceId: workspace.id, - }, - }) - .catch(error => { - console.error(error); - }); + onConfirm={useCallback(() => { + jumpToSubPath(workspace.id, WorkspaceSubPath.ALL); blockSuiteWorkspace.removePage(pageId); - }} + }, [blockSuiteWorkspace, jumpToSubPath, pageId, workspace.id])} onCancel={() => { setOpen(false); }} diff --git a/apps/web/src/components/blocksuite/workspace-header/header-right-items/user-avatar.tsx b/apps/core/src/components/blocksuite/workspace-header/header-right-items/user-avatar.tsx similarity index 100% rename from apps/web/src/components/blocksuite/workspace-header/header-right-items/user-avatar.tsx rename to apps/core/src/components/blocksuite/workspace-header/header-right-items/user-avatar.tsx diff --git a/apps/web/src/components/blocksuite/workspace-header/header.tsx b/apps/core/src/components/blocksuite/workspace-header/header.tsx similarity index 82% rename from apps/web/src/components/blocksuite/workspace-header/header.tsx rename to apps/core/src/components/blocksuite/workspace-header/header.tsx index 99849b842..33437c1d3 100644 --- a/apps/web/src/components/blocksuite/workspace-header/header.tsx +++ b/apps/core/src/components/blocksuite/workspace-header/header.tsx @@ -5,7 +5,6 @@ import { } from '@affine/component/app-sidebar'; import { SidebarSwitch } from '@affine/component/app-sidebar/sidebar-header'; import { isDesktop } from '@affine/env/constant'; -import { WorkspaceFlavour } from '@affine/env/workspace'; import { CloseIcon, MinusIcon, RoundedRectangleIcon } from '@blocksuite/icons'; import type { Page } from '@blocksuite/store'; import { affinePluginsAtom } from '@toeverything/plugin-infra/manager'; @@ -24,12 +23,8 @@ import { import { contentLayoutAtom } from '../../../atoms/layout'; import { currentModeAtom } from '../../../atoms/mode'; import type { AffineOfficialWorkspace } from '../../../shared'; -import { DownloadClientTip } from './download-tips'; -import EditPage from './header-right-items/edit-page'; import { EditorOptionMenu } from './header-right-items/editor-option-menu'; -import { HeaderShareMenu } from './header-right-items/share-menu'; import TrashButtonGroup from './header-right-items/trash-button-group'; -import UserAvatar from './header-right-items/user-avatar'; import * as styles from './styles.css'; import { OSWarningMessage, shouldShowWarning } from './utils'; @@ -45,10 +40,6 @@ export type BaseHeaderProps< export enum HeaderRightItemName { EditorOptionMenu = 'editorOptionMenu', TrashButtonGroup = 'trashButtonGroup', - ShareMenu = 'shareMenu', - EditPage = 'editPage', - UserAvatar = 'userAvatar', - // some windows only items WindowsAppControls = 'windowsAppControls', } @@ -72,24 +63,6 @@ const HeaderRightItems: Record = { return currentPage?.meta.trash === true; }, }, - [HeaderRightItemName.ShareMenu]: { - Component: HeaderShareMenu, - availableWhen: (workspace, currentPage) => { - return workspace.flavour !== WorkspaceFlavour.PUBLIC && !!currentPage; - }, - }, - [HeaderRightItemName.EditPage]: { - Component: EditPage, - availableWhen: (workspace, currentPage, { isPublic }) => { - return isPublic; - }, - }, - [HeaderRightItemName.UserAvatar]: { - Component: UserAvatar, - availableWhen: (workspace, currentPage, { isPublic }) => { - return isPublic; - }, - }, [HeaderRightItemName.EditorOptionMenu]: { Component: EditorOptionMenu, availableWhen: (_, currentPage, { isPublic }) => { @@ -192,8 +165,6 @@ export const Header = forwardRef< PropsWithChildren & HTMLAttributes >((props, ref) => { const [showWarning, setShowWarning] = useState(false); - const [showGuideDownloadClientTip, setShowGuideDownloadClientTip] = - useState(true); // const [shouldShowGuideDownloadClientTip] = useAtom( // guideDownloadClientTipAtom // ); @@ -213,22 +184,13 @@ export const Header = forwardRef< data-open={open} data-sidebar-floating={appSidebarFloating} > - {showGuideDownloadClientTip ? ( - { - setShowGuideDownloadClientTip(false); - }} - /> - ) : ( - } - onClose={() => { - setShowWarning(false); - }} - /> - )} + } + onClose={() => { + setShowWarning(false); + }} + />
{ if (isDesktop) { - // even though desktop have compatibility issues, we don't want to show the warning + // even though desktop has compatibility issues, + // we don't want to show the warning return false; } if (!environment.isBrowser) { diff --git a/apps/web/src/components/filter-container.css.ts b/apps/core/src/components/filter-container.css.ts similarity index 100% rename from apps/web/src/components/filter-container.css.ts rename to apps/core/src/components/filter-container.css.ts diff --git a/apps/web/src/components/page-detail-editor.css.ts b/apps/core/src/components/page-detail-editor.css.ts similarity index 100% rename from apps/web/src/components/page-detail-editor.css.ts rename to apps/core/src/components/page-detail-editor.css.ts diff --git a/apps/web/src/components/page-detail-editor.tsx b/apps/core/src/components/page-detail-editor.tsx similarity index 95% rename from apps/web/src/components/page-detail-editor.tsx rename to apps/core/src/components/page-detail-editor.tsx index eaf6d44b7..0665978c9 100644 --- a/apps/web/src/components/page-detail-editor.tsx +++ b/apps/core/src/components/page-detail-editor.tsx @@ -7,7 +7,6 @@ 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 { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-block-suite-workspace-page-title'; import { affinePluginsAtom } from '@toeverything/plugin-infra/manager'; import type { AffinePlugin, @@ -17,7 +16,6 @@ import type { import type { PluginBlockSuiteAdapter } from '@toeverything/plugin-infra/type'; import clsx from 'clsx'; import { useAtomValue, useSetAtom } from 'jotai'; -import Head from 'next/head'; import type { CSSProperties, FC, ReactElement } from 'react'; import { memo, Suspense, useCallback, useMemo } from 'react'; import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels'; @@ -190,7 +188,6 @@ export const PageDetailEditor: FC = props => { if (!page) { throw new PageNotFoundError(workspace, pageId); } - const title = useBlockSuiteWorkspacePageTitle(workspace, pageId); const layout = useAtomValue(contentLayoutAtom); const affinePluginsMap = useAtomValue(affinePluginsAtom); @@ -201,9 +198,6 @@ export const PageDetailEditor: FC = props => { return ( <> - - {title} - diff --git a/apps/web/src/components/pure/file-upload/index.tsx b/apps/core/src/components/pure/file-upload/index.tsx similarity index 100% rename from apps/web/src/components/pure/file-upload/index.tsx rename to apps/core/src/components/pure/file-upload/index.tsx diff --git a/apps/web/src/components/pure/footer/index.tsx b/apps/core/src/components/pure/footer/index.tsx similarity index 100% rename from apps/web/src/components/pure/footer/index.tsx rename to apps/core/src/components/pure/footer/index.tsx diff --git a/apps/web/src/components/pure/footer/styles.ts b/apps/core/src/components/pure/footer/styles.ts similarity index 100% rename from apps/web/src/components/pure/footer/styles.ts rename to apps/core/src/components/pure/footer/styles.ts diff --git a/apps/web/src/components/pure/help-island/icons.tsx b/apps/core/src/components/pure/help-island/icons.tsx similarity index 100% rename from apps/web/src/components/pure/help-island/icons.tsx rename to apps/core/src/components/pure/help-island/icons.tsx diff --git a/apps/web/src/components/pure/help-island/index.tsx b/apps/core/src/components/pure/help-island/index.tsx similarity index 100% rename from apps/web/src/components/pure/help-island/index.tsx rename to apps/core/src/components/pure/help-island/index.tsx diff --git a/apps/web/src/components/pure/help-island/style.ts b/apps/core/src/components/pure/help-island/style.ts similarity index 100% rename from apps/web/src/components/pure/help-island/style.ts rename to apps/core/src/components/pure/help-island/style.ts diff --git a/apps/web/src/components/pure/icons/index.tsx b/apps/core/src/components/pure/icons/index.tsx similarity index 100% rename from apps/web/src/components/pure/icons/index.tsx rename to apps/core/src/components/pure/icons/index.tsx diff --git a/apps/web/src/components/pure/quick-search-button/index.tsx b/apps/core/src/components/pure/quick-search-button/index.tsx similarity index 100% rename from apps/web/src/components/pure/quick-search-button/index.tsx rename to apps/core/src/components/pure/quick-search-button/index.tsx diff --git a/apps/web/src/components/pure/quick-search-modal/config.ts b/apps/core/src/components/pure/quick-search-modal/config.ts similarity index 100% rename from apps/web/src/components/pure/quick-search-modal/config.ts rename to apps/core/src/components/pure/quick-search-modal/config.ts diff --git a/apps/web/src/components/pure/quick-search-modal/footer.tsx b/apps/core/src/components/pure/quick-search-modal/footer.tsx similarity index 87% rename from apps/web/src/components/pure/quick-search-modal/footer.tsx rename to apps/core/src/components/pure/quick-search-modal/footer.tsx index a518fab0b..ef446d2ee 100644 --- a/apps/web/src/components/pure/quick-search-modal/footer.tsx +++ b/apps/core/src/components/pure/quick-search-modal/footer.tsx @@ -6,11 +6,10 @@ import { PlusIcon } from '@blocksuite/icons'; import { nanoid } from '@blocksuite/store'; import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper'; import { Command } from 'cmdk'; -import type { NextRouter } from 'next/router'; import type React from 'react'; import { useCallback } from 'react'; -import { useRouterHelper } from '../../../hooks/use-router-helper'; +import { useNavigateHelper } from '../../../hooks/use-navigate-helper'; import type { BlockSuiteWorkspace } from '../../../shared'; import { StyledModalFooterContent } from './style'; @@ -18,18 +17,16 @@ export type FooterProps = { query: string; onClose: () => void; blockSuiteWorkspace: BlockSuiteWorkspace; - router: NextRouter; }; export const Footer: React.FC = ({ query, onClose, blockSuiteWorkspace, - router, }) => { const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace); const t = useAFFiNEI18N(); - const { jumpToPage } = useRouterHelper(router); + const { jumpToPage } = useNavigateHelper(); const MAX_QUERY_SHOW_LENGTH = 20; const normalizedQuery = query.length > MAX_QUERY_SHOW_LENGTH @@ -55,9 +52,7 @@ export const Footer: React.FC = ({ title: query, }); onClose(); - jumpToPage(blockSuiteWorkspace.id, page.id).catch(err => { - console.error(err); - }); + jumpToPage(blockSuiteWorkspace.id, page.id); }, [blockSuiteWorkspace, createPage, jumpToPage, onClose, query])} > diff --git a/apps/web/src/components/pure/quick-search-modal/index.tsx b/apps/core/src/components/pure/quick-search-modal/index.tsx similarity index 75% rename from apps/web/src/components/pure/quick-search-modal/index.tsx rename to apps/core/src/components/pure/quick-search-modal/index.tsx index 0205cf47b..e5b2775fd 100644 --- a/apps/web/src/components/pure/quick-search-modal/index.tsx +++ b/apps/core/src/components/pure/quick-search-modal/index.tsx @@ -1,20 +1,12 @@ import { Modal, ModalWrapper } from '@affine/component'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { Command } from 'cmdk'; -import type { NextRouter } from 'next/router'; -import type React from 'react'; -import { - useCallback, - useEffect, - useMemo, - useRef, - useState, - useTransition, -} from 'react'; +import { startTransition } from 'react'; +import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { useLocation } from 'react-router-dom'; import type { AllWorkspace } from '../../../shared'; import { Footer } from './footer'; -import { PublishedResults } from './published-results'; import { Results } from './results'; import { SearchInput } from './search-input'; import { @@ -29,30 +21,27 @@ export type QuickSearchModalProps = { workspace: AllWorkspace; open: boolean; setOpen: (value: boolean) => void; - router: NextRouter; }; export const QuickSearchModal: React.FC = ({ open, setOpen, - router, workspace, }) => { const blockSuiteWorkspace = workspace?.blockSuiteWorkspace; const t = useAFFiNEI18N(); const inputRef = useRef(null); - const [loading, startTransition] = useTransition(); const [query, _setQuery] = useState(''); const setQuery = useCallback((query: string) => { startTransition(() => { _setQuery(query); }); }, []); + const location = useLocation(); const isPublicWorkspace = useMemo( - () => router.pathname.startsWith('/public-workspace'), - [router] + () => location.pathname.startsWith('/public-workspace'), + [location] ); - const [publishWorkspaceName, setPublishWorkspaceName] = useState(''); const [showCreatePage, setShowCreatePage] = useState(true); const isPublicAndNoQuery = useCallback(() => { return isPublicWorkspace && query.length === 0; @@ -78,7 +67,7 @@ export const QuickSearchModal: React.FC = ({ document.addEventListener('keydown', keydown, { capture: true }); return () => document.removeEventListener('keydown', keydown, { capture: true }); - }, [open, router, setOpen, setQuery]); + }, [open, setOpen, setQuery]); useEffect(() => { if (open) { // Waiting for DOM rendering @@ -137,13 +126,7 @@ export const QuickSearchModal: React.FC = ({ return; } }} - placeholder={ - isPublicWorkspace - ? t['Quick search placeholder2']({ - workspace: publishWorkspaceName, - }) - : t['Quick search placeholder']() - } + placeholder={t['Quick search placeholder']()} /> {environment.isBrowser && environment.isMacOs @@ -158,24 +141,12 @@ export const QuickSearchModal: React.FC = ({ - {isPublicWorkspace ? ( - - ) : ( - - )} + {isPublicWorkspace ? null : showCreatePage ? ( <> @@ -185,7 +156,6 @@ export const QuickSearchModal: React.FC = ({ query={query} onClose={handleClose} blockSuiteWorkspace={blockSuiteWorkspace} - router={router} /> diff --git a/apps/web/src/components/pure/quick-search-modal/results.tsx b/apps/core/src/components/pure/quick-search-modal/results.tsx similarity index 86% rename from apps/web/src/components/pure/quick-search-modal/results.tsx rename to apps/core/src/components/pure/quick-search-modal/results.tsx index 651a9a133..3ac21890d 100644 --- a/apps/web/src/components/pure/quick-search-modal/results.tsx +++ b/apps/core/src/components/pure/quick-search-modal/results.tsx @@ -6,13 +6,12 @@ import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page- import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper'; import { Command } from 'cmdk'; import { useAtomValue } from 'jotai'; -import Image from 'next/legacy/image'; -import type { NextRouter } from 'next/router'; import type { Dispatch, FC, SetStateAction } from 'react'; import { useEffect } from 'react'; +import { useNavigate } from 'react-router-dom'; import { recentPageSettingsAtom } from '../../../atoms'; -import { useRouterHelper } from '../../../hooks/use-router-helper'; +import { useNavigateHelper } from '../../../hooks/use-navigate-helper'; import type { AllWorkspace } from '../../../shared'; import { useSwitchToConfig } from './config'; import { StyledListItem, StyledNotFound } from './style'; @@ -22,13 +21,11 @@ export type ResultsProps = { query: string; onClose: () => void; setShowCreatePage: Dispatch>; - router: NextRouter; }; export const Results: FC = ({ query, workspace, setShowCreatePage, - router, onClose, }) => { const blockSuiteWorkspace = workspace.blockSuiteWorkspace; @@ -39,7 +36,8 @@ export const Results: FC = ({ const recentPageSetting = useAtomValue(recentPageSettingsAtom); const t = useAFFiNEI18N(); - const { jumpToPage } = useRouterHelper(router); + const navigate = useNavigate(); + const { jumpToPage } = useNavigateHelper(); const results = blockSuiteWorkspace.search({ query }); // remove `space:` prefix @@ -75,9 +73,7 @@ export const Results: FC = ({ value={page.id} onSelect={() => { onClose(); - jumpToPage(blockSuiteWorkspace.id, page.id).catch( - console.error - ); + jumpToPage(blockSuiteWorkspace.id, page.id); }} > @@ -101,7 +97,7 @@ export const Results: FC = ({ value={link.title} onSelect={() => { onClose(); - link.href && router.push(link.href).catch(console.error); + link.href && navigate(link.href); link.onClick?.(); }} > @@ -120,12 +116,7 @@ export const Results: FC = ({ return ( {t['Find 0 result']()} - no result + ); } @@ -140,9 +131,7 @@ export const Results: FC = ({ onSelect={() => { onClose(); assertExists(blockSuiteWorkspace.id); - jumpToPage(blockSuiteWorkspace.id, result.id).catch(error => - console.error(error) - ); + jumpToPage(blockSuiteWorkspace.id, result.id); }} value={result.id} > diff --git a/apps/web/src/components/pure/quick-search-modal/search-input.tsx b/apps/core/src/components/pure/quick-search-modal/search-input.tsx similarity index 100% rename from apps/web/src/components/pure/quick-search-modal/search-input.tsx rename to apps/core/src/components/pure/quick-search-modal/search-input.tsx diff --git a/apps/web/src/components/pure/quick-search-modal/style.ts b/apps/core/src/components/pure/quick-search-modal/style.ts similarity index 100% rename from apps/web/src/components/pure/quick-search-modal/style.ts rename to apps/core/src/components/pure/quick-search-modal/style.ts diff --git a/apps/web/src/components/pure/shortcuts-modal/icons.tsx b/apps/core/src/components/pure/shortcuts-modal/icons.tsx similarity index 100% rename from apps/web/src/components/pure/shortcuts-modal/icons.tsx rename to apps/core/src/components/pure/shortcuts-modal/icons.tsx diff --git a/apps/web/src/components/pure/shortcuts-modal/index.tsx b/apps/core/src/components/pure/shortcuts-modal/index.tsx similarity index 100% rename from apps/web/src/components/pure/shortcuts-modal/index.tsx rename to apps/core/src/components/pure/shortcuts-modal/index.tsx diff --git a/apps/web/src/components/pure/shortcuts-modal/style.ts b/apps/core/src/components/pure/shortcuts-modal/style.ts similarity index 100% rename from apps/web/src/components/pure/shortcuts-modal/style.ts rename to apps/core/src/components/pure/shortcuts-modal/style.ts diff --git a/apps/web/src/components/pure/workspace-list-modal/index.tsx b/apps/core/src/components/pure/workspace-list-modal/index.tsx similarity index 100% rename from apps/web/src/components/pure/workspace-list-modal/index.tsx rename to apps/core/src/components/pure/workspace-list-modal/index.tsx diff --git a/apps/web/src/components/pure/workspace-list-modal/styles.ts b/apps/core/src/components/pure/workspace-list-modal/styles.ts similarity index 100% rename from apps/web/src/components/pure/workspace-list-modal/styles.ts rename to apps/core/src/components/pure/workspace-list-modal/styles.ts diff --git a/apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.css.ts b/apps/core/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.css.ts similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.css.ts rename to apps/core/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.css.ts diff --git a/apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.ts b/apps/core/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.ts similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.ts rename to apps/core/src/components/pure/workspace-slider-bar/WorkspaceSelector/index.ts diff --git a/apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/styles.ts b/apps/core/src/components/pure/workspace-slider-bar/WorkspaceSelector/styles.ts similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/styles.ts rename to apps/core/src/components/pure/workspace-slider-bar/WorkspaceSelector/styles.ts diff --git a/apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/workspace-selector.tsx b/apps/core/src/components/pure/workspace-slider-bar/WorkspaceSelector/workspace-selector.tsx similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/WorkspaceSelector/workspace-selector.tsx rename to apps/core/src/components/pure/workspace-slider-bar/WorkspaceSelector/workspace-selector.tsx diff --git a/apps/web/src/components/pure/workspace-slider-bar/collections/collections-list.tsx b/apps/core/src/components/pure/workspace-slider-bar/collections/collections-list.tsx similarity index 95% rename from apps/web/src/components/pure/workspace-slider-bar/collections/collections-list.tsx rename to apps/core/src/components/pure/workspace-slider-bar/collections/collections-list.tsx index 1ae6404c0..9314a532e 100644 --- a/apps/web/src/components/pure/workspace-slider-bar/collections/collections-list.tsx +++ b/apps/core/src/components/pure/workspace-slider-bar/collections/collections-list.tsx @@ -7,6 +7,7 @@ import { } from '@affine/component/page-list'; import type { Collection } from '@affine/env/filter'; import type { GetPageInfoById } from '@affine/env/page-info'; +import { WorkspaceSubPath } from '@affine/env/workspace'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { DeleteIcon, @@ -20,11 +21,11 @@ import type { DragEndEvent } from '@dnd-kit/core'; import { useDroppable } from '@dnd-kit/core'; import * as Collapsible from '@radix-ui/react-collapsible'; import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta'; -import { useRouter } from 'next/router'; import type { ReactElement } from 'react'; import React, { useCallback, useMemo, useState } from 'react'; import { useGetPageInfoById } from '../../../../hooks/use-get-page-info'; +import { useNavigateHelper } from '../../../../hooks/use-navigate-helper'; import { filterPage } from '../../../../utils/filter'; import type { CollectionsListProps } from '../index'; import { Page } from './page'; @@ -130,17 +131,11 @@ const CollectionRenderer = ({ }) => { const [collapsed, setCollapsed] = React.useState(true); const setting = useCollectionManager(workspace.id); - const router = useRouter(); + const { jumpToSubPath } = useNavigateHelper(); const clickCollection = useCallback(() => { - router - .push(`/workspace/${workspace.id}/all`) - .then(() => { - setting.selectCollection(collection.id); - }) - .catch(err => { - console.error(err); - }); - }, [router, workspace.id, setting, collection.id]); + jumpToSubPath(workspace.id, WorkspaceSubPath.ALL); + setting.selectCollection(collection.id); + }, [jumpToSubPath, workspace.id, setting, collection.id]); const { setNodeRef, isOver } = useDroppable({ id: `${Collections_DROP_AREA_PREFIX}${collection.id}`, data: { diff --git a/apps/web/src/components/pure/workspace-slider-bar/collections/index.tsx b/apps/core/src/components/pure/workspace-slider-bar/collections/index.tsx similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/collections/index.tsx rename to apps/core/src/components/pure/workspace-slider-bar/collections/index.tsx diff --git a/apps/web/src/components/pure/workspace-slider-bar/collections/page.tsx b/apps/core/src/components/pure/workspace-slider-bar/collections/page.tsx similarity index 94% rename from apps/web/src/components/pure/workspace-slider-bar/collections/page.tsx rename to apps/core/src/components/pure/workspace-slider-bar/collections/page.tsx index 16f8051f8..bbce0b15e 100644 --- a/apps/web/src/components/pure/workspace-slider-bar/collections/page.tsx +++ b/apps/core/src/components/pure/workspace-slider-bar/collections/page.tsx @@ -13,12 +13,13 @@ import type { PageMeta, Workspace } from '@blocksuite/store'; import * as Collapsible from '@radix-ui/react-collapsible'; import { useBlockSuitePageReferences } from '@toeverything/hooks/use-block-suite-page-references'; import { useAtomValue } from 'jotai/index'; -import { useRouter } from 'next/router'; import type { ReactElement } from 'react'; import React, { useCallback, useMemo } from 'react'; +import { useParams } from 'react-router-dom'; import { pageSettingFamily } from '../../../../atoms'; import { useBlockSuiteMetaHelper } from '../../../../hooks/affine/use-block-suite-meta-helper'; +import { useNavigateHelper } from '../../../../hooks/use-navigate-helper'; import { ReferencePage } from '../components/reference-page'; import * as styles from './styles.css'; @@ -133,16 +134,17 @@ export const Page = ({ allPageMeta: Record; }) => { const [collapsed, setCollapsed] = React.useState(true); - const router = useRouter(); + const params = useParams(); + const { jumpToPage } = useNavigateHelper(); const t = useAFFiNEI18N(); const pageId = page.id; - const active = router.query.pageId === pageId; + const active = params.pageId === pageId; const setting = useAtomValue(pageSettingFamily(pageId)); const icon = setting?.mode === 'edgeless' ? : ; const references = useBlockSuitePageReferences(workspace, pageId); const clickPage = useCallback(() => { - return router.push(`/workspace/${workspace.id}/${page.id}`); - }, [page.id, router, workspace.id]); + jumpToPage(workspace.id, page.id); + }, [jumpToPage, page.id, workspace.id]); const referencesToRender = references.filter(id => !allPageMeta[id]?.trash); return ( diff --git a/apps/web/src/components/pure/workspace-slider-bar/collections/styles.css.ts b/apps/core/src/components/pure/workspace-slider-bar/collections/styles.css.ts similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/collections/styles.css.ts rename to apps/core/src/components/pure/workspace-slider-bar/collections/styles.css.ts diff --git a/apps/web/src/components/pure/workspace-slider-bar/components/reference-page.tsx b/apps/core/src/components/pure/workspace-slider-bar/components/reference-page.tsx similarity index 94% rename from apps/web/src/components/pure/workspace-slider-bar/components/reference-page.tsx rename to apps/core/src/components/pure/workspace-slider-bar/components/reference-page.tsx index 3e9cdbe6b..46cc2a30b 100644 --- a/apps/web/src/components/pure/workspace-slider-bar/components/reference-page.tsx +++ b/apps/core/src/components/pure/workspace-slider-bar/components/reference-page.tsx @@ -4,9 +4,9 @@ import { EdgelessIcon, PageIcon } from '@blocksuite/icons'; import type { PageMeta, Workspace } from '@blocksuite/store'; import * as Collapsible from '@radix-ui/react-collapsible'; import { useBlockSuitePageReferences } from '@toeverything/hooks/use-block-suite-page-references'; -import { useAtomValue } from 'jotai/index'; -import { useRouter } from 'next/router'; +import { useAtomValue } from 'jotai/react'; import { useMemo, useState } from 'react'; +import { useParams } from 'react-router-dom'; import { pageSettingFamily } from '../../../../atoms'; import * as styles from '../favorite/styles.css'; @@ -23,9 +23,9 @@ export const ReferencePage = ({ metaMapping, parentIds, }: ReferencePageProps) => { - const router = useRouter(); + const params = useParams(); const setting = useAtomValue(pageSettingFamily(pageId)); - const active = router.query.pageId === pageId; + const active = params.pageId === pageId; const icon = setting?.mode === 'edgeless' ? : ; const references = useBlockSuitePageReferences(workspace, pageId); const referencesToShow = useMemo(() => { diff --git a/apps/web/src/components/pure/workspace-slider-bar/favorite/empty-item.tsx b/apps/core/src/components/pure/workspace-slider-bar/favorite/empty-item.tsx similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/favorite/empty-item.tsx rename to apps/core/src/components/pure/workspace-slider-bar/favorite/empty-item.tsx diff --git a/apps/web/src/components/pure/workspace-slider-bar/favorite/favorite-list.tsx b/apps/core/src/components/pure/workspace-slider-bar/favorite/favorite-list.tsx similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/favorite/favorite-list.tsx rename to apps/core/src/components/pure/workspace-slider-bar/favorite/favorite-list.tsx diff --git a/apps/web/src/components/pure/workspace-slider-bar/favorite/index.tsx b/apps/core/src/components/pure/workspace-slider-bar/favorite/index.tsx similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/favorite/index.tsx rename to apps/core/src/components/pure/workspace-slider-bar/favorite/index.tsx diff --git a/apps/web/src/components/pure/workspace-slider-bar/favorite/styles.css.ts b/apps/core/src/components/pure/workspace-slider-bar/favorite/styles.css.ts similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/favorite/styles.css.ts rename to apps/core/src/components/pure/workspace-slider-bar/favorite/styles.css.ts diff --git a/apps/web/src/components/pure/workspace-slider-bar/index.tsx b/apps/core/src/components/pure/workspace-slider-bar/index.tsx similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/index.tsx rename to apps/core/src/components/pure/workspace-slider-bar/index.tsx diff --git a/apps/web/src/components/pure/workspace-slider-bar/shared-styles.ts b/apps/core/src/components/pure/workspace-slider-bar/shared-styles.ts similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/shared-styles.ts rename to apps/core/src/components/pure/workspace-slider-bar/shared-styles.ts diff --git a/apps/web/src/components/pure/workspace-slider-bar/style.ts b/apps/core/src/components/pure/workspace-slider-bar/style.ts similarity index 100% rename from apps/web/src/components/pure/workspace-slider-bar/style.ts rename to apps/core/src/components/pure/workspace-slider-bar/style.ts diff --git a/apps/web/src/components/pure/workspace-title/index.tsx b/apps/core/src/components/pure/workspace-title/index.tsx similarity index 100% rename from apps/web/src/components/pure/workspace-title/index.tsx rename to apps/core/src/components/pure/workspace-title/index.tsx diff --git a/apps/web/src/components/root-app-sidebar/import-page.tsx b/apps/core/src/components/root-app-sidebar/import-page.tsx similarity index 100% rename from apps/web/src/components/root-app-sidebar/import-page.tsx rename to apps/core/src/components/root-app-sidebar/import-page.tsx diff --git a/apps/web/src/components/root-app-sidebar/index.tsx b/apps/core/src/components/root-app-sidebar/index.tsx similarity index 100% rename from apps/web/src/components/root-app-sidebar/index.tsx rename to apps/core/src/components/root-app-sidebar/index.tsx diff --git a/apps/web/src/components/workspace-header.tsx b/apps/core/src/components/workspace-header.tsx similarity index 100% rename from apps/web/src/components/workspace-header.tsx rename to apps/core/src/components/workspace-header.tsx diff --git a/apps/web/src/hooks/__tests__/use-system-online.spec.ts b/apps/core/src/hooks/__tests__/use-system-online.spec.ts similarity index 100% rename from apps/web/src/hooks/__tests__/use-system-online.spec.ts rename to apps/core/src/hooks/__tests__/use-system-online.spec.ts diff --git a/apps/web/src/hooks/affine/README.md b/apps/core/src/hooks/affine/README.md similarity index 100% rename from apps/web/src/hooks/affine/README.md rename to apps/core/src/hooks/affine/README.md diff --git a/apps/web/src/hooks/affine/use-block-suite-meta-helper.ts b/apps/core/src/hooks/affine/use-block-suite-meta-helper.ts similarity index 100% rename from apps/web/src/hooks/affine/use-block-suite-meta-helper.ts rename to apps/core/src/hooks/affine/use-block-suite-meta-helper.ts diff --git a/apps/web/src/hooks/affine/use-reference-link-helper.ts b/apps/core/src/hooks/affine/use-reference-link-helper.ts similarity index 100% rename from apps/web/src/hooks/affine/use-reference-link-helper.ts rename to apps/core/src/hooks/affine/use-reference-link-helper.ts diff --git a/apps/web/src/hooks/affine/use-shortcuts.ts b/apps/core/src/hooks/affine/use-shortcuts.ts similarity index 100% rename from apps/web/src/hooks/affine/use-shortcuts.ts rename to apps/core/src/hooks/affine/use-shortcuts.ts diff --git a/apps/web/src/hooks/current/use-current-workspace.ts b/apps/core/src/hooks/current/use-current-workspace.ts similarity index 100% rename from apps/web/src/hooks/current/use-current-workspace.ts rename to apps/core/src/hooks/current/use-current-workspace.ts diff --git a/apps/web/src/hooks/root/use-on-transform-workspace.ts b/apps/core/src/hooks/root/use-on-transform-workspace.ts similarity index 100% rename from apps/web/src/hooks/root/use-on-transform-workspace.ts rename to apps/core/src/hooks/root/use-on-transform-workspace.ts diff --git a/apps/web/src/hooks/use-get-page-info.ts b/apps/core/src/hooks/use-get-page-info.ts similarity index 100% rename from apps/web/src/hooks/use-get-page-info.ts rename to apps/core/src/hooks/use-get-page-info.ts diff --git a/apps/core/src/hooks/use-location-title.ts b/apps/core/src/hooks/use-location-title.ts new file mode 100644 index 000000000..682cbcfcb --- /dev/null +++ b/apps/core/src/hooks/use-location-title.ts @@ -0,0 +1,4 @@ +// todo +export function useLocationTitle(): string { + return 'AFFiNE'; +} diff --git a/apps/core/src/hooks/use-navigate-helper.ts b/apps/core/src/hooks/use-navigate-helper.ts new file mode 100644 index 000000000..49e7c944b --- /dev/null +++ b/apps/core/src/hooks/use-navigate-helper.ts @@ -0,0 +1,88 @@ +import type { WorkspaceSubPath } from '@affine/env/workspace'; +import { useCallback } from 'react'; +import { useLocation, useNavigate } from 'react-router-dom'; + +export enum RouteLogic { + REPLACE = 'replace', + PUSH = 'push', +} + +export function useNavigateHelper() { + const location = useLocation(); + const navigate = useNavigate(); + const jumpToPage = useCallback( + ( + workspaceId: string, + pageId: string, + logic: RouteLogic = RouteLogic.PUSH + ) => { + return navigate(`/workspace/${workspaceId}/${pageId}`, { + replace: logic === RouteLogic.REPLACE, + }); + }, + [navigate] + ); + const jumpToPublicWorkspacePage = useCallback( + ( + workspaceId: string, + pageId: string, + logic: RouteLogic = RouteLogic.PUSH + ) => { + return navigate(`/public-workspace/${workspaceId}/${pageId}`, { + replace: logic === RouteLogic.REPLACE, + }); + }, + [navigate] + ); + const jumpToSubPath = useCallback( + ( + workspaceId: string, + subPath: WorkspaceSubPath, + logic: RouteLogic = RouteLogic.PUSH + ) => { + return navigate(`/workspace/${workspaceId}/${subPath}`, { + replace: logic === RouteLogic.REPLACE, + }); + }, + [navigate] + ); + const openPage = useCallback( + (workspaceId: string, pageId: string) => { + const isPublicWorkspace = + location.pathname.indexOf('/public-workspace') === 0; + if (isPublicWorkspace) { + return jumpToPublicWorkspacePage(workspaceId, pageId); + } else { + return jumpToPage(workspaceId, pageId); + } + }, + [jumpToPage, jumpToPublicWorkspacePage, location.pathname] + ); + + const jumpToIndex = useCallback( + (logic: RouteLogic = RouteLogic.PUSH) => { + return navigate('/', { + replace: logic === RouteLogic.REPLACE, + }); + }, + [navigate] + ); + + const jumpTo404 = useCallback( + (logic: RouteLogic = RouteLogic.PUSH) => { + return navigate('/404', { + replace: logic === RouteLogic.REPLACE, + }); + }, + [navigate] + ); + + return { + jumpToPage, + jumpToPublicWorkspacePage, + jumpToSubPath, + jumpToIndex, + jumpTo404, + openPage, + }; +} diff --git a/apps/web/src/hooks/use-system-online.ts b/apps/core/src/hooks/use-system-online.ts similarity index 100% rename from apps/web/src/hooks/use-system-online.ts rename to apps/core/src/hooks/use-system-online.ts diff --git a/apps/web/src/hooks/use-transform-workspace.ts b/apps/core/src/hooks/use-transform-workspace.ts similarity index 100% rename from apps/web/src/hooks/use-transform-workspace.ts rename to apps/core/src/hooks/use-transform-workspace.ts diff --git a/apps/web/src/hooks/use-workspace-blob.ts b/apps/core/src/hooks/use-workspace-blob.ts similarity index 100% rename from apps/web/src/hooks/use-workspace-blob.ts rename to apps/core/src/hooks/use-workspace-blob.ts diff --git a/apps/web/src/hooks/use-workspace.ts b/apps/core/src/hooks/use-workspace.ts similarity index 100% rename from apps/web/src/hooks/use-workspace.ts rename to apps/core/src/hooks/use-workspace.ts diff --git a/apps/web/src/hooks/use-workspaces.ts b/apps/core/src/hooks/use-workspaces.ts similarity index 100% rename from apps/web/src/hooks/use-workspaces.ts rename to apps/core/src/hooks/use-workspaces.ts diff --git a/apps/core/src/index.tsx b/apps/core/src/index.tsx new file mode 100644 index 000000000..8ac6ece92 --- /dev/null +++ b/apps/core/src/index.tsx @@ -0,0 +1,106 @@ +import { migrateToSubdoc } from '@affine/env/blocksuite'; +import { setupGlobal } from '@affine/env/global'; +import type { LocalIndexedDBDownloadProvider } from '@affine/env/workspace'; +import { WorkspaceFlavour, WorkspaceVersion } from '@affine/env/workspace'; +import { type WorkspaceAdapter } from '@affine/env/workspace'; +import type { RootWorkspaceMetadata } from '@affine/workspace/atom'; +import { workspaceAdaptersAtom } from '@affine/workspace/atom'; +import { + migrateLocalBlobStorage, + upgradeV1ToV2, +} from '@affine/workspace/migration'; +import { createIndexedDBDownloadProvider } from '@affine/workspace/providers'; +import { assertExists } from '@blocksuite/global/utils'; +import { rootStore } from '@toeverything/plugin-infra/manager'; +import { createRoot } from 'react-dom/client'; + +import { WorkspaceAdapters } from './adapters/workspace'; + +// bootstrap +setupGlobal(); + +rootStore.set( + workspaceAdaptersAtom, + WorkspaceAdapters as Record< + WorkspaceFlavour, + WorkspaceAdapter + > +); + +const value = localStorage.getItem('jotai-workspaces'); +if (value) { + try { + const metadata = JSON.parse(value) as RootWorkspaceMetadata[]; + const promises: Promise[] = []; + const newMetadata = [...metadata]; + metadata.forEach(oldMeta => { + if (!('version' in oldMeta)) { + const adapter = WorkspaceAdapters[oldMeta.flavour]; + assertExists(adapter); + const upgrade = async () => { + const workspace = await adapter.CRUD.get(oldMeta.id); + if (!workspace) { + console.warn('cannot find workspace', oldMeta.id); + return; + } + if (workspace.flavour !== WorkspaceFlavour.LOCAL) { + console.warn('not supported'); + return; + } + const doc = workspace.blockSuiteWorkspace.doc; + const provider = createIndexedDBDownloadProvider(workspace.id, doc, { + awareness: workspace.blockSuiteWorkspace.awarenessStore.awareness, + }) as LocalIndexedDBDownloadProvider; + provider.sync(); + await provider.whenReady; + const newDoc = migrateToSubdoc(doc); + if (doc === newDoc) { + console.log('doc not changed'); + return; + } + const newWorkspace = upgradeV1ToV2(workspace); + + const newId = await adapter.CRUD.create( + newWorkspace.blockSuiteWorkspace + ); + + await adapter.CRUD.delete(workspace as any); + console.log('migrated', oldMeta.id, newId); + const index = newMetadata.findIndex(meta => meta.id === oldMeta.id); + newMetadata[index] = { + ...oldMeta, + id: newId, + version: WorkspaceVersion.SubDoc, + }; + await migrateLocalBlobStorage(workspace.id, newId); + }; + + // create a new workspace and push it to metadata + promises.push(upgrade()); + } + }); + + Promise.all(promises) + .then(() => { + console.log('migration done'); + }) + .catch(() => { + console.error('migration failed'); + }) + .finally(() => { + localStorage.setItem('jotai-workspaces', JSON.stringify(newMetadata)); + window.dispatchEvent(new CustomEvent('migration-done')); + window.$migrationDone = true; + }); + } catch (e) { + console.error('error when migrating data', e); + } +} + +// start app +import('./app').then(({ App }) => { + const root = document.getElementById('app'); + assertExists(root); + + createRoot(root).render(); +}); diff --git a/apps/web/src/layouts/workspace-layout.tsx b/apps/core/src/layouts/workspace-layout.tsx similarity index 85% rename from apps/web/src/layouts/workspace-layout.tsx rename to apps/core/src/layouts/workspace-layout.tsx index 49b939dea..246e83c48 100644 --- a/apps/web/src/layouts/workspace-layout.tsx +++ b/apps/core/src/layouts/workspace-layout.tsx @@ -10,10 +10,7 @@ import { ToolContainer, WorkspaceFallback, } from '@affine/component/workspace'; -import { - DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX, - isDesktop, -} from '@affine/env/constant'; +import { DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX } from '@affine/env/constant'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { rootBlockHubAtom, @@ -38,10 +35,9 @@ import { currentWorkspaceIdAtom, } from '@toeverything/plugin-infra/manager'; import { useAtom, useAtomValue, useSetAtom } from 'jotai'; -import Head from 'next/head'; -import { useRouter } from 'next/router'; import type { FC, PropsWithChildren, ReactElement } from 'react'; import { lazy, Suspense, useCallback, useEffect, useMemo } from 'react'; +import { useLocation, useNavigate, useParams } from 'react-router-dom'; import { WorkspaceAdapters } from '../adapters/workspace'; import { @@ -49,7 +45,6 @@ import { openSettingModalAtom, openWorkspacesModalAtom, } from '../atoms'; -import { useTrackRouterHistoryEffect } from '../atoms/history'; import { useAppSetting } from '../atoms/settings'; import { AppContainer } from '../components/affine/app-container'; import type { IslandItemNames } from '../components/pure/help-island'; @@ -61,13 +56,12 @@ import { } from '../components/root-app-sidebar'; import { useBlockSuiteMetaHelper } from '../hooks/affine/use-block-suite-meta-helper'; import { useCurrentWorkspace } from '../hooks/current/use-current-workspace'; -import { useRouterHelper } from '../hooks/use-router-helper'; -import { useRouterTitle } from '../hooks/use-router-title'; +import { useNavigateHelper } from '../hooks/use-navigate-helper'; import { AllWorkspaceModals, CurrentWorkspaceModals, } from '../providers/modal-provider'; -import { pathGenerator, publicPathGenerator } from '../shared'; +import { pathGenerator } from '../shared'; import { toast } from '../utils'; const QuickSearchModal = lazy(() => @@ -82,7 +76,6 @@ function DefaultProvider({ children }: PropsWithChildren) { export const QuickSearch: FC = () => { const [currentWorkspace] = useCurrentWorkspace(); - const router = useRouter(); const [openQuickSearchModal, setOpenQuickSearchModalAtom] = useAtom( openQuickSearchModalAtom ); @@ -95,7 +88,6 @@ export const QuickSearch: FC = () => { workspace={currentWorkspace} open={openQuickSearchModal} setOpen={setOpenQuickSearchModalAtom} - router={router} /> ); }; @@ -109,35 +101,33 @@ if (globalThis.HALTING_PROBLEM_TIMEOUT === undefined) { globalThis.HALTING_PROBLEM_TIMEOUT = 1000; } +const showList: IslandItemNames[] = environment.isDesktop + ? ['whatNew', 'contact', 'guide'] + : ['whatNew', 'contact']; + export const CurrentWorkspaceContext = ({ children, }: PropsWithChildren): ReactElement => { const workspaceId = useAtomValue(currentWorkspaceIdAtom); const metadata = useAtomValue(rootWorkspacesMetadataAtom); const exist = metadata.find(m => m.id === workspaceId); - const router = useRouter(); - const push = router.push; + const navigate = useNavigate(); // fixme(himself65): this is not a good way to handle this, // need a better way to check whether this workspace really exist. useEffect(() => { const id = setTimeout(() => { if (!exist) { - push('/').catch(err => { - console.error(err); - }); + navigate('/'); globalThis.HALTING_PROBLEM_TIMEOUT <<= 1; } }, globalThis.HALTING_PROBLEM_TIMEOUT); return () => { clearTimeout(id); }; - }, [push, exist, metadata.length]); + }, [exist, metadata.length, navigate]); if (metadata.length === 0) { return ; } - if (!router.isReady) { - return ; - } if (!workspaceId) { return ; } @@ -149,7 +139,6 @@ export const CurrentWorkspaceContext = ({ export const WorkspaceLayout: FC = function WorkspacesSuspense({ children }) { - useTrackRouterHistoryEffect(); const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom); const jotaiWorkspaces = useAtomValue(rootWorkspacesMetadataAtom); const meta = useMemo( @@ -183,8 +172,7 @@ export const WorkspaceLayout: FC = export const WorkspaceLayoutInner: FC = ({ children }) => { const [currentWorkspace] = useCurrentWorkspace(); const [currentPageId, setCurrentPageId] = useAtom(currentPageIdAtom); - const router = useRouter(); - const { jumpToPage } = useRouterHelper(router); + const { jumpToPage, openPage } = useNavigateHelper(); usePassiveWorkspaceEffect(currentWorkspace.blockSuiteWorkspace); @@ -197,26 +185,15 @@ export const WorkspaceLayoutInner: FC = ({ children }) => { jumpOnce: false, }); setCurrentPageId(currentPageId); - jumpToPage(currentWorkspace.id, page.id).catch(err => { - console.error(err); - }); + jumpToPage(currentWorkspace.id, page.id); } - }, [ - currentPageId, - currentWorkspace, - jumpToPage, - router.query.pageId, - setCurrentPageId, - ]); + }, [currentPageId, currentWorkspace, jumpToPage, setCurrentPageId]); - const { openPage } = useRouterHelper(router); const [, setOpenWorkspacesModal] = useAtom(openWorkspacesModalAtom); const helper = useBlockSuiteWorkspaceHelper( currentWorkspace.blockSuiteWorkspace ); - const isPublicWorkspace = - router.pathname.split('/')[1] === 'public-workspace'; - const title = useRouterTitle(router); + const handleCreatePage = useCallback(() => { return helper.createPage(nanoid()); }, [helper]); @@ -257,10 +234,6 @@ export const WorkspaceLayoutInner: FC = ({ children }) => { ); const t = useAFFiNEI18N(); - const showList: IslandItemNames[] = isDesktop - ? ['whatNew', 'contact', 'guide'] - : ['whatNew', 'contact']; - const handleDragEnd = useCallback( (e: DragEndEvent) => { // Drag page into trash folder @@ -281,12 +254,11 @@ export const WorkspaceLayoutInner: FC = ({ children }) => { ); const [appSetting] = useAppSetting(); + const location = useLocation(); + const { pageId } = useParams(); return ( <> - - {title} - {/* This DndContext is used for drag page from all-pages list into a folder in sidebar */} = ({ children }) => { > = ({ children }) => { [currentWorkspace, openPage] )} createPage={handleCreatePage} - currentPath={router.asPath.split('?')[0]} - paths={isPublicWorkspace ? publicPathGenerator : pathGenerator} + currentPath={location.pathname.split('?')[0]} + paths={pathGenerator} /> {children} - {!isPublicWorkspace && ( - - )} + diff --git a/apps/web/src/pages/404.tsx b/apps/core/src/pages/404.tsx similarity index 58% rename from apps/web/src/pages/404.tsx rename to apps/core/src/pages/404.tsx index fbe0e5d23..0056aeb66 100644 --- a/apps/web/src/pages/404.tsx +++ b/apps/core/src/pages/404.tsx @@ -1,12 +1,9 @@ import { Button, displayFlex, styled } from '@affine/component'; import { WorkspaceSubPath } from '@affine/env/workspace'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; -import Head from 'next/head'; -import Image from 'next/legacy/image'; -import { useRouter } from 'next/router'; -import React from 'react'; +import type { ReactElement } from 'react'; -import { useRouterHelper } from '../hooks/use-router-helper'; +import { useNavigateHelper } from '../hooks/use-navigate-helper'; export const StyledContainer = styled('div')(() => { return { @@ -28,11 +25,10 @@ export const StyledContainer = styled('div')(() => { export const NotfoundPage = () => { const t = useAFFiNEI18N(); - const router = useRouter(); - const { jumpToSubPath } = useRouterHelper(router); + const { jumpToSubPath, jumpToIndex } = useNavigateHelper(); return ( - 404 + 404

{t['404 - Page Not Found']()}

- ); - return ( -
-
    - {ids.map(id => ( -
  • { - setId(id); - }} - key={id} - > - {id} -
  • - ))} -
- {writeIntoProductionNode} - {id && } -
- ); -}; - -export default function MigrationPage(): ReactElement { - return ( - - - - - - - - ); -} diff --git a/apps/web/src/pages/_document.tsx b/apps/web/src/pages/_document.tsx deleted file mode 100644 index f54e162d6..000000000 --- a/apps/web/src/pages/_document.tsx +++ /dev/null @@ -1,87 +0,0 @@ -import type { EmotionJSX } from '@emotion/react/types/jsx-namespace'; -import createEmotionServer from '@emotion/server/create-instance'; -import type { DocumentContext } from 'next/document'; -import Document, { Head, Html, Main, NextScript } from 'next/document'; -import * as React from 'react'; - -import createEmotionCache from '../utils/create-emotion-cache'; - -const description = - 'There can be more than Notion and Miro. AFFiNE is a next-gen knowledge base that brings planning, sorting and creating all together.'; - -export default class AppDocument extends Document<{ - emotionStyleTags: EmotionJSX.Element[]; -}> { - static override getInitialProps = async (ctx: DocumentContext) => { - const originalRenderPage = ctx.renderPage; - - const cache = createEmotionCache(); - const { extractCriticalToChunks } = createEmotionServer(cache); - - ctx.renderPage = () => - originalRenderPage({ - enhanceApp: (App: any) => - function EnhanceApp(props) { - return ; - }, - }); - - const initialProps = await Document.getInitialProps(ctx); - const emotionStyles = extractCriticalToChunks(initialProps.html); - const emotionStyleTags = emotionStyles.styles.map(style => ( -