ef8211e99c95b27a1c65b9710bca74d3afffe287276c8b3f5e1a848629a117d59fe4a2eb2d5c8c90689d30e6fab59761bb8cb5ed09238f0fa2aa3c958cd9d3 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import type { BlockBlot } from 'parchment';
  2. import Quill from '../core/quill.js';
  3. import Module from '../core/module.js';
  4. import type { BlockEmbed } from '../blots/block.js';
  5. import type { Range } from '../core/selection.js';
  6. declare const SHORTKEY: string;
  7. export interface Context {
  8. collapsed: boolean;
  9. empty: boolean;
  10. offset: number;
  11. prefix: string;
  12. suffix: string;
  13. format: Record<string, unknown>;
  14. event: KeyboardEvent;
  15. line: BlockEmbed | BlockBlot;
  16. }
  17. interface BindingObject extends Partial<Omit<Context, 'prefix' | 'suffix' | 'format'>> {
  18. key: number | string | string[];
  19. shortKey?: boolean | null;
  20. shiftKey?: boolean | null;
  21. altKey?: boolean | null;
  22. metaKey?: boolean | null;
  23. ctrlKey?: boolean | null;
  24. prefix?: RegExp;
  25. suffix?: RegExp;
  26. format?: Record<string, unknown> | string[];
  27. handler?: (this: {
  28. quill: Quill;
  29. }, range: Range, curContext: Context, binding: NormalizedBinding) => boolean | void;
  30. }
  31. type Binding = BindingObject | string | number;
  32. interface NormalizedBinding extends Omit<BindingObject, 'key' | 'shortKey'> {
  33. key: string | number;
  34. }
  35. interface KeyboardOptions {
  36. bindings: Record<string, Binding>;
  37. }
  38. interface KeyboardOptions {
  39. bindings: Record<string, Binding>;
  40. }
  41. declare class Keyboard extends Module<KeyboardOptions> {
  42. static DEFAULTS: KeyboardOptions;
  43. static match(evt: KeyboardEvent, binding: BindingObject): boolean;
  44. bindings: Record<string, NormalizedBinding[]>;
  45. constructor(quill: Quill, options: Partial<KeyboardOptions>);
  46. addBinding(keyBinding: Binding, context?: Required<BindingObject['handler']> | Partial<Omit<BindingObject, 'key' | 'handler'>>, handler?: Required<BindingObject['handler']> | Partial<Omit<BindingObject, 'key' | 'handler'>>): void;
  47. listen(): void;
  48. handleBackspace(range: Range, context: Context): void;
  49. handleDelete(range: Range, context: Context): void;
  50. handleDeleteRange(range: Range): void;
  51. handleEnter(range: Range, context: Context): void;
  52. }
  53. declare function normalize(binding: Binding): BindingObject | null;
  54. declare function deleteRange({ quill, range }: {
  55. quill: Quill;
  56. range: Range;
  57. }): void;
  58. export { Keyboard as default, SHORTKEY, normalize, deleteRange };