feat(core): open new page on meta-clicking a page link (#6220)
This commit is contained in:
@@ -23,6 +23,8 @@ export class Workbench {
|
|||||||
this.views.value[this.activeViewIndex.value]
|
this.views.value[this.activeViewIndex.value]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
basename = new LiveData('/');
|
||||||
|
|
||||||
location = LiveData.from(
|
location = LiveData.from(
|
||||||
this.activeView.pipe(switchMap(view => view.location)),
|
this.activeView.pipe(switchMap(view => view.location)),
|
||||||
this.views.value[this.activeViewIndex.value].history.location
|
this.views.value[this.activeViewIndex.value].history.location
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
|
import { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
|
||||||
import { useService } from '@toeverything/infra/di';
|
import { useService } from '@toeverything/infra/di';
|
||||||
|
import { useLiveData } from '@toeverything/infra/livedata';
|
||||||
import type { To } from 'history';
|
import type { To } from 'history';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
@@ -15,24 +16,28 @@ export const WorkbenchLink = ({
|
|||||||
>) => {
|
>) => {
|
||||||
const workbench = useService(Workbench);
|
const workbench = useService(Workbench);
|
||||||
const { appSettings } = useAppSettingHelper();
|
const { appSettings } = useAppSettingHelper();
|
||||||
|
const basename = useLiveData(workbench.basename);
|
||||||
const handleClick = useCallback(
|
const handleClick = useCallback(
|
||||||
(event: React.MouseEvent<HTMLAnchorElement>) => {
|
(event: React.MouseEvent<HTMLAnchorElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
// TODO: open this when multi view control is implemented
|
|
||||||
if (
|
if (event.ctrlKey || event.metaKey) {
|
||||||
appSettings.enableMultiView &&
|
if (appSettings.enableMultiView && environment.isDesktop) {
|
||||||
environment.isDesktop &&
|
|
||||||
(event.ctrlKey || event.metaKey)
|
|
||||||
) {
|
|
||||||
workbench.open(to, { at: 'beside' });
|
workbench.open(to, { at: 'beside' });
|
||||||
|
} else if (!environment.isDesktop) {
|
||||||
|
const href =
|
||||||
|
typeof to === 'string'
|
||||||
|
? to
|
||||||
|
: `${to.pathname}${to.search}${to.hash}`;
|
||||||
|
window.open(basename + href, '_blank');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
workbench.open(to);
|
workbench.open(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
onClick?.(event);
|
onClick?.(event);
|
||||||
},
|
},
|
||||||
[appSettings.enableMultiView, onClick, to, workbench]
|
[appSettings.enableMultiView, basename, onClick, to, workbench]
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<a {...other} href="#" onClick={handleClick}>
|
<a {...other} href="#" onClick={handleClick}>
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ export const WorkbenchRoot = () => {
|
|||||||
[workbench]
|
[workbench]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
workbench.basename.next(basename);
|
||||||
|
}, [basename, workbench.basename]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SplitView
|
<SplitView
|
||||||
className={styles.workbenchRootContainer}
|
className={styles.workbenchRootContainer}
|
||||||
|
|||||||
Reference in New Issue
Block a user