diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 0000000000..f80d334591
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1,2 @@
+**/project.json @darkskygit
+**/pnpm-lock.yaml @darkskygit
diff --git a/packages/app/next.config.js b/packages/app/next.config.js
index 20f12e5770..6d7225864c 100644
--- a/packages/app/next.config.js
+++ b/packages/app/next.config.js
@@ -4,6 +4,11 @@ const { dependencies } = require('./package.json');
const path = require('node:path');
const printer = require('./scripts/printer').printer;
+const enableDebugLocal = path.isAbsolute(process.env.LOCAL_BLOCK_SUITE ?? '');
+const EDITOR_VERSION = enableDebugLocal
+ ? 'local-version'
+ : dependencies['@blocksuite/editor'];
+
/** @type {import('next').NextConfig} */
const nextConfig = {
productionBrowserSourceMaps: true,
@@ -16,7 +21,7 @@ const nextConfig = {
CI: process.env.CI || null,
VERSION: getGitVersion(),
COMMIT_HASH: getCommitHash(),
- EDITOR_VERSION: dependencies['@blocksuite/editor'],
+ EDITOR_VERSION,
},
webpack: config => {
config.experiments = { ...config.experiments, topLevelAwait: true };
@@ -63,11 +68,25 @@ const baseDir = process.env.LOCAL_BLOCK_SUITE ?? '/';
const withDebugLocal = require('next-debug-local')(
{
'@blocksuite/editor': path.resolve(baseDir, 'packages', 'editor'),
+ '@blocksuite/blocks/models': path.resolve(
+ baseDir,
+ 'packages',
+ 'blocks',
+ 'src',
+ 'models'
+ ),
+ '@blocksuite/blocks/std': path.resolve(
+ baseDir,
+ 'packages',
+ 'blocks',
+ 'src',
+ 'std'
+ ),
'@blocksuite/blocks': path.resolve(baseDir, 'packages', 'blocks'),
'@blocksuite/store': path.resolve(baseDir, 'packages', 'store'),
},
{
- enable: path.isAbsolute(process.env.LOCAL_BLOCK_SUITE ?? ''),
+ enable: enableDebugLocal,
}
);
diff --git a/packages/app/package.json b/packages/app/package.json
index 00b96a7fd1..ab9571a953 100644
--- a/packages/app/package.json
+++ b/packages/app/package.json
@@ -45,7 +45,7 @@
"@types/react": "18.0.20",
"@types/react-dom": "18.0.6",
"@types/wicg-file-system-access": "^2020.9.5",
- "chalk-next": "^6.1.5",
+ "chalk": "^4.1.2",
"eslint": "8.22.0",
"eslint-config-next": "12.3.1",
"eslint-config-prettier": "^8.5.0",
diff --git a/packages/app/src/components/404/index.tsx b/packages/app/src/components/404/index.tsx
index e2f828ad9f..7df644bbfe 100644
--- a/packages/app/src/components/404/index.tsx
+++ b/packages/app/src/components/404/index.tsx
@@ -1,9 +1,10 @@
import { NotFoundTitle, PageContainer } from './styles';
-
+import { useTranslation } from 'react-i18next';
export const NotfoundPage = () => {
+ const { t } = useTranslation();
return (
- 404 - Page Not Found
+ {t('404 - Page Not Found')}
);
};
diff --git a/packages/app/src/components/contact-modal/index.tsx b/packages/app/src/components/contact-modal/index.tsx
index a182f3e047..921b34ba65 100644
--- a/packages/app/src/components/contact-modal/index.tsx
+++ b/packages/app/src/components/contact-modal/index.tsx
@@ -23,7 +23,7 @@ import {
StyledModalFooter,
} from './style';
import bg from '@/components/contact-modal/bg.png';
-
+import { useTranslation } from 'react-i18next';
const linkList = [
{
icon: ,
@@ -51,27 +51,31 @@ const linkList = [
link: 'https://discord.gg/Arn7TqJBvG',
},
];
-const rightLinkList = [
- {
- icon: ,
- title: 'Official Website ',
- subTitle: 'AFFiNE.pro',
- link: 'https://affine.pro',
- },
- {
- icon: ,
- title: 'AFFiNE Community',
- subTitle: 'community.affine.pro',
- link: 'https://community.affine.pro',
- },
-];
type TransitionsModalProps = {
open: boolean;
onClose: () => void;
};
-export const ContactModal = ({ open, onClose }: TransitionsModalProps) => {
+export const ContactModal = ({
+ open,
+ onClose,
+}: TransitionsModalProps): JSX.Element => {
+ const { t } = useTranslation();
+ const rightLinkList = [
+ {
+ icon: ,
+ title: t('Official Website'),
+ subTitle: 'AFFiNE.pro',
+ link: 'https://affine.pro',
+ },
+ {
+ icon: ,
+ title: t('AFFiNE Community'),
+ subTitle: 'community.affine.pro',
+ link: 'https://community.affine.pro',
+ },
+ ];
return (
{
})}
- Get in touch!
+ {t('Get in touch!')}
{linkList.map(({ icon, title, link }) => {
return (
@@ -128,7 +132,7 @@ export const ContactModal = ({ open, onClose }: TransitionsModalProps) => {
target="_blank"
rel="noreferrer"
>
- How is AFFiNE Alpha different?
+ {t('How is AFFiNE Alpha different?')}
Copyright © 2022 Toeverything
diff --git a/packages/app/src/components/editor-mode-switch/index.tsx b/packages/app/src/components/editor-mode-switch/index.tsx
index 8a219e4757..86a54d8606 100644
--- a/packages/app/src/components/editor-mode-switch/index.tsx
+++ b/packages/app/src/components/editor-mode-switch/index.tsx
@@ -15,7 +15,7 @@ import { useTheme } from '@/providers/themeProvider';
import { EdgelessIcon, PaperIcon } from './icons';
import useCurrentPageMeta from '@/hooks/use-current-page-meta';
import { usePageHelper } from '@/hooks/use-page-helper';
-
+import { useTranslation } from 'react-i18next';
const PaperItem = ({ active }: { active?: boolean }) => {
const {
theme: {
@@ -96,7 +96,7 @@ export const EditorModeSwitch = ({
setRadioItemStatus(modifyRadioItemStatus());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isHover, mode]);
-
+ const { t } = useTranslation();
return (
}
active={mode === 'page'}
status={radioItemStatus.left}
@@ -126,7 +126,7 @@ export const EditorModeSwitch = ({
}
active={mode === 'edgeless'}
diff --git a/packages/app/src/components/header/header-right-items/editor-option-menu.tsx b/packages/app/src/components/header/header-right-items/editor-option-menu.tsx
index ea71aef757..cfd2813de5 100644
--- a/packages/app/src/components/header/header-right-items/editor-option-menu.tsx
+++ b/packages/app/src/components/header/header-right-items/editor-option-menu.tsx
@@ -16,12 +16,13 @@ import { usePageHelper } from '@/hooks/use-page-helper';
import { useConfirm } from '@/providers/confirm-provider';
import useCurrentPageMeta from '@/hooks/use-current-page-meta';
import { toast } from '@/ui/toast';
-
+import { useTranslation } from 'react-i18next';
const PopoverContent = () => {
const { editor } = useAppState();
const { toggleFavoritePage, toggleDeletePage } = usePageHelper();
const { changePageMode } = usePageHelper();
const { confirm } = useConfirm();
+ const { t } = useTranslation();
const {
mode = 'page',
id = '',
@@ -35,11 +36,13 @@ const PopoverContent = () => {
data-testid="editor-option-menu-favorite"
onClick={() => {
toggleFavoritePage(id);
- toast(!favorite ? 'Removed to Favourites' : 'Added to Favourites');
+ toast(
+ favorite ? t('Removed from Favourites') : t('Added to Favourites')
+ );
}}
icon={favorite ? : }
>
- {favorite ? 'Remove' : 'Add'} to favourites
+ {favorite ? t('Remove from favourites') : t('Add to favourites')}
: }
@@ -48,7 +51,8 @@ const PopoverContent = () => {
changePageMode(id, mode === 'page' ? 'edgeless' : 'page');
}}
>
- Convert to {mode === 'page' ? 'Edgeless' : 'Page'}
+ {t('Convert to ')}
+ {mode === 'page' ? t('Edgeless') : t('Page')}
>
);
diff --git a/packages/app/src/components/header/quick-search-button.tsx b/packages/app/src/components/header/quick-search-button.tsx
index a08c61bf65..e45e78fed4 100644
--- a/packages/app/src/components/header/quick-search-button.tsx
+++ b/packages/app/src/components/header/quick-search-button.tsx
@@ -3,15 +3,15 @@ import { IconButton, IconButtonProps } from '@/ui/button';
import { Tooltip } from '@/ui/tooltip';
import { ArrowDownIcon } from '@blocksuite/icons';
import { useModal } from '@/providers/global-modal-provider';
-
+import { useTranslation } from 'react-i18next';
export const QuickSearchButton = ({
onClick,
...props
}: Omit) => {
const { triggerQuickSearchModal } = useModal();
-
+ const { t } = useTranslation();
return (
-
+
{showList.includes('contact') && (
-
+
)}
{showList.includes('shortcuts') && (
-
+
{
const [status, setStatus] = useState<'unImported' | 'importing'>('importing');
const { openPage, createPage } = usePageHelper();
const { currentWorkspace } = useAppState();
+ const { t } = useTranslation();
const _applyTemplate = function (pageId: string, template: Template) {
const page = currentWorkspace?.getPage(pageId);
@@ -84,7 +86,7 @@ export const ImportModal = ({ open, onClose }: ImportModalProps) => {
- Import
+ {t('Import')}
{status === 'unImported' && (
diff --git a/packages/app/src/components/page-list/index.tsx b/packages/app/src/components/page-list/index.tsx
index f63fa39944..604d71000f 100644
--- a/packages/app/src/components/page-list/index.tsx
+++ b/packages/app/src/components/page-list/index.tsx
@@ -24,7 +24,7 @@ import { useAppState } from '@/providers/app-state-provider/context';
import { toast } from '@/ui/toast';
import { usePageHelper } from '@/hooks/use-page-helper';
import { useTheme } from '@/providers/themeProvider';
-
+import { useTranslation } from 'react-i18next';
const FavoriteTag = ({
pageMeta: { favorite, id },
}: {
@@ -32,9 +32,10 @@ const FavoriteTag = ({
}) => {
const { toggleFavoritePage } = usePageHelper();
const { theme } = useTheme();
+ const { t } = useTranslation();
return (
{
e.stopPropagation();
toggleFavoritePage(id);
- toast(!favorite ? 'Removed to Favourites' : 'Added to Favourites');
+ toast(
+ favorite ? t('Removed from Favourites') : t('Added to Favourites')
+ );
}}
style={{
color: favorite ? theme.colors.primaryColor : theme.colors.iconColor,
@@ -71,6 +74,7 @@ export const PageList = ({
}) => {
const router = useRouter();
const { currentWorkspaceId } = useAppState();
+ const { t } = useTranslation();
if (pageList.length === 0) {
return ;
}
@@ -80,10 +84,10 @@ export const PageList = ({
- Title
- Created
+ {t('Title')}
+ {t('Created')}
- {isTrash ? 'Moved to Trash' : 'Updated'}
+ {isTrash ? t('Moved to Trash') : t('Updated')}
@@ -108,7 +112,7 @@ export const PageList = ({
)}
- {pageMeta.title || 'Untitled'}
+ {pageMeta.title || t('Untitled')}
{showFavoriteTag && }
diff --git a/packages/app/src/components/page-list/operation-cell.tsx b/packages/app/src/components/page-list/operation-cell.tsx
index 7416b65d9a..1b4ec7434a 100644
--- a/packages/app/src/components/page-list/operation-cell.tsx
+++ b/packages/app/src/components/page-list/operation-cell.tsx
@@ -14,23 +14,25 @@ import {
} from '@blocksuite/icons';
import { toast } from '@/ui/toast';
import { usePageHelper } from '@/hooks/use-page-helper';
-
+import { useTranslation } from 'react-i18next';
export const OperationCell = ({ pageMeta }: { pageMeta: PageMeta }) => {
const { id, favorite } = pageMeta;
const { openPage } = usePageHelper();
const { toggleFavoritePage, toggleDeletePage } = usePageHelper();
const { confirm } = useConfirm();
-
+ const { t } = useTranslation();
const OperationMenu = (
<>
>
);
@@ -74,7 +78,7 @@ export const TrashOperationCell = ({ pageMeta }: { pageMeta: PageMeta }) => {
const { openPage, getPageMeta } = usePageHelper();
const { toggleDeletePage, permanentlyDeletePage } = usePageHelper();
const { confirm } = useConfirm();
-
+ const { t } = useTranslation();
return (
{
style={{ marginRight: '12px' }}
onClick={() => {
toggleDeletePage(id);
- toast(`${getPageMeta(id)?.title || 'Untitled'} restored`);
+ toast(t('restored', { title: getPageMeta(id)?.title || 'Untitled' }));
openPage(id);
}}
>
@@ -92,13 +96,13 @@ export const TrashOperationCell = ({ pageMeta }: { pageMeta: PageMeta }) => {
darker={true}
onClick={() => {
confirm({
- title: 'Delete permanently?',
- content: "Once deleted, you can't undo this action.",
- confirmText: 'Delete',
+ title: t('Delete permanently?'),
+ content: t("Once deleted, you can't undo this action."),
+ confirmText: t('Delete'),
confirmType: 'danger',
}).then(confirm => {
confirm && permanentlyDeletePage(id);
- toast('Permanently deleted');
+ toast(t('Permanently deleted'));
});
}}
>
diff --git a/packages/app/src/components/quick-search/config.ts b/packages/app/src/components/quick-search/config.ts
index 7c5b8afe72..c35636c3cc 100644
--- a/packages/app/src/components/quick-search/config.ts
+++ b/packages/app/src/components/quick-search/config.ts
@@ -1,21 +1,29 @@
import { AllPagesIcon, FavouritesIcon, TrashIcon } from '@blocksuite/icons';
+import { useTranslation } from 'react-i18next';
-export const config = (currentWorkspaceId: string) => {
+export const useSwitchToConfig = (
+ currentWorkspaceId: string
+): {
+ title: string;
+ href: string;
+ icon: React.FC>;
+}[] => {
+ const { t } = useTranslation();
const List = [
{
- title: 'All pages',
+ title: t('All pages'),
href: currentWorkspaceId ? `/workspace/${currentWorkspaceId}/all` : '',
icon: AllPagesIcon,
},
{
- title: 'Favourites',
+ title: t('Favourites'),
href: currentWorkspaceId
? `/workspace/${currentWorkspaceId}/favorite`
: '',
icon: FavouritesIcon,
},
{
- title: 'Trash',
+ title: t('Trash'),
href: currentWorkspaceId ? `/workspace/${currentWorkspaceId}/trash` : '',
icon: TrashIcon,
},
diff --git a/packages/app/src/components/quick-search/footer.tsx b/packages/app/src/components/quick-search/footer.tsx
index 5f03b6c85e..48914cda73 100644
--- a/packages/app/src/components/quick-search/footer.tsx
+++ b/packages/app/src/components/quick-search/footer.tsx
@@ -4,10 +4,11 @@ import { StyledModalFooterContent } from './style';
import { useModal } from '@/providers/global-modal-provider';
import { Command } from 'cmdk';
import { usePageHelper } from '@/hooks/use-page-helper';
-
+import { useTranslation } from 'react-i18next';
export const Footer = (props: { query: string }) => {
const { triggerQuickSearchModal } = useModal();
const { openPage, createPage } = usePageHelper();
+ const { t } = useTranslation();
const query = props.query;
return (
@@ -25,9 +26,9 @@ export const Footer = (props: { query: string }) => {
{query ? (
- New "{query}" page
+ {t('New Keyword Page', { query: query })}
) : (
- New page
+ {t('New Page')}
)}
diff --git a/packages/app/src/components/quick-search/results.tsx b/packages/app/src/components/quick-search/results.tsx
index 2a99e389ff..eeb9fc2d44 100644
--- a/packages/app/src/components/quick-search/results.tsx
+++ b/packages/app/src/components/quick-search/results.tsx
@@ -5,8 +5,9 @@ import { PaperIcon, EdgelessIcon } from '@blocksuite/icons';
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { useAppState } from '@/providers/app-state-provider';
import { useRouter } from 'next/router';
-import { config } from './config';
+import { useSwitchToConfig } from './config';
import { NoResultSVG } from './noResultSVG';
+import { useTranslation } from 'react-i18next';
import usePageHelper from '@/hooks/use-page-helper';
import usePageMetaList from '@/hooks/use-page-meta-list';
export const Results = (props: {
@@ -25,8 +26,9 @@ export const Results = (props: {
const router = useRouter();
const { currentWorkspaceId } = useAppState();
const { search } = usePageHelper();
- const List = config(currentWorkspaceId);
+ const List = useSwitchToConfig(currentWorkspaceId);
const [results, setResults] = useState(new Map());
+ const { t } = useTranslation();
useEffect(() => {
setResults(search(query));
setLoading(false);
@@ -47,7 +49,9 @@ export const Results = (props: {
<>
{query ? (
resultsPageMeta.length ? (
-
+
{resultsPageMeta.map(result => {
return (
) : (
- Find 0 result
+ {t('Find 0 result')}
)
) : (
-
+
{List.map(link => {
return (
{
+ const { t } = useTranslation();
+ return {
+ [t('Undo')]: '⌘+Z',
+ [t('Redo')]: '⌘+⇧+Z',
+ [t('Bold')]: '⌘+B',
+ [t('Italic')]: '⌘+I',
+ [t('Underline')]: '⌘+U',
+ [t('Strikethrough')]: '⌘+⇧+S',
+ [t('Inline code')]: ' ⌘+E',
+ [t('Code block')]: '⌘+⌥+C',
+ [t('Link')]: '⌘+K',
+ [t('Body text')]: '⌘+⌥+0',
+ [t('Heading', { number: '1' })]: '⌘+⌥+1',
+ [t('Heading', { number: '2' })]: '⌘+⌥+2',
+ [t('Heading', { number: '3' })]: '⌘+⌥+3',
+ [t('Heading', { number: '4' })]: '⌘+⌥+4',
+ [t('Heading', { number: '5' })]: '⌘+⌥+5',
+ [t('Heading', { number: '6' })]: '⌘+⌥+6',
+ [t('Increase indent')]: 'Tab',
+ [t('Reduce indent')]: '⇧+Tab',
+ };
};
-export const macMarkdownShortcuts = {
- Bold: '**Text** ',
- Italic: '*Text* ',
- Underline: '~Text~ ',
- Strikethrough: '~~Text~~ ',
- Divider: '***',
- 'Inline code': '`Text` ',
- 'Code block': '``` Space',
- 'Heading 1': '# Text',
- 'Heading 2': '## Text',
- 'Heading 3': '### Text',
- 'Heading 4': '#### Text',
- 'Heading 5': '##### Text',
- 'Heading 6': '###### Text',
+export const useMacMarkdownShortcuts = (): ShortcutTip => {
+ const { t } = useTranslation();
+ return {
+ [t('Bold')]: '**Text** ',
+ [t('Italic')]: '*Text* ',
+ [t('Underline')]: '~Text~ ',
+ [t('Strikethrough')]: '~~Text~~ ',
+ [t('Divider')]: '***',
+ [t('Inline code')]: '`Text` ',
+ [t('Code block')]: '``` Space',
+ [t('Heading', { number: '1' })]: '# Text',
+ [t('Heading', { number: '2' })]: '## Text',
+ [t('Heading', { number: '3' })]: '### Text',
+ [t('Heading', { number: '4' })]: '#### Text',
+ [t('Heading', { number: '5' })]: '##### Text',
+ [t('Heading', { number: '6' })]: '###### Text',
+ };
};
-export const windowsKeyboardShortcuts = {
- Undo: 'Ctrl+Z',
- Redo: 'Ctrl+Y',
- Bold: 'Ctrl+B',
- Italic: 'Ctrl+I',
- Underline: 'Ctrl+U',
- Strikethrough: 'Ctrl+Shift+S',
- 'Inline code': ' Ctrl+E',
- 'Code block': 'Ctrl+Alt+C',
- Link: 'Ctrl+K',
- 'Body text': 'Ctrl+Shift+0',
- 'Heading 1': 'Ctrl+Shift+1',
- 'Heading 2': 'Ctrl+Shift+2',
- 'Heading 3': 'Ctrl+Shift+3',
- 'Heading 4': 'Ctrl+Shift+4',
- 'Heading 5': 'Ctrl+Shift+5',
- 'Heading 6': 'Ctrl+Shift+6',
- 'Increase indent': 'Tab',
- 'Reduce indent': 'Shift+Tab',
+export const useWindowsKeyboardShortcuts = (): ShortcutTip => {
+ const { t } = useTranslation();
+ return {
+ [t('Undo')]: 'Ctrl+Z',
+ [t('Redo')]: 'Ctrl+Y',
+ [t('Bold')]: 'Ctrl+B',
+ [t('Italic')]: 'Ctrl+I',
+ [t('Underline')]: 'Ctrl+U',
+ [t('Strikethrough')]: 'Ctrl+Shift+S',
+ [t('Inline code')]: ' Ctrl+E',
+ [t('Code block')]: 'Ctrl+Alt+C',
+ [t('Link')]: 'Ctrl+K',
+ [t('Body text')]: 'Ctrl+Shift+0',
+ [t('Heading', { number: '1' })]: 'Ctrl+Shift+1',
+ [t('Heading', { number: '2' })]: 'Ctrl+Shift+2',
+ [t('Heading', { number: '3' })]: 'Ctrl+Shift+3',
+ [t('Heading', { number: '4' })]: 'Ctrl+Shift+4',
+ [t('Heading', { number: '5' })]: 'Ctrl+Shift+5',
+ [t('Heading', { number: '6' })]: 'Ctrl+Shift+6',
+ [t('Increase indent')]: 'Tab',
+ [t('Reduce indent')]: 'Shift+Tab',
+ };
};
-export const winMarkdownShortcuts = {
- Bold: '**Text** ',
- Italic: '*Text* ',
- Underline: '~Text~ ',
- Strikethrough: '~~Text~~ ',
- 'Inline code': '`Text` ',
- 'Code block': '``` Text',
- 'Heading 1': '# Text',
- 'Heading 2': '## Text',
- 'Heading 3': '### Text',
- 'Heading 4': '#### Text',
- 'Heading 5': '##### Text',
- 'Heading 6': '###### Text',
+export const useWinMarkdownShortcuts = (): ShortcutTip => {
+ const { t } = useTranslation();
+ return {
+ [t('Bold')]: '**Text** ',
+ [t('Italic')]: '*Text* ',
+ [t('Underline')]: '~Text~ ',
+ [t('Strikethrough')]: '~~Text~~ ',
+ [t('Divider')]: '***',
+ [t('Inline code')]: '`Text` ',
+ [t('Code block')]: '``` Text',
+ [t('Heading', { number: '1' })]: '# Text',
+ [t('Heading', { number: '2' })]: '## Text',
+ [t('Heading', { number: '3' })]: '### Text',
+ [t('Heading', { number: '4' })]: '#### Text',
+ [t('Heading', { number: '5' })]: '##### Text',
+ [t('Heading', { number: '6' })]: '###### Text',
+ };
};
diff --git a/packages/app/src/components/shortcuts-modal/index.tsx b/packages/app/src/components/shortcuts-modal/index.tsx
index 63a4246d64..4f28b0ecec 100644
--- a/packages/app/src/components/shortcuts-modal/index.tsx
+++ b/packages/app/src/components/shortcuts-modal/index.tsx
@@ -8,14 +8,15 @@ import {
StyledTitle,
} from './style';
import {
- macKeyboardShortcuts,
- macMarkdownShortcuts,
- windowsKeyboardShortcuts,
- winMarkdownShortcuts,
+ useMacKeyboardShortcuts,
+ useMacMarkdownShortcuts,
+ useWindowsKeyboardShortcuts,
+ useWinMarkdownShortcuts,
} from '@/components/shortcuts-modal/config';
import Slide from '@mui/material/Slide';
import { ModalCloseButton } from '@/ui/modal';
import { getUaHelper } from '@/utils';
+import { useTranslation } from 'react-i18next';
type ModalProps = {
open: boolean;
onClose: () => void;
@@ -26,12 +27,18 @@ const isMac = () => {
};
export const ShortcutsModal = ({ open, onClose }: ModalProps) => {
+ const { t } = useTranslation();
+ const macMarkdownShortcuts = useMacMarkdownShortcuts();
+ const winMarkdownShortcuts = useWinMarkdownShortcuts();
+ const macKeyboardShortcuts = useMacKeyboardShortcuts();
+ const windowsKeyboardShortcuts = useWindowsKeyboardShortcuts();
const markdownShortcuts = isMac()
? macMarkdownShortcuts
: winMarkdownShortcuts;
const keyboardShortcuts = isMac()
? macKeyboardShortcuts
: windowsKeyboardShortcuts;
+
return createPortal(
@@ -39,7 +46,7 @@ export const ShortcutsModal = ({ open, onClose }: ModalProps) => {
- Shortcuts
+ {t('Shortcuts')}
{
/>
- Keyboard Shortcuts
+ {t('Keyboard Shortcuts')}
{Object.entries(keyboardShortcuts).map(([title, shortcuts]) => {
return (
@@ -63,7 +70,7 @@ export const ShortcutsModal = ({ open, onClose }: ModalProps) => {
);
})}
- Markdown Syntax
+ {t('Markdown Syntax')}
{Object.entries(markdownShortcuts).map(([title, shortcuts]) => {
return (
diff --git a/packages/app/src/components/workspace-slider-bar/index.tsx b/packages/app/src/components/workspace-slider-bar/index.tsx
index b9132fab52..8b96df83cf 100644
--- a/packages/app/src/components/workspace-slider-bar/index.tsx
+++ b/packages/app/src/components/workspace-slider-bar/index.tsx
@@ -27,18 +27,18 @@ import Link from 'next/link';
import { Tooltip } from '@/ui/tooltip';
import { useModal } from '@/providers/global-modal-provider';
import { useAppState } from '@/providers/app-state-provider/context';
-
import { IconButton } from '@/ui/button';
import useLocalStorage from '@/hooks/use-local-storage';
import usePageMetaList from '@/hooks/use-page-meta-list';
import { usePageHelper } from '@/hooks/use-page-helper';
import { WorkspaceSetting } from '@/components/workspace-setting';
+import { useTranslation } from 'react-i18next';
const FavoriteList = ({ showList }: { showList: boolean }) => {
const { openPage } = usePageHelper();
const pageList = usePageMetaList();
const router = useRouter();
-
+ const { t } = useTranslation();
const favoriteList = pageList.filter(p => p.favorite && !p.trash);
return (
@@ -61,7 +61,7 @@ const FavoriteList = ({ showList }: { showList: boolean }) => {
);
})}
{favoriteList.length === 0 && (
- No item
+ {t('No item')}
)}
);
@@ -72,7 +72,7 @@ export const WorkSpaceSliderBar = () => {
const { currentWorkspaceId } = useAppState();
const { openPage, createPage } = usePageHelper();
const router = useRouter();
-
+ const { t } = useTranslation();
const [showTip, setShowTip] = useState(false);
const [show, setShow] = useLocalStorage('AFFiNE_SLIDE_BAR', false, true);
@@ -90,7 +90,7 @@ export const WorkSpaceSliderBar = () => {
<>
@@ -124,17 +124,17 @@ export const WorkSpaceSliderBar = () => {
}}
>
- Quick search
+ {t('Quick search')}
- All pages
+ {t('All pages')}
- Favourites
+ {t('Favourites')}
{
triggerImportModal();
}}
>
- Import
+ {t('Import')}
- Trash
+ {t('Trash')}
{
}
}}
>
- New Page
+ {t('New Page')}
diff --git a/packages/app/src/libs/i18n/resources/en.json b/packages/app/src/libs/i18n/resources/en.json
index c2716448f7..9ce5282e71 100644
--- a/packages/app/src/libs/i18n/resources/en.json
+++ b/packages/app/src/libs/i18n/resources/en.json
@@ -1,28 +1,65 @@
{
- "Sync to Disk": "Sync to Disk",
- "Share": "Share",
- "WarningTips": {
- "IsNotfsApiSupported": "Welcome to the AFFiNE demo. To begin saving changes you can SYNC DATA TO DISK with the latest version of Chromium based browser like Chrome/Edge",
- "IsNotLocalWorkspace": "Welcome to the AFFiNE demo. To begin saving changes you can SYNC TO DISK.",
- "DoNotStore": "AFFiNE is under active development and the current version is UNSTABLE. Please DO NOT store information or data"
- },
- "Layout": "Layout",
- "Comment": "Comment",
- "Settings": "Settings",
- "ComingSoon": "Layout Settings Coming Soon...",
- "Duplicate Page": "Duplicate Page",
- "Copy Page Link": "Copy Page Link",
- "Language": "Language",
- "Clear Workspace": "Clear Workspace",
- "Export As Markdown": "Export As Markdown",
- "Export As HTML": "Export As HTML",
- "Export As PDF (Unsupported)": "Export As PDF (Unsupported)",
- "Import Workspace": "Import Workspace",
- "Export Workspace": "Export Workspace",
- "Last edited by": "Last edited by {{name}}",
- "Logout": "Logout",
+ "Quick search": "Quick search",
+ "All pages": "All pages",
+ "Favourites": "Favourites",
+ "No item": "No item",
+ "Import": "Import",
+ "Trash": "Trash",
+ "New Page": "New Page",
+ "New Keyword Page": "New '{{query}}' page",
+ "Find 0 result": "Find 0 result",
+ "Find results": "Find {{number}} results",
+ "Collapse sidebar": "Collapse sidebar",
+ "Expand sidebar": "Expand sidebar",
+ "Removed from Favourites": "Removed from Favourites",
+ "Remove from favourites": "Remove from favourites",
+ "Added to Favourites": "Added to Favourites",
+ "Add to favourites": "Add to favourites",
+ "Paper": "Paper",
+ "Edgeless": "Edgeless",
+ "Switch to": "Switch to",
+ "Convert to ": "Convert to ",
+ "Page": "Page",
+ "Export": "Export",
+ "Export to HTML": "Export to HTML",
+ "Export to Markdown": "Export to Markdown",
"Delete": "Delete",
- "Turn into": "Turn into",
- "Add A Below Block": "Add A Below Block",
- "Divide Here As A New Group": "Divide Here As A New Group"
+ "Title": "Title",
+ "Untitled": "Untitled",
+ "Created": "Created",
+ "Updated": "Updated",
+ "Open in new tab": "Open in new tab",
+ "Favourite": "Favourite",
+ "Favourited": "Favourited",
+ "Delete page?": "Delete page?",
+ "Delete permanently?": "Delete permanently?",
+ "will be moved to Trash": "{{title}} will be moved to Trash",
+ "Once deleted, you can't undo this action.": "Once deleted,you can't undo this action.",
+ "Moved to Trash": "Moved to Trash",
+ "Permanently deleted": "Permanently deleted",
+ "restored": "{{title}} restored",
+ "Cancel": "Cancel",
+ "Keyboard Shortcuts": "Keyboard Shortcuts",
+ "Contact Us": "Contact Us",
+ "Official Website": "Official Website",
+ "Get in touch!": "Get in touch!",
+ "AFFiNE Community": "AFFiNE Community",
+ "How is AFFiNE Alpha different?": "How is AFFiNE Alpha different?",
+ "Shortcuts": "Shortcuts",
+ "Undo": "Undo",
+ "Redo": "Redo",
+ "Bold": "Bold",
+ "Italic": "Italic",
+ "Underline": "Underline",
+ "Strikethrough": "Strikethrough",
+ "Inline code": "Inline code",
+ "Code block": "Code block",
+ "Link": "Link",
+ "Body text": "Body text",
+ "Heading": "Heading {{number}}",
+ "Increase indent": "Increase indent",
+ "Reduce indent": "Reduce indent",
+ "Markdown Syntax": "Markdown Syntax",
+ "Divider": "Divider",
+ "404 - Page Not Found": "404 - Page Not Found"
}
diff --git a/packages/app/src/pages/_app.tsx b/packages/app/src/pages/_app.tsx
index bb56e9acef..c7cbd78d4b 100644
--- a/packages/app/src/pages/_app.tsx
+++ b/packages/app/src/pages/_app.tsx
@@ -18,6 +18,7 @@ import { useEffect } from 'react';
import { useAppState } from '@/providers/app-state-provider';
import { PageLoading } from '@/components/loading';
import Head from 'next/head';
+import '@/libs/i18n';
const ThemeProvider = dynamic(() => import('@/providers/themeProvider'), {
ssr: false,
diff --git a/packages/app/src/pages/workspace/[workspaceId]/all.tsx b/packages/app/src/pages/workspace/[workspaceId]/all.tsx
index dacb16bd59..18f6e2a64b 100644
--- a/packages/app/src/pages/workspace/[workspaceId]/all.tsx
+++ b/packages/app/src/pages/workspace/[workspaceId]/all.tsx
@@ -4,13 +4,13 @@ import usePageMetaList from '@/hooks/use-page-meta-list';
import { PageListHeader } from '@/components/header';
import { ReactElement } from 'react';
import WorkspaceLayout from '@/components/workspace-layout';
-
+import { useTranslation } from 'react-i18next';
const All = () => {
const pageMetaList = usePageMetaList();
-
+ const { t } = useTranslation();
return (
<>
- }>All Page
+ }>{t('All pages')}
!p.trash)}
showFavoriteTag={true}
diff --git a/packages/app/src/pages/workspace/[workspaceId]/favorite.tsx b/packages/app/src/pages/workspace/[workspaceId]/favorite.tsx
index bde04923d6..d787f34e1b 100644
--- a/packages/app/src/pages/workspace/[workspaceId]/favorite.tsx
+++ b/packages/app/src/pages/workspace/[workspaceId]/favorite.tsx
@@ -4,12 +4,15 @@ import { FavouritesIcon } from '@blocksuite/icons';
import usePageMetaList from '@/hooks/use-page-meta-list';
import { ReactElement } from 'react';
import WorkspaceLayout from '@/components/workspace-layout';
-
+import { useTranslation } from 'react-i18next';
export const Favorite = () => {
const pageMetaList = usePageMetaList();
+ const { t } = useTranslation();
return (
<>
- }>Favourites
+ }>
+ {t('Favourites')}
+
p.favorite && !p.trash)} />
>
);
diff --git a/packages/app/src/pages/workspace/[workspaceId]/trash.tsx b/packages/app/src/pages/workspace/[workspaceId]/trash.tsx
index 9e7f397669..2343b39138 100644
--- a/packages/app/src/pages/workspace/[workspaceId]/trash.tsx
+++ b/packages/app/src/pages/workspace/[workspaceId]/trash.tsx
@@ -4,12 +4,13 @@ import { TrashIcon } from '@blocksuite/icons';
import usePageMetaList from '@/hooks/use-page-meta-list';
import { ReactElement } from 'react';
import WorkspaceLayout from '@/components/workspace-layout';
-
+import { useTranslation } from 'react-i18next';
export const Trash = () => {
const pageMetaList = usePageMetaList();
+ const { t } = useTranslation();
return (
<>
- }>Trash
+ }>{t('Trash')}
p.trash)} isTrash={true} />
>
);
diff --git a/packages/app/src/templates/Welcome-to-AFFiNE-Alpha-v2.0.md b/packages/app/src/templates/Welcome-to-AFFiNE-Alpha-v2.0.md
index 8493d51149..e0fc661340 100644
--- a/packages/app/src/templates/Welcome-to-AFFiNE-Alpha-v2.0.md
+++ b/packages/app/src/templates/Welcome-to-AFFiNE-Alpha-v2.0.md
@@ -27,7 +27,7 @@ Let us know what you think of this latest version.
### Playground:
-[] Try a horiztaonl line: `---`
+[] Try a horizontal line: `---`
[] What about a code block? ```
diff --git a/packages/app/src/ui/confirm/Confirm.tsx b/packages/app/src/ui/confirm/Confirm.tsx
index 7b789c4f89..872a43624e 100644
--- a/packages/app/src/ui/confirm/Confirm.tsx
+++ b/packages/app/src/ui/confirm/Confirm.tsx
@@ -7,6 +7,7 @@ import {
StyledModalWrapper,
} from '@/ui/confirm/styles';
import { Button } from '@/ui/button';
+import { useTranslation } from 'react-i18next';
export type ConfirmProps = {
title?: string;
content?: string;
@@ -28,6 +29,7 @@ export const Confirm = ({
cancelText = 'Cancel',
}: ConfirmProps) => {
const [open, setOpen] = useState(true);
+ const { t } = useTranslation();
return (
diff --git a/packages/data-center/src/apis/token.ts b/packages/data-center/src/apis/token.ts
index b0acf68ee3..c509da0f33 100644
--- a/packages/data-center/src/apis/token.ts
+++ b/packages/data-center/src/apis/token.ts
@@ -60,7 +60,9 @@ class Token {
}
async initToken(token: string) {
- this._setToken(await login({ token, type: 'Google' }));
+ const tokens = await login({ token, type: 'Google' });
+ this._setToken(tokens);
+ return this._user;
}
async refreshToken(token?: string) {
@@ -153,10 +155,27 @@ export const getAuthorizer = () => {
const googleAuthProvider = new GoogleAuthProvider();
+ const getToken = async () => {
+ const currentUser = firebaseAuth.currentUser;
+ if (currentUser) {
+ await currentUser.getIdTokenResult(true);
+ if (!currentUser.isAnonymous) {
+ return currentUser.getIdToken();
+ }
+ }
+ return;
+ };
+
const signInWithGoogle = async () => {
- const user = await signInWithPopup(firebaseAuth, googleAuthProvider);
- const idToken = await user.user.getIdToken();
- await token.initToken(idToken);
+ const idToken = await getToken();
+ if (idToken) {
+ await token.initToken(idToken);
+ } else {
+ const user = await signInWithPopup(firebaseAuth, googleAuthProvider);
+ const idToken = await user.user.getIdToken();
+ await token.initToken(idToken);
+ }
+ return firebaseAuth.currentUser;
};
const onAuthStateChanged = (callback: (user: User | null) => void) => {
diff --git a/packages/data-center/src/datacenter.ts b/packages/data-center/src/datacenter.ts
index 62edea334d..3e31e9f1d8 100644
--- a/packages/data-center/src/datacenter.ts
+++ b/packages/data-center/src/datacenter.ts
@@ -1,6 +1,6 @@
import assert from 'assert';
import { BlockSchema } from '@blocksuite/blocks/models';
-import { Workspace } from '@blocksuite/store';
+import { Workspace, Signal } from '@blocksuite/store';
import { getLogger } from './index.js';
import { getApis, Apis } from './apis/index.js';
@@ -16,6 +16,17 @@ type LoadConfig = {
config?: Record;
};
+export type DataCenterSignals = DataCenter['signals'];
+type WorkspaceItem = {
+ // provider id
+ provider: string;
+ // data exists locally
+ locally: boolean;
+};
+type WorkspaceLoadEvent = WorkspaceItem & {
+ workspace: string;
+};
+
export class DataCenter {
private readonly _apis: Apis;
private readonly _providers = new Map();
@@ -23,6 +34,11 @@ export class DataCenter {
private readonly _config;
private readonly _logger;
+ readonly signals = {
+ listAdd: new Signal(),
+ listRemove: new Signal(),
+ };
+
static async init(debug: boolean): Promise {
const dc = new DataCenter(debug);
dc.addProvider(AffineProvider);
@@ -36,6 +52,16 @@ export class DataCenter {
this._config = getKVConfigure('sys');
this._logger = getLogger('dc');
this._logger.enabled = debug;
+
+ this.signals.listAdd.on(e => {
+ this._config.set(`list:${e.workspace}`, {
+ provider: e.provider,
+ locally: e.locally,
+ });
+ });
+ this.signals.listRemove.on(workspace => {
+ this._config.delete(`list:${workspace}`);
+ });
}
get apis(): Readonly {
@@ -86,9 +112,9 @@ export class DataCenter {
await provider.init({
apis: this._apis,
config,
- globalConfig: getKVConfigure(`provider:${providerId}`),
debug: this._logger.enabled,
logger: this._logger.extend(`${Provider.id}:${id}`),
+ signals: this.signals,
workspace,
});
await provider.initData();
@@ -97,6 +123,21 @@ export class DataCenter {
return provider;
}
+ async auth(providerId: string, globalConfig?: Record) {
+ const Provider = this._providers.get(providerId);
+ if (Provider) {
+ // initial configurator
+ const config = getKVConfigure(`provider:${providerId}`);
+ // set workspace configs
+ const values = Object.entries(globalConfig || {});
+ if (values.length) await config.setMany(values);
+
+ const logger = this._logger.extend(`auth:${providerId}`);
+ logger.enabled = this._logger.enabled;
+ await Provider.auth(config, logger, this.signals);
+ }
+ }
+
/**
* load workspace data to memory
* @param workspaceId workspace id
@@ -154,21 +195,14 @@ export class DataCenter {
* data state is also map, the key is the provider id, and the data exists locally when the value is true, otherwise it does not exist
*/
async list(): Promise>> {
- const lists = await Promise.all(
- Array.from(this._providers.entries()).map(([providerId, provider]) =>
- provider
- .list(getKVConfigure(`provider:${providerId}`))
- .then(list => [providerId, list || []] as const)
- )
- );
-
- return lists.reduce((ret, [providerId, list]) => {
- for (const [item, isLocal] of list) {
- const workspace = ret[item] || {};
- workspace[providerId] = isLocal;
- ret[item] = workspace;
+ const entries: [string, WorkspaceItem][] = await this._config.entries();
+ return entries.reduce((acc, [k, i]) => {
+ if (k.startsWith('list:')) {
+ const key = k.slice(5);
+ acc[key] = acc[key] || {};
+ acc[key][i.provider] = i.locally;
}
- return ret;
+ return acc;
}, {} as Record>);
}
diff --git a/packages/data-center/src/index.ts b/packages/data-center/src/index.ts
index 68aa74b916..0ca8f1cfee 100644
--- a/packages/data-center/src/index.ts
+++ b/packages/data-center/src/index.ts
@@ -7,6 +7,17 @@ const _initializeDataCenter = () => {
return (debug = true) => {
if (!_dataCenterInstance) {
_dataCenterInstance = DataCenter.init(debug);
+ _dataCenterInstance.then(dc => {
+ try {
+ if (window) {
+ (window as any).dc = dc;
+ }
+ } catch (_) {
+ // ignore
+ }
+
+ return dc;
+ });
}
return _dataCenterInstance;
diff --git a/packages/data-center/src/provider/affine/index.ts b/packages/data-center/src/provider/affine/index.ts
index fef7a4d0a9..d2323f4ae1 100644
--- a/packages/data-center/src/provider/affine/index.ts
+++ b/packages/data-center/src/provider/affine/index.ts
@@ -1,11 +1,17 @@
import assert from 'assert';
-import { applyUpdate } from 'yjs';
+import { applyUpdate, Doc } from 'yjs';
-import type { InitialParams } from '../index.js';
-import { token, Callback } from '../../apis/index.js';
+import type {
+ ConfigStore,
+ DataCenterSignals,
+ InitialParams,
+ Logger,
+} from '../index.js';
+import { token, Callback, getApis } from '../../apis/index.js';
import { LocalProvider } from '../local/index.js';
import { WebsocketProvider } from './sync.js';
+import { IndexedDBProvider } from '../local/indexeddb.js';
export class AffineProvider extends LocalProvider {
static id = 'affine';
@@ -55,7 +61,14 @@ export class AffineProvider extends LocalProvider {
}
async initData() {
- await super.initData();
+ const databases = await indexedDB.databases();
+ await super.initData(
+ // set locally to true if exists a same name db
+ databases
+ .map(db => db.name)
+ .filter(v => v)
+ .includes(this._workspace.room)
+ );
const workspace = this._workspace;
const doc = workspace.doc;
@@ -64,23 +77,29 @@ export class AffineProvider extends LocalProvider {
if (workspace.room && token.isLogin) {
try {
- const updates = await this._apis.downloadWorkspace(workspace.room);
- if (updates) {
- await new Promise(resolve => {
- doc.once('update', resolve);
- applyUpdate(doc, new Uint8Array(updates));
- });
- // Wait for ws synchronization to complete, otherwise the data will be modified in reverse, which can be optimized later
- this._ws = new WebsocketProvider('/', workspace.room, doc);
- await new Promise((resolve, reject) => {
- // TODO: synced will also be triggered on reconnection after losing sync
- // There needs to be an event mechanism to emit the synchronization state to the upper layer
- assert(this._ws);
- this._ws.once('synced', () => resolve());
- this._ws.once('lost-connection', () => resolve());
- this._ws.once('connection-error', () => reject());
- });
- }
+ // init data from cloud
+ await AffineProvider._initCloudDoc(
+ workspace.room,
+ doc,
+ this._logger,
+ this._signals
+ );
+
+ // Wait for ws synchronization to complete, otherwise the data will be modified in reverse, which can be optimized later
+ this._ws = new WebsocketProvider('/', workspace.room, doc);
+ await new Promise((resolve, reject) => {
+ // TODO: synced will also be triggered on reconnection after losing sync
+ // There needs to be an event mechanism to emit the synchronization state to the upper layer
+ assert(this._ws);
+ this._ws.once('synced', () => resolve());
+ this._ws.once('lost-connection', () => resolve());
+ this._ws.once('connection-error', () => reject());
+ });
+ this._signals.listAdd.emit({
+ workspace: workspace.room,
+ provider: this.id,
+ locally: true,
+ });
} catch (e) {
this._logger('Failed to init cloud workspace', e);
}
@@ -91,4 +110,66 @@ export class AffineProvider extends LocalProvider {
// just a workaround for yjs
doc.getMap('space:meta');
}
+
+ private static async _initCloudDoc(
+ workspace: string,
+ doc: Doc,
+ logger: Logger,
+ signals: DataCenterSignals
+ ) {
+ const apis = getApis();
+ logger(`Loading ${workspace}...`);
+ const updates = await apis.downloadWorkspace(workspace);
+ if (updates) {
+ await new Promise(resolve => {
+ doc.once('update', resolve);
+ applyUpdate(doc, new Uint8Array(updates));
+ });
+ logger(`Loaded: ${workspace}`);
+
+ // only add to list as online workspace
+ signals.listAdd.emit({
+ workspace,
+ provider: this.id,
+ // at this time we always download full workspace
+ // but after we support sub doc, we can only download metadata
+ locally: false,
+ });
+ }
+ }
+
+ static async auth(
+ config: Readonly>,
+ logger: Logger,
+ signals: DataCenterSignals
+ ) {
+ const refreshToken = await config.get('token');
+ if (refreshToken) {
+ await token.refreshToken(refreshToken);
+ if (token.isLogin && !token.isExpired) {
+ logger('check login success');
+ // login success
+ return;
+ }
+ }
+
+ logger('start login');
+ // login with google
+ const apis = getApis();
+ assert(apis.signInWithGoogle);
+ const user = await apis.signInWithGoogle();
+ assert(user);
+ logger(`login success: ${user.displayName}`);
+
+ // TODO: refresh local workspace data
+ const workspaces = await apis.getWorkspaces();
+ await Promise.all(
+ workspaces.map(async ({ id }) => {
+ const doc = new Doc();
+ const idb = new IndexedDBProvider(id, doc);
+ await idb.whenSynced;
+ await this._initCloudDoc(id, doc, logger, signals);
+ })
+ );
+ }
}
diff --git a/packages/data-center/src/provider/base.ts b/packages/data-center/src/provider/base.ts
index 95bd309a1c..bd8d8a4e03 100644
--- a/packages/data-center/src/provider/base.ts
+++ b/packages/data-center/src/provider/base.ts
@@ -1,14 +1,20 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { Workspace } from '@blocksuite/store';
-import type { Apis, Logger, InitialParams, ConfigStore } from './index';
+import type {
+ Apis,
+ DataCenterSignals,
+ Logger,
+ InitialParams,
+ ConfigStore,
+} from './index';
export class BaseProvider {
static id = 'base';
protected _apis!: Readonly;
protected _config!: Readonly;
- protected _globalConfig!: Readonly;
protected _logger!: Logger;
+ protected _signals!: DataCenterSignals;
protected _workspace!: Workspace;
constructor() {
@@ -22,8 +28,8 @@ export class BaseProvider {
async init(params: InitialParams) {
this._apis = params.apis;
this._config = params.config;
- this._globalConfig = params.globalConfig;
this._logger = params.logger;
+ this._signals = params.signals;
this._workspace = params.workspace;
this._logger.enabled = params.debug;
}
@@ -55,6 +61,14 @@ export class BaseProvider {
return this._workspace;
}
+ static async auth(
+ _config: Readonly,
+ logger: Logger,
+ _signals: DataCenterSignals
+ ) {
+ logger("This provider doesn't require authentication");
+ }
+
// get workspace list,return a map of workspace id and boolean
// if value is true, it exists locally, otherwise it does not exist locally
static async list(
diff --git a/packages/data-center/src/provider/index.ts b/packages/data-center/src/provider/index.ts
index f3fc53f9ad..5718b7eef0 100644
--- a/packages/data-center/src/provider/index.ts
+++ b/packages/data-center/src/provider/index.ts
@@ -1,6 +1,7 @@
import type { Workspace } from '@blocksuite/store';
import type { Apis } from '../apis';
+import type { DataCenterSignals } from '../datacenter';
import type { getLogger } from '../index';
import type { ConfigStore } from '../store';
@@ -9,13 +10,13 @@ export type Logger = ReturnType;
export type InitialParams = {
apis: Apis;
config: Readonly;
- globalConfig: Readonly;
debug: boolean;
logger: Logger;
+ signals: DataCenterSignals;
workspace: Workspace;
};
-export type { Apis, ConfigStore, Workspace };
+export type { Apis, ConfigStore, DataCenterSignals, Workspace };
export type { BaseProvider } from './base.js';
export { AffineProvider } from './affine/index.js';
export { LocalProvider } from './local/index.js';
diff --git a/packages/data-center/src/provider/local/index.ts b/packages/data-center/src/provider/local/index.ts
index d2ced1b9ee..24bf9584a7 100644
--- a/packages/data-center/src/provider/local/index.ts
+++ b/packages/data-center/src/provider/local/index.ts
@@ -21,7 +21,7 @@ export class LocalProvider extends BaseProvider {
this._blobs = blobs;
}
- async initData() {
+ async initData(locally = true) {
assert(this._workspace.room);
this._logger('Loading local data');
this._idb = new IndexedDBProvider(
@@ -32,14 +32,19 @@ export class LocalProvider extends BaseProvider {
await this._idb.whenSynced;
this._logger('Local data loaded');
- await this._globalConfig.set(this._workspace.room, true);
+ this._signals.listAdd.emit({
+ workspace: this._workspace.room,
+ provider: this.id,
+ locally,
+ });
}
async clear() {
+ assert(this._workspace.room);
await super.clear();
await this._blobs.clear();
await this._idb?.clearData();
- await this._globalConfig.delete(this._workspace.room!);
+ this._signals.listRemove.emit(this._workspace.room);
}
async destroy(): Promise {
@@ -59,6 +64,10 @@ export class LocalProvider extends BaseProvider {
config: Readonly>
): Promise