mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 02:26:21 +08:00
35 lines
1.1 KiB
TypeScript
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;
|
|
} = {}
|
|
) {}
|
|
}
|