Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: add onScroll hook in editor, resolved #561

qishaoxuan52e9d0b2d73a
diff --git a/libs/components/editor-core/src/RenderRoot.tsx b/libs/components/editor-core/src/RenderRoot.tsx
index d6af706ebe..13c2bbbc82 100644
--- a/libs/components/editor-core/src/RenderRoot.tsx
+++ b/libs/components/editor-core/src/RenderRoot.tsx
@@ -11,6 +11,7 @@ import {
type ReturnUnobserve,
} from '@toeverything/datasource/db-service';
import { addNewGroup } from './recast-block';
+import { HookType } from './editor';
interface RenderRootProps {
editor: BlockEditor;
@@ -178,6 +179,10 @@ export const RenderRoot: FC<PropsWithChildren<RenderRootProps>> = ({
editor.getHooks().onRootNodeDrop(event);
};
+ const onScroll = (event: React.UIEvent) => {
+ editor.getHooks().onRootNodeScroll(event);
+ };
+
return (
<RootContext.Provider value={{ editor, editorElement }}>
<Container
@@ -197,6 +202,7 @@ export const RenderRoot: FC<PropsWithChildren<RenderRootProps>> = ({
onDragOverCapture={onDragOverCapture}
onDragEnd={onDragEnd}
onDrop={onDrop}
+ onScroll={onScroll}
>
<Content
ref={contentRef}
diff --git a/libs/components/editor-core/src/editor/plugin/hooks.ts b/libs/components/editor-core/src/editor/plugin/hooks.ts
index f037691689..5798b1982d 100644
--- a/libs/components/editor-core/src/editor/plugin/hooks.ts
+++ b/libs/components/editor-core/src/editor/plugin/hooks.ts
@@ -197,4 +197,8 @@ export class Hooks implements HooksRunner, PluginHooks {
public beforeCut(e: ClipboardEvent): void {
this.run_hook(HookType.BEFORE_CUT, e);
}
+
+ public onRootNodeScroll(e: React.UIEvent): void {
+ this.run_hook(HookType.ON_ROOTNODE_SCROLL, e);
+ }
}
diff --git a/libs/components/editor-core/src/editor/types.ts b/libs/components/editor-core/src/editor/types.ts
index 1c766c2ffa..0f6b09afb3 100644
--- a/libs/components/editor-core/src/editor/types.ts
+++ b/libs/components/editor-core/src/editor/types.ts
@@ -172,6 +172,7 @@ export enum HookType {
AFTER_ON_NODE_DRAG_OVER = 'afterOnNodeDragOver',
BEFORE_COPY = 'beforeCopy',
BEFORE_CUT = 'beforeCut',
+ ON_ROOTNODE_SCROLL = 'onRootNodeScroll',
}
export interface HookBaseArgs {
@@ -231,6 +232,7 @@ export interface HooksRunner {
) => void;
beforeCopy: (e: ClipboardEvent) => void;
beforeCut: (e: ClipboardEvent) => void;
+ onRootNodeScroll: (e: React.UIEvent) => void;
}
export type AnyFunction = (...args: any[]) => any;