refactor(core): new back&forward button base on workbench (#6012)

# feature:

## In Browser:
- hidden back&forward button in sidebar.
- back and forward is equal with `window.history.back()` `window.history.forward()`

## In Desktop:
- Back and forward can be controlled through the sidebar, cmdk, and shortcut keys.
- back and forward act on the currently **active** view.
- buttons change disable&enable style based on current active view history

# Refactor:

Move app-sidebar and app-container from @affine/component to @affine/core
This commit is contained in:
EYHN
2024-03-05 07:01:24 +00:00
parent b06aeb22dd
commit 7c76c25a9c
77 changed files with 625 additions and 349 deletions

View File

@@ -1,7 +1,8 @@
import { appSidebarOpenAtom } from '@affine/component/app-sidebar';
import { useAtom } from 'jotai';
import { useCallback, useMemo } from 'react';
import { appSidebarOpenAtom } from '../../components/app-sidebar';
export function useSwitchSidebarStatus() {
const [isOpened, setOpened] = useAtom(appSidebarOpenAtom);

View File

@@ -1,49 +0,0 @@
import {
PreconditionStrategy,
registerAffineCommand,
} from '@toeverything/infra/command';
import { useEffect } from 'react';
export function useRegisterBrowserHistoryCommands(
back: () => unknown,
forward: () => unknown
) {
useEffect(() => {
const unsubs: Array<() => void> = [];
unsubs.push(
registerAffineCommand({
id: 'affine:shortcut-history-go-back',
category: 'affine:general',
preconditionStrategy: PreconditionStrategy.Never,
icon: 'none',
label: 'go back',
keyBinding: {
binding: '$mod+[',
},
run() {
back();
},
})
);
unsubs.push(
registerAffineCommand({
id: 'affine:shortcut-history-go-forward',
category: 'affine:general',
preconditionStrategy: PreconditionStrategy.Never,
icon: 'none',
label: 'go forward',
keyBinding: {
binding: '$mod+]',
},
run() {
forward();
},
})
);
return () => {
unsubs.forEach(unsub => unsub());
};
}, [back, forward]);
}