UNPKG

@adaptabletools/adaptable

Version:

Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

95 lines (94 loc) 4.99 kB
import type { EditOptions, PlusMinusOptions } from '../../AdaptableOptions/EditOptions'; import type { PlusMinusNudge } from '../../AdaptableState/PlusMinusState'; /** * Minimal shape required to match a key press against a Plus/Minus trigger. * Compatible with the native `KeyboardEvent`. */ export type PlusMinusKeyEvent = { key: string; metaKey?: boolean; altKey?: boolean; ctrlKey?: boolean; shiftKey?: boolean; }; /** * Resolve increment/decrement trigger strings for a single nudge. * Per-nudge fields win; otherwise {@link PlusMinusOptions}; otherwise `+` / `-`. */ export declare function resolvePlusMinusTriggerKeysForNudge(nudge: Pick<PlusMinusNudge, 'IncrementKey' | 'DecrementKey'>, globalOptions: Readonly<EditOptions['plusMinusOptions']> | undefined): { incrementKey: string; decrementKey: string; }; /** True when resolved increment and decrement would match the same key press. */ export declare function plusMinusResolvedKeysConflict(nudge: Pick<PlusMinusNudge, 'IncrementKey' | 'DecrementKey'>, globalOptions: Readonly<EditOptions['plusMinusOptions']> | undefined): boolean; /** * Match a pressed key (with its modifier state) against a configured trigger. * Single-character triggers (including the defaults `+` / `-`) are compared * case-insensitively against the pressed key. Multi-character triggers are * parsed as keyboard shortcut combinations (e.g. `shift+Enter`) and delegated * to {@link eventMatchesKeyboardShortcut}. */ export declare function plusMinusEventMatchesTrigger(event: PlusMinusKeyEvent, configuredKey: string): boolean; /** Increment key from `AdaptableOptions.plusMinusOptions` only, then built-in `+`. */ export declare function plusMinusIncrementKeyFromOptionsOnly(globalOptions: Readonly<PlusMinusOptions> | undefined): string; /** Decrement key from `AdaptableOptions.plusMinusOptions` only, then built-in `-`. */ export declare function plusMinusDecrementKeyFromOptionsOnly(globalOptions: Readonly<PlusMinusOptions> | undefined): string; /** * Canonical, comparable form of a trigger so equivalent descriptors compare * equal regardless of case or modifier ordering (e.g. `Shift+Enter` and * `shift+enter` normalise to the same value). Single characters are lowercased. */ export declare function normalizePlusMinusTrigger(trigger: string | undefined): string; /** * True when `candidate` is the same trigger as `baseline` for “no nudge override * to persist” (normalised comparison, see {@link normalizePlusMinusTrigger}). */ export declare function plusMinusTriggerSameAsBaseline(candidate: string, baseline: string): boolean; /** Result of interpreting a key press inside a "record shortcut" UI. */ export type PlusMinusCaptureResult = { kind: 'pending'; modifiers: string[]; } | { kind: 'invalid'; reason: string; } | { kind: 'captured'; trigger: string; }; /** * Interpret a key press (from a "record shortcut" UI, à la VS Code) into a * Plus/Minus trigger: * - `pending`: only modifier keys are held so far (waiting for a real key). * - `captured`: a complete, representable trigger — a single literal character * (such as the default `+`), a named key (e.g. `Enter`), or a modifier * combination (e.g. `shift+Enter`). * - `invalid`: the press cannot be represented as a trigger (e.g. a `+` * character combined with modifiers, since `+` is the glue between parts). */ export declare function capturePlusMinusTriggerFromEvent(event: PlusMinusKeyEvent): PlusMinusCaptureResult; /** Human-friendly label for a single trigger token (a modifier or a key). */ export declare function plusMinusKeyLabel(token: string): string; /** * Split a stored trigger into human-friendly key tokens for kbd-style display * (e.g. `shift+Enter` -> `['Shift', 'Enter']`, `+` -> `['+']`). */ export declare function plusMinusTriggerDisplayParts(trigger: string): string[]; /** * Precomputed keys for fast keydown filtering. Stores the lowercased * non-modifier key of each trigger (the default `+` / `-`, a literal single * char, or the key part of a combination such as `enter` for `shift+Enter`), * so a pressed `event.key` can be cheaply rejected before running nudge rules. */ export type PlusMinusTriggerKeyLookup = { /** Lowercased non-modifier keys that could trigger a nudge. */ effectiveKeysLower: Set<string>; /** True when a trigger uses the `*` wildcard, so any key could match. */ matchAnyKey: boolean; }; /** Build a lookup of all increment/decrement keys across active nudges (resolved). */ export declare function buildPlusMinusTriggerKeyLookup(nudges: PlusMinusNudge[], globalOptions: Readonly<PlusMinusOptions> | undefined): PlusMinusTriggerKeyLookup; /** * O(1) check: whether this pressed key could match any configured Plus Minus trigger. * When false, skip fetching cells / running nudge rules. */ export declare function plusMinusKeyCouldTrigger(keyEventString: string, lookup: PlusMinusTriggerKeyLookup): boolean;