{"version":3,"file":"tree-view-keyboard-helpers.mjs","names":[],"sources":["../../../src/tree-view/tree-view-keyboard-helpers.ts"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\nimport { findFocusableChildren } from '../_common/utils';\n\nconst focusElementInElement = (\n  parentElement: HTMLElement,\n  newParentElement: HTMLElement,\n  activeElement: HTMLElement,\n) => {\n  const focusable = findFocusableChildren(newParentElement);\n  const focusableCurrent = findFocusableChildren(parentElement);\n  const cellIndex = focusableCurrent.indexOf(activeElement);\n\n  let newIndex = cellIndex;\n\n  if (cellIndex >= focusable.length) {\n    newIndex = focusable.length - 1;\n  } else if (cellIndex < 0) {\n    newIndex = 0;\n  }\n  const element = focusable[newIndex];\n  if (element instanceof HTMLElement) {\n    element.focus();\n  }\n};\n\nexport const focusNextRow = (parentElement: HTMLElement) => {\n  const { nextElementSibling } = parentElement;\n  if (nextElementSibling instanceof HTMLElement) {\n    nextElementSibling.focus();\n  }\n};\n\nexport const focusPreviousRow = (parentElement: HTMLElement) => {\n  const { previousElementSibling } = parentElement;\n  if (previousElementSibling instanceof HTMLElement) {\n    previousElementSibling.focus();\n  }\n};\n\nexport const focusCellInNextRow = (parentElement: HTMLElement) => {\n  const { nextElementSibling } = parentElement;\n  const { activeElement } = document;\n  if (\n    !(nextElementSibling instanceof HTMLElement) ||\n    !(activeElement instanceof HTMLElement)\n  ) {\n    return;\n  }\n\n  focusElementInElement(parentElement, nextElementSibling, activeElement);\n};\n\nexport const focusCellInPreviousRow = (parentElement: HTMLElement) => {\n  const { previousElementSibling } = parentElement;\n  const { activeElement } = document;\n  if (\n    !(previousElementSibling instanceof HTMLElement) ||\n    !(activeElement instanceof HTMLElement)\n  ) {\n    return;\n  }\n\n  focusElementInElement(parentElement, previousElementSibling, activeElement);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,yBACJ,eACA,kBACA,kBACG;CACH,MAAM,YAAY,sBAAsB,gBAAgB;CAExD,MAAM,YADmB,sBAAsB,aACd,CAAC,CAAC,QAAQ,aAAa;CAExD,IAAI,WAAW;CAEf,IAAI,aAAa,UAAU,QACzB,WAAW,UAAU,SAAS;MACzB,IAAI,YAAY,GACrB,WAAW;CAEb,MAAM,UAAU,UAAU;CAC1B,IAAI,mBAAmB,aACrB,QAAQ,MAAM;AAElB;AAEA,MAAa,gBAAgB,kBAA+B;CAC1D,MAAM,EAAE,uBAAuB;CAC/B,IAAI,8BAA8B,aAChC,mBAAmB,MAAM;AAE7B;AAEA,MAAa,oBAAoB,kBAA+B;CAC9D,MAAM,EAAE,2BAA2B;CACnC,IAAI,kCAAkC,aACpC,uBAAuB,MAAM;AAEjC;AAEA,MAAa,sBAAsB,kBAA+B;CAChE,MAAM,EAAE,uBAAuB;CAC/B,MAAM,EAAE,kBAAkB;CAC1B,IACE,EAAE,8BAA8B,gBAChC,EAAE,yBAAyB,cAE3B;CAGF,sBAAsB,eAAe,oBAAoB,aAAa;AACxE;AAEA,MAAa,0BAA0B,kBAA+B;CACpE,MAAM,EAAE,2BAA2B;CACnC,MAAM,EAAE,kBAAkB;CAC1B,IACE,EAAE,kCAAkC,gBACpC,EAAE,yBAAyB,cAE3B;CAGF,sBAAsB,eAAe,wBAAwB,aAAa;AAC5E"}