event-handlers.ts
ink/events/event-handlers.ts
74
Lines
2202
Bytes
3
Exports
5
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with ui-flow. It contains 74 lines, 5 detected imports, and 3 detected exports.
Important relationships
Detected exports
EventHandlerPropsHANDLER_FOR_EVENTEVENT_HANDLER_PROPS
Keywords
eventbubblevoidcapturefocuseventhandlerhandlerkeyboardeventhandlerpasteeventhandlerhovereventhandlereventhandlerprops
Detected imports
./click-event.js./focus-event.js./keyboard-event.js./paste-event.js./resize-event.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import type { ClickEvent } from './click-event.js'
import type { FocusEvent } from './focus-event.js'
import type { KeyboardEvent } from './keyboard-event.js'
import type { PasteEvent } from './paste-event.js'
import type { ResizeEvent } from './resize-event.js'
type KeyboardEventHandler = (event: KeyboardEvent) => void
type FocusEventHandler = (event: FocusEvent) => void
type PasteEventHandler = (event: PasteEvent) => void
type ResizeEventHandler = (event: ResizeEvent) => void
type ClickEventHandler = (event: ClickEvent) => void
type HoverEventHandler = () => void
/**
* Props for event handlers on Box and other host components.
*
* Follows the React/DOM naming convention:
* - onEventName: handler for bubble phase
* - onEventNameCapture: handler for capture phase
*/
export type EventHandlerProps = {
onKeyDown?: KeyboardEventHandler
onKeyDownCapture?: KeyboardEventHandler
onFocus?: FocusEventHandler
onFocusCapture?: FocusEventHandler
onBlur?: FocusEventHandler
onBlurCapture?: FocusEventHandler
onPaste?: PasteEventHandler
onPasteCapture?: PasteEventHandler
onResize?: ResizeEventHandler
onClick?: ClickEventHandler
onMouseEnter?: HoverEventHandler
onMouseLeave?: HoverEventHandler
}
/**
* Reverse lookup: event type string → handler prop names.
* Used by the dispatcher for O(1) handler lookup per node.
*/
export const HANDLER_FOR_EVENT: Record<
string,
{ bubble?: keyof EventHandlerProps; capture?: keyof EventHandlerProps }
> = {
keydown: { bubble: 'onKeyDown', capture: 'onKeyDownCapture' },
focus: { bubble: 'onFocus', capture: 'onFocusCapture' },
blur: { bubble: 'onBlur', capture: 'onBlurCapture' },
paste: { bubble: 'onPaste', capture: 'onPasteCapture' },
resize: { bubble: 'onResize' },
click: { bubble: 'onClick' },
}
/**
* Set of all event handler prop names, for the reconciler to detect
* event props and store them in _eventHandlers instead of attributes.
*/
export const EVENT_HANDLER_PROPS = new Set<string>([
'onKeyDown',
'onKeyDownCapture',
'onFocus',
'onFocusCapture',
'onBlur',
'onBlurCapture',
'onPaste',
'onPasteCapture',
'onResize',
'onClick',
'onMouseEnter',
'onMouseLeave',
])