Line data Source code
1 : const REKA_LAYER_SELECTORS =
2 : '[data-dismissable-layer], [data-reka-popper-content-wrapper]'
3 :
4 : const TOAST_SELECTORS = '[data-toast-kind], [data-toast-dock]'
5 :
6 2356 : const OWNED_LAYER_SELECTORS = `${REKA_LAYER_SELECTORS}, ${TOAST_SELECTORS}`
7 :
8 : type OutsideEvent = CustomEvent<{ originalEvent: Event }>
9 :
10 2356 : const IME_PROCESS_KEY_CODE = 229
11 :
12 2 : function isInsideOverlay(target: EventTarget | null): boolean {
13 2 : return (
14 : target instanceof Element && target.closest(OWNED_LAYER_SELECTORS) !== null
15 : )
16 : }
17 :
18 2 : export function onRekaPointerDownOutside(
19 : options: { dismissOnPointerDownOutside?: boolean },
20 : event: OutsideEvent
21 : ) {
22 2 : if (isInsideOverlay(event.detail.originalEvent.target)) {
23 0 : event.preventDefault()
24 0 : return
25 : }
26 2 : if (options.dismissOnPointerDownOutside === false) {
27 0 : event.preventDefault()
28 : }
29 : }
30 :
31 17 : export function onRekaEscapeKeyDown(
32 : options: { closable?: boolean },
33 : event: KeyboardEvent
34 : ) {
35 17 : const isImeKey = event.isComposing || event.keyCode === IME_PROCESS_KEY_CODE
36 17 : if (options.closable === false || isImeKey) event.preventDefault()
37 : }
|