refactor!: remove next.js (#3267)

This commit is contained in:
Alex Yang
2023-07-19 00:53:10 +08:00
committed by GitHub
parent 79227a1e7c
commit 47f12f77f2
296 changed files with 4115 additions and 3617 deletions
+6
View File
@@ -0,0 +1,6 @@
# AFFiNE Hooks
> This directory will be moved to `@affine/worksapce/affine/hooks` in the future.
Only put hooks in this directory if they are specific to AFFiNE, for example
if they are using the AFFiNE API, or if the `AffineWorkspace` is required.
@@ -0,0 +1,126 @@
import {
useBlockSuitePageMeta,
usePageMetaHelper,
} from '@toeverything/hooks/use-block-suite-page-meta';
import { useCallback } from 'react';
import type { BlockSuiteWorkspace } from '../../shared';
import { useReferenceLinkHelper } from './use-reference-link-helper';
export function useBlockSuiteMetaHelper(
blockSuiteWorkspace: BlockSuiteWorkspace
) {
const { setPageMeta, getPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const { addReferenceLink } = useReferenceLinkHelper(blockSuiteWorkspace);
const metas = useBlockSuitePageMeta(blockSuiteWorkspace);
const addToFavorite = useCallback(
(pageId: string) => {
setPageMeta(pageId, {
favorite: true,
});
},
[setPageMeta]
);
const removeFromFavorite = useCallback(
(pageId: string) => {
setPageMeta(pageId, {
favorite: false,
});
},
[setPageMeta]
);
const toggleFavorite = useCallback(
(pageId: string) => {
const { favorite } = getPageMeta(pageId) ?? {};
setPageMeta(pageId, {
favorite: !favorite,
});
},
[getPageMeta, setPageMeta]
);
// TODO-Doma
// "Remove" may cause ambiguity here. Consider renaming as "moveToTrash".
const removeToTrash = useCallback(
(pageId: string, isRoot = true) => {
const parentMeta = metas.find(m => m.subpageIds?.includes(pageId));
const { subpageIds = [] } = getPageMeta(pageId) ?? {};
subpageIds.forEach(id => {
removeToTrash(id, false);
});
setPageMeta(pageId, {
trash: true,
trashDate: +new Date(),
trashRelate: isRoot ? parentMeta?.id : undefined,
});
},
[getPageMeta, metas, setPageMeta]
);
const restoreFromTrash = useCallback(
(pageId: string) => {
const { subpageIds = [], trashRelate } = getPageMeta(pageId) ?? {};
if (trashRelate) {
addReferenceLink(trashRelate, pageId);
}
setPageMeta(pageId, {
trash: false,
trashDate: undefined,
trashRelate: undefined,
});
subpageIds.forEach(id => {
restoreFromTrash(id);
});
},
[addReferenceLink, getPageMeta, setPageMeta]
);
const permanentlyDeletePage = useCallback(
(pageId: string) => {
blockSuiteWorkspace.removePage(pageId);
},
[blockSuiteWorkspace]
);
/**
* see {@link useBlockSuiteWorkspacePageIsPublic}
*/
const publicPage = useCallback(
(pageId: string) => {
setPageMeta(pageId, {
isPublic: true,
});
},
[setPageMeta]
);
/**
* see {@link useBlockSuiteWorkspacePageIsPublic}
*/
const cancelPublicPage = useCallback(
(pageId: string) => {
setPageMeta(pageId, {
isPublic: false,
});
},
[setPageMeta]
);
return {
publicPage,
cancelPublicPage,
addToFavorite,
removeFromFavorite,
toggleFavorite,
removeToTrash,
restoreFromTrash,
permanentlyDeletePage,
};
}
@@ -0,0 +1,35 @@
import { useCallback } from 'react';
import type { BlockSuiteWorkspace } from '../../shared';
export function useReferenceLinkHelper(
blockSuiteWorkspace: BlockSuiteWorkspace
) {
const addReferenceLink = useCallback(
(pageId: string, referenceId: string) => {
const page = blockSuiteWorkspace?.getPage(pageId);
if (!page) {
return;
}
const text = page.Text.fromDelta([
{
insert: ' ',
attributes: {
reference: {
type: 'Subpage',
pageId: referenceId,
},
},
},
]);
const [frame] = page.getBlockByFlavour('affine:note');
frame && page.addBlock('affine:paragraph', { text }, frame.id);
},
[blockSuiteWorkspace]
);
return {
addReferenceLink,
};
}
+239
View File
@@ -0,0 +1,239 @@
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { useMemo } from 'react';
interface ShortcutTip {
[x: string]: string;
}
export const useWinGeneralKeyboardShortcuts = (): ShortcutTip => {
const t = useAFFiNEI18N();
return useMemo(
() => ({
[t['Cancel']()]: 'ESC',
[t['Quick Search']()]: 'Ctrl + K',
[t['New Page']()]: 'Ctrl + N',
// not implement yet
// [t['Append to Daily Note']()]: 'Ctrl + Alt + A',
[t['Expand/Collapse Sidebar']()]: 'Ctrl + /',
// not implement yet
// [t['Go Back']()]: 'Ctrl + [',
// [t['Go Forward']()]: 'Ctrl + ]',
}),
[t]
);
};
export const useMacGeneralKeyboardShortcuts = (): ShortcutTip => {
const t = useAFFiNEI18N();
return useMemo(
() => ({
[t['Cancel']()]: 'ESC',
[t['Quick Search']()]: '⌘ + K',
[t['New Page']()]: '⌘ + N',
// not implement yet
// [t['Append to Daily Note']()]: '⌘ + ⌥ + A',
[t['Expand/Collapse Sidebar']()]: '⌘ + /',
// not implement yet
// [t['Go Back']()]: '⌘ + [',
// [t['Go Forward']()]: '⌘ + ]',
}),
[t]
);
};
export const useMacEdgelessKeyboardShortcuts = (): ShortcutTip => {
const t = useAFFiNEI18N();
return useMemo(
() => ({
[t['Select All']()]: '⌘ + A',
[t['Undo']()]: '⌘ + Z',
[t['Redo']()]: '⌘ + ⇧ + Z',
[t['Zoom in']()]: '⌘ + +',
[t['Zoom out']()]: '⌘ + -',
[t['Zoom to 100%']()]: '⌘ + 0',
[t['Zoom to fit']()]: '⌘ + 1',
[t['Select']()]: 'V',
[t['Text']()]: 'T',
[t['Shape']()]: 'S',
[t['Image']()]: 'I',
[t['Straight Connector']()]: 'L',
[t['Elbowed Connector']()]: 'X',
// not implement yet
// [t['Curve Connector']()]: 'C',
[t['Pen']()]: 'P',
[t['Hand']()]: 'H',
[t['Note']()]: 'N',
// not implement yet
// [t['Group']()]: '⌘ + G',
// [t['Ungroup']()]: '⌘ + ⇧ + G',
}),
[t]
);
};
export const useWinEdgelessKeyboardShortcuts = (): ShortcutTip => {
const t = useAFFiNEI18N();
return useMemo(
() => ({
[t['Select All']()]: 'Ctrl + A',
[t['Undo']()]: 'Ctrl + Z',
[t['Redo']()]: 'Ctrl + Y/Ctrl + Shift + Z',
[t['Zoom in']()]: 'Ctrl + +',
[t['Zoom out']()]: 'Ctrl + -',
[t['Zoom to 100%']()]: 'Ctrl + 0',
[t['Zoom to fit']()]: 'Ctrl + 1',
[t['Select']()]: 'V',
[t['Text']()]: 'T',
[t['Shape']()]: 'S',
[t['Image']()]: 'I',
[t['Straight Connector']()]: 'L',
[t['Elbowed Connector']()]: 'X',
// not implement yet
// [t['Curve Connector']()]: 'C',
[t['Pen']()]: 'P',
[t['Hand']()]: 'H',
[t['Note']()]: 'N',
[t['Switch']()]: 'Alt + S',
// not implement yet
// [t['Group']()]: 'Ctrl + G',
// [t['Ungroup']()]: 'Ctrl + Shift + G',
}),
[t]
);
};
export const useMacPageKeyboardShortcuts = (): ShortcutTip => {
const t = useAFFiNEI18N();
return useMemo(
() => ({
[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['Quick search']()]: '⌘+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',
[t['Group as Database']()]: '⌘ + G',
[t['Switch']()]: '⌥ + S',
// not implement yet
// [t['Move Up']()]: '⌘ + ⌥ + ↑',
// [t['Move Down']()]: '⌘ + ⌥ + ↓',
}),
[t]
);
};
export const useMacMarkdownShortcuts = (): ShortcutTip => {
const t = useAFFiNEI18N();
return useMemo(
() => ({
[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',
}),
[t]
);
};
export const useWinPageKeyboardShortcuts = (): ShortcutTip => {
const t = useAFFiNEI18N();
return useMemo(
() => ({
[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['Quick search']()]: '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',
[t['Group as Database']()]: 'Ctrl + G',
['Switch']: 'Alt + S',
// not implement yet
// [t['Move Up']()]: 'Ctrl + Alt + ↑',
// [t['Move Down']()]: 'Ctrl + Alt + ↓',
}),
[t]
);
};
export const useWinMarkdownShortcuts = (): ShortcutTip => {
const t = useAFFiNEI18N();
return useMemo(
() => ({
[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',
}),
[t]
);
};
export const useMarkdownShortcuts = (): ShortcutTip => {
const macMarkdownShortcuts = useMacMarkdownShortcuts();
const winMarkdownShortcuts = useWinMarkdownShortcuts();
const isMac = environment.isBrowser && environment.isMacOs;
return isMac ? macMarkdownShortcuts : winMarkdownShortcuts;
};
export const usePageShortcuts = (): ShortcutTip => {
const macPageShortcuts = useMacPageKeyboardShortcuts();
const winPageShortcuts = useWinPageKeyboardShortcuts();
const isMac = environment.isBrowser && environment.isMacOs;
return isMac ? macPageShortcuts : winPageShortcuts;
};
export const useEdgelessShortcuts = (): ShortcutTip => {
const macEdgelessShortcuts = useMacEdgelessKeyboardShortcuts();
const winEdgelessShortcuts = useWinEdgelessKeyboardShortcuts();
const isMac = environment.isBrowser && environment.isMacOs;
return isMac ? macEdgelessShortcuts : winEdgelessShortcuts;
};
export const useGeneralShortcuts = (): ShortcutTip => {
const macGeneralShortcuts = useMacGeneralKeyboardShortcuts();
const winGeneralShortcuts = useWinGeneralKeyboardShortcuts();
const isMac = environment.isBrowser && environment.isMacOs;
return isMac ? macGeneralShortcuts : winGeneralShortcuts;
};