feat: new CMD-K (#4408)

This commit is contained in:
Peng Xiao
2023-09-22 22:31:26 +08:00
committed by GitHub
parent 27e4599c94
commit e0063ebc9b
49 changed files with 2936 additions and 965 deletions

View File

@@ -13,6 +13,7 @@ import {
blockSuiteEditorHeaderStyle,
blockSuiteEditorStyle,
} from './index.css';
import { useRegisterBlocksuiteEditorCommands } from './use-register-blocksuite-editor-commands';
export type EditorProps = {
page: Page;
@@ -164,6 +165,7 @@ export const BlockSuiteFallback = memo(function BlockSuiteFallback() {
export const BlockSuiteEditor = memo(function BlockSuiteEditor(
props: EditorProps & ErrorBoundaryProps
): ReactElement {
useRegisterBlocksuiteEditorCommands();
return (
<ErrorBoundary
fallbackRender={useCallback(

View File

@@ -0,0 +1,35 @@
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { EdgelessIcon } from '@blocksuite/icons';
import { registerAffineCommand } from '@toeverything/infra/command';
import { useEffect } from 'react';
export function useRegisterBlocksuiteEditorCommands() {
const t = useAFFiNEI18N();
useEffect(() => {
const unsubs: Array<() => void> = [];
const getEdgeless = () => {
return document.querySelector('affine-edgeless-page');
};
unsubs.push(
registerAffineCommand({
id: 'editor:edgeless-presentation-start',
preconditionStrategy: () => !!getEdgeless(),
category: 'editor:edgeless',
icon: <EdgelessIcon />,
label: t['com.affine.cmdk.affine.editor.edgeless.presentation-start'](),
run() {
// this is pretty hack and easy to break. need a better way to communicate with blocksuite editor
document
.querySelector<HTMLElement>('edgeless-toolbar')
?.shadowRoot?.querySelector<HTMLElement>(
'.edgeless-toolbar-left-part > edgeless-tool-icon-button:last-child'
)
?.click();
},
})
);
return () => {
unsubs.forEach(unsub => unsub());
};
}, [t]);
}

View File

@@ -8,4 +8,5 @@ export * from './operation-menu-items';
export * from './styles';
export * from './type';
export * from './use-collection-manager';
export * from './utils';
export * from './view';