nitin
2026-02-02 18:44:27 +05:30
committed by GitHub
parent 7f33286274
commit b643fbe425
3 changed files with 45 additions and 0 deletions
@@ -1,6 +1,8 @@
import { useCallback } from 'react';
import { useSetRecoilState } from 'recoil';
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
import { commandMenuPageState } from '@/command-menu/states/commandMenuPageState';
import { CommandMenuPages } from '@/command-menu/types/CommandMenuPages';
import { useSetRecoilComponentState } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentState';
@@ -24,6 +26,7 @@ export const useEditPageLayoutWidget = (pageLayoutIdFromProps?: string) => {
const { navigatePageLayoutCommandMenu } = useNavigatePageLayoutCommandMenu();
const { closeCommandMenu } = useCommandMenu();
const setCommandMenuPage = useSetRecoilState(commandMenuPageState);
const handleEditWidget = useCallback(
({
@@ -53,12 +56,14 @@ export const useEditPageLayoutWidget = (pageLayoutIdFromProps?: string) => {
return;
}
setCommandMenuPage(CommandMenuPages.Root);
closeCommandMenu();
},
[
setPageLayoutEditingWidgetId,
navigatePageLayoutCommandMenu,
closeCommandMenu,
setCommandMenuPage,
],
);
@@ -11,6 +11,7 @@ import { isPageLayoutInEditModeComponentState } from '@/page-layout/states/isPag
import { pageLayoutEditingWidgetIdComponentState } from '@/page-layout/states/pageLayoutEditingWidgetIdComponentState';
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
import { DashboardsBlockEditor } from '@/page-layout/widgets/standalone-rich-text/components/DashboardsBlockEditor';
import { StandaloneRichTextWidgetAutoFocusEffect } from '@/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextWidgetAutoFocusEffect';
import { BLOCK_EDITOR_GLOBAL_HOTKEYS_CONFIG } from '@/ui/input/editor/constants/BlockEditorGlobalHotkeysConfig';
import { useAttachmentSync } from '@/ui/input/editor/hooks/useAttachmentSync';
import { parseInitialBlocknote } from '@/ui/input/editor/utils/parseInitialBlocknote';
@@ -182,6 +183,11 @@ export const StandaloneRichTextWidget = ({
ref={containerElementRef}
isPageLayoutInEditMode={isPageLayoutInEditMode}
>
<StandaloneRichTextWidgetAutoFocusEffect
shouldFocus={isEditable}
editor={editor}
containerElement={containerElementRef.current}
/>
<ScrollWrapper
componentInstanceId={`scroll-wrapper-rich-text-widget-${widget.id}`}
>
@@ -0,0 +1,34 @@
import { useEffect } from 'react';
import { type BLOCK_SCHEMA } from '@/activities/blocks/constants/Schema';
type StandaloneRichTextWidgetAutoFocusEffectProps = {
shouldFocus: boolean;
editor: typeof BLOCK_SCHEMA.BlockNoteEditor;
containerElement?: HTMLElement | null;
};
export const StandaloneRichTextWidgetAutoFocusEffect = ({
shouldFocus,
editor,
containerElement,
}: StandaloneRichTextWidgetAutoFocusEffectProps) => {
useEffect(() => {
if (shouldFocus) {
const alreadyFocused =
containerElement?.contains(document.activeElement) ?? false;
if (!alreadyFocused) {
const rafId = requestAnimationFrame(() => {
editor.focus();
});
return () => {
cancelAnimationFrame(rafId);
};
}
}
}, [shouldFocus, editor, containerElement]);
return null;
};