Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.151/page_editor/plugins/fragments_and_widgets/hooks/useKeyboardNavigation",["module","exports","require","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$react","../../../app/config/constants/keycodes","../../../app/config/constants/listItemTypes"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function useKeyboardNavigation({handleOpen:t,type:n}){const[r,u]=(0,s.useState)(null),[c,a]=(0,s.useState)(!1);return(0,s.useEffect)((()=>{const e=null==r?void 0:r.closest('[role="menubar"]'),t=(null==r?void 0:r.closest("li"))===(null==e?void 0:e.firstChild);a(t)}),[r]),(0,o.useEventListener)("keydown",(o=>{e.includes(o.keyCode)&&(o.preventDefault(),n===i.LIST_ITEM_TYPES.header?function onHeaderKeyDown(e,t,n){if(t===l.ARROW_DOWN_KEYCODE){const t=e.nextSibling,n=null==t?void 0:t.querySelector("li");if(n)n.focus();else{const t=e.parentElement.nextSibling,n=null==t?void 0:t.querySelector("button");null==n||n.focus()}}else if(t===l.ARROW_UP_KEYCODE){const t=e.parentElement.previousSibling;if(!t)return;const n=t.querySelector("ul");if(n){n.lastChild.focus()}else{t.querySelector("button").focus()}}else t===l.ARROW_RIGHT_KEYCODE?n(!0):t===l.ARROW_LEFT_KEYCODE&&n(!1)}(r,o.keyCode,t):n===i.LIST_ITEM_TYPES.listItem&&function onListItemKeyDown(e,t){if(t===l.ARROW_UP_KEYCODE)if(e.previousSibling)e.previousSibling.focus();else{e.closest(".page-editor__collapse").querySelector("button").focus()}else if(t===l.ARROW_DOWN_KEYCODE)if(e.nextSibling)e.nextSibling.focus();else{const t=e.closest(".page-editor__collapse").nextSibling,n=null==t?void 0:t.querySelector("button");null==n||n.focus()}else if(t===l.ARROW_RIGHT_KEYCODE)if(document.activeElement===e){e.querySelector("button").focus()}else{const e=document.activeElement.nextSibling;null==e||e.focus()}else if(t===l.ARROW_LEFT_KEYCODE){const t=document.activeElement.previousSibling;"BUTTON"===(null==t?void 0:t.tagName)?t.focus():e.focus()}}(r,o.keyCode))}),!0,r),(0,o.useEventListener)("focus",(()=>a(!0)),!0,r),(0,o.useEventListener)("blur",(e=>{const t=e.target.closest('[role="menubar"]'),n=e.relatedTarget;t.contains(n)&&a(!1)}),!0,r),{isTarget:c,setElement:u}};var o=n("@liferay/frontend-js-react-web"),s=n("liferay!frontend-js-react-web$react"),l=n("../../../app/config/constants/keycodes"),i=n("../../../app/config/constants/listItemTypes");const e=[l.ARROW_DOWN_KEYCODE,l.ARROW_LEFT_KEYCODE,l.ARROW_RIGHT_KEYCODE,l.ARROW_UP_KEYCODE]}}));
//# sourceMappingURL=useKeyboardNavigation.js.map