Files
AFFiNE-Mirror/blocksuite/framework/inline/src/services/hook.ts
T
2024-12-20 15:38:06 +08:00

35 lines
1.1 KiB
TypeScript

import type { InlineEditor } from '../inline-editor.js';
import type { InlineRange } from '../types.js';
import type { BaseTextAttributes } from '../utils/base-attributes.js';
export interface BeforeinputHookCtx<TextAttributes extends BaseTextAttributes> {
inlineEditor: InlineEditor<TextAttributes>;
raw: InputEvent;
inlineRange: InlineRange;
data: string | null;
attributes: TextAttributes;
}
export interface CompositionEndHookCtx<
TextAttributes extends BaseTextAttributes,
> {
inlineEditor: InlineEditor<TextAttributes>;
raw: CompositionEvent;
inlineRange: InlineRange;
data: string | null;
attributes: TextAttributes;
}
export type HookContext<TextAttributes extends BaseTextAttributes> =
| BeforeinputHookCtx<TextAttributes>
| CompositionEndHookCtx<TextAttributes>;
export class InlineHookService<TextAttributes extends BaseTextAttributes> {
constructor(
readonly editor: InlineEditor<TextAttributes>,
readonly hooks: {
beforeinput?: (props: BeforeinputHookCtx<TextAttributes>) => void;
compositionEnd?: (props: CompositionEndHookCtx<TextAttributes>) => void;
} = {}
) {}
}