import { Arr, type Optional } from '@ephox/katamari'; import type { EventArgs } from '@ephox/sugar'; import type { KeyRuleHandler } from '../keying/KeyingModeTypes'; import * as KeyMatch from './KeyMatch'; export interface KeyRule { matches: KeyMatch.KeyMatcher; classification: KeyRuleHandler; } const basic = (key: number, action: KeyRuleHandler): KeyRule => ({ matches: KeyMatch.is(key), classification: action }); const rule = (matches: KeyMatch.KeyMatcher, action: KeyRuleHandler): KeyRule => ({ matches, classification: action }); const choose = (transitions: Array>, event: EventArgs): Optional> => { const transition = Arr.find(transitions, (t) => t.matches(event)); return transition.map((t) => t.classification); }; export { basic, rule, choose };