{"version":3,"file":"data-grid-nav.mjs","names":[],"sources":["../../../../src/data-grid/data-grid-nav/data-grid-nav.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 { isValidInteractiveElement } from './helpers';\nimport { Keys } from './keys';\nimport { Selectors } from './selectors';\n\ntype FocusableElement = HTMLElement | SVGElement;\n\nexport type Config =\n  | {\n      /** Enable debug logs */\n      isDebug?: boolean;\n      /** CSS Selectors being used to find Rows, Row Groups, Cells and Focusable elements */\n      selectors?: Partial<typeof Selectors>;\n      /** How many rows to move when pressing page up/down - Default goes to first/last row */\n      pageUpDown?: number;\n    }\n  | undefined;\n\nexport class DataGridNav {\n  private selectors: Record<keyof typeof Selectors, string>;\n  readonly pageUpDown: number | undefined;\n  private keys: string[] = [];\n  private disabled: boolean;\n  readonly debug: boolean;\n\n  constructor();\n  constructor(config: Config);\n  constructor(config: Config = {}) {\n    const { selectors = {}, pageUpDown, isDebug = false } = config;\n    this.selectors = { ...Selectors, ...selectors };\n    this.pageUpDown = pageUpDown;\n    this.keys = [];\n    this.debug = isDebug;\n    this.disabled = false;\n  }\n\n  private debugLog = (functionName: string, message: string) => {\n    if (this.debug) {\n      console.info(`[${functionName}]: ${message}`);\n    }\n  };\n\n  /**\n   * Disables the keyboard listener in cases\n   * that elements inside the grid need to use\n   * arrows keys etc., like select dropdowns\n   */\n  public disable() {\n    this.disabled = true;\n  }\n\n  /**\n   * Enables the keyboard listeners\n   */\n  public enable() {\n    this.disabled = false;\n  }\n\n  private isFocusable(el: Element): el is FocusableElement {\n    return el instanceof HTMLElement || el instanceof SVGElement;\n  }\n\n  public focusParentCell(el: Element) {\n    const cell = el.closest(this.selectors.Cell);\n    if (cell && this.isFocusable(cell)) {\n      cell.focus();\n    }\n  }\n\n  /** Used as a keyboard listener for key up */\n  public tableKeyUp() {\n    // TODO: have a cleanup as user can press key\n    //  and then move to another tab, and get back to the same tab\n    // so this will not be empty (the bug exists with .pop)\n    this.keys = [];\n  }\n\n  /** Used as a keyboard listener for key down */\n  public tableKeyDown(event: KeyboardEvent) {\n    this.debugLog('tableKeyDown', `Key pressed: ${event.key}`);\n    if (this.disabled) {\n      this.debugLog('tableKeyDown', 'interaction is disabled');\n      return;\n    }\n    /**\n     * Avoid page scrolling etc.\n     * Enable default behavior for:\n     * Tab, Shift + Tab\n     * TODO: Actually it will be better to just prevent\n     * in ArrowKeys and PageKeys maybe?\n     * Or should the consumer stop propagation?!\n     * Cannot work with preventDefault as it will\n     * first capture the event from an input in cell for example\n     */\n    if (\n      Keys.ArrowDown === event.key ||\n      Keys.ArrowUp === event.key ||\n      Keys.ArrowLeft === event.key ||\n      Keys.ArrowRight === event.key\n    ) {\n      event.preventDefault();\n    }\n\n    /**\n     * Add key to the stack if it's\n     * not the same with the last (long press)\n     */\n    if (\n      this.keys.length === 0 ||\n      this.keys[this.keys.length - 1] !== event.key\n    ) {\n      this.keys.push(event.key);\n    }\n\n    /**\n     * Need to check if we are inside a grid cell\n     * or not to enable/disable Grid Navigation\n     */\n    if (!(event.target instanceof Element)) {\n      return;\n    }\n    const cell = event.target.parentElement?.closest(\n      `${this.selectors.Cell},${this.selectors.Row}`,\n    );\n\n    if (!cell) {\n      this.debugLog('tableKeyDown', 'cell not found');\n      return;\n    }\n\n    if (cell.matches(this.selectors.Cell)) {\n      this.debugLog('tableKeyDown', 'event captured in cell');\n      this.cellNavigation(event);\n    } else {\n      this.debugLog('tableKeyDown', 'event captured in grid');\n      this.gridNavigation(event);\n    }\n  }\n\n  /**\n   * Handles the navigation inside a cell\n   */\n  public cellNavigation(event: KeyboardEvent) {\n    if (!(event.target instanceof Element)) {\n      return;\n    }\n\n    const cell = event.target.closest(this.selectors.Cell);\n\n    if (!cell) {\n      this.debugLog('cellNavigation', 'cell not found');\n      return;\n    }\n\n    if (this.getValidFocusableChild(cell)) {\n      this.debugLog('cellNavigation', 'valid focusable child found');\n      this.gridNavigation(event);\n      return;\n    }\n\n    const focusableWidgets = cell\n      ? [...cell.querySelectorAll(this.selectors.Focusable)]\n      : [];\n    const widgetIdx = focusableWidgets.findIndex((el) => el === event.target);\n\n    /**\n     * Keys: Escape\n     * Restore grid navigation\n     */\n    if (event.key === Keys.Escape && this.isFocusable(cell)) {\n      cell.focus();\n      event.preventDefault();\n      event.stopPropagation();\n      return;\n    }\n\n    /**\n     * Keys: ArrowRight, ArrowDown\n     * Move to the next focusable cell, or the first one\n     *\n     * Arrow Down disabled:\n     * https://github.com/w3c/aria-practices/issues/2739#issuecomment-1613538972\n     */\n    if (event.key === Keys.ArrowRight || event.key === Keys.ArrowDown) {\n      const nextFocusable =\n        widgetIdx === focusableWidgets.length - 1 ? 0 : widgetIdx + 1;\n      const widgetToFocus = focusableWidgets[nextFocusable];\n      if (this.isFocusable(widgetToFocus)) {\n        widgetToFocus.focus();\n      }\n      return;\n    }\n\n    /**\n     * Keys: ArrowLeft, ArrowUp\n     * Move to the previous focusable cell, or the last one\n     *\n     * Arrow Up disabled:\n     * https://github.com/w3c/aria-practices/issues/2739#issuecomment-1613538972\n     */\n    if (event.key === Keys.ArrowLeft || event.key === Keys.ArrowUp) {\n      const previousFocusable =\n        widgetIdx === 0 ? focusableWidgets.length - 1 : widgetIdx - 1;\n      const widgetToFocus = focusableWidgets[previousFocusable];\n      if (this.isFocusable(widgetToFocus)) {\n        widgetToFocus.focus();\n      }\n      return;\n    }\n  }\n\n  /**\n   * Get the valid focusable child of a cell\n   * @returns `FocusableElement` | `null` - The valid focusable child, or null if there are none or multiple focusable children\n   */\n  private getValidFocusableChild(el: Element): FocusableElement | null {\n    const focusableChildren = [\n      ...el.querySelectorAll(this.selectors.Focusable),\n    ];\n    if (\n      focusableChildren.length === 1 &&\n      isValidInteractiveElement(focusableChildren[0]) &&\n      this.isFocusable(focusableChildren[0])\n    ) {\n      return focusableChildren[0];\n    }\n    return null;\n  }\n\n  /**\n   * Handles the navigation outside a cell\n   * on the grid level\n   */\n  public gridNavigation(event: KeyboardEvent) {\n    if (!(event.target instanceof Element)) {\n      return;\n    }\n\n    if (this.keys.length === 1) {\n      /**\n       * Keys: Enter\n       * Should move focus inside the cell to the first focusable element:\n       * https://www.w3.org/WAI/ARIA/apg/patterns/grid/#gridNav_inside\n       */\n      if (event.key === Keys.Enter) {\n        const cell = event.target.querySelector(this.selectors.Focusable);\n        if (cell && this.isFocusable(cell)) {\n          // Enter can trigger child elements:\n          // Source: https://www.reddit.com/r/learnjavascript/comments/14kpj24/wrong_keydown_listener_is_called_with_focus/\n          // If the event.preventDefault causes issues, we can offset the execution with setTimeout\n          cell.focus();\n          event.preventDefault();\n        }\n      }\n\n      /**\n       * Keys: ArrowLeft, ArrowRight\n       * Should move focus to the next/previous cell\n       */\n      if (event.key === Keys.ArrowLeft || event.key === Keys.ArrowRight) {\n        const direction = event.key === Keys.ArrowLeft ? 'prev' : 'next';\n        // Get the closest cell we are currently in\n        const cell = event.target.closest(this.selectors.Cell);\n\n        if (cell && cell instanceof Element) {\n          const closeFocusable = this.findUntil(\n            direction,\n            cell,\n            this.selectors.Cell,\n          );\n          if (closeFocusable) {\n            const focusableChild = this.getValidFocusableChild(closeFocusable);\n\n            const toFocus = focusableChild ?? closeFocusable;\n            toFocus.focus();\n            toFocus.scrollIntoView({\n              block: 'nearest',\n              inline: 'nearest',\n            });\n          }\n        }\n      }\n\n      /**\n       * Keys: Up,Down\n       * Should move focus to the same column of the next/previous row\n       */\n      if (event.key === Keys.ArrowDown || event.key === Keys.ArrowUp) {\n        this.verticalCellNavigation(event);\n        return;\n      }\n\n      /**\n       * Keys: PageUp, PageDown\n       * Should move focus to the first/last row\n       * or a predefined number of rows if user provides a value\n       */\n      if (event.key === Keys.PageUp || event.key === Keys.PageDown) {\n        this.pageCellNavigation(event);\n        return;\n      }\n\n      /**\n       * Keys: Home, End\n       * Should move focus to the first/last cell of the current row\n       */\n      if (event.key === Keys.Home || event.key === Keys.End) {\n        const row = event.target.closest(this.selectors.Row) as Element;\n        const rowChildren = [...(row?.children || [])];\n        if (event.key === 'End') {\n          rowChildren.reverse();\n        }\n        this.focusOnFirstCell(rowChildren);\n      }\n    } else {\n      /**\n       * Keys: Control + Home, Control + End\n       * Should move focus to the first/last cell of the first/last row\n       */\n      const [firstKey, secondKey] = this.keys;\n      if (\n        firstKey === 'Control' &&\n        (secondKey === Keys.Home || secondKey === Keys.End)\n      ) {\n        const row = event.target.closest(this.selectors.Row) as Element;\n        const siblings = row.parentElement?.children;\n\n        if (!siblings) {\n          this.debugLog('cellNavigation', 'siblings not found');\n          return;\n        }\n\n        const rowToFocus =\n          secondKey === Keys.Home ? siblings[0] : siblings[siblings.length - 1];\n        const rowChildren = [...(rowToFocus?.children || [])];\n        if (secondKey === Keys.End) {\n          rowChildren.reverse();\n        }\n        this.focusOnFirstCell(rowChildren);\n      }\n    }\n  }\n\n  private pageCellNavigation(event: KeyboardEvent) {\n    if (!(event.target instanceof Element)) {\n      return;\n    }\n    const row = event.target.closest(this.selectors.Row) as Element;\n    const cell = event.target.closest(this.selectors.Cell) as Element;\n\n    if (row && cell) {\n      const position = this.getColumnIndex(cell);\n\n      if (position === undefined) {\n        this.debugLog('cellNavigation', 'position not found');\n        return;\n      }\n\n      const direction = event.key === Keys.PageUp ? 'prev' : 'next';\n      const siblings = row.parentElement?.children;\n\n      if (!siblings) {\n        this.debugLog('cellNavigation', 'siblings not found');\n        return;\n      }\n\n      // If pageUpDown is defined, we should move that number of rows, or to the closest possible\n      let destinationRow: Element | ChildNode;\n      if (this.pageUpDown) {\n        const methodClbk =\n          direction === 'prev' ? 'previousSibling' : 'nextSibling';\n        let sibling = row[methodClbk];\n        if (sibling === null) {\n          return;\n        }\n\n        let lastVisitedSibling = sibling;\n\n        for (let index = 0; index < this.pageUpDown - 1 && sibling; index++) {\n          sibling = sibling[methodClbk];\n          if (sibling) {\n            lastVisitedSibling = sibling;\n          }\n        }\n        destinationRow = sibling ? sibling : lastVisitedSibling;\n      } else {\n        destinationRow =\n          direction === 'prev' ? siblings[0] : siblings[siblings.length - 1];\n      }\n      if (!destinationRow || !(destinationRow instanceof Element)) {\n        return;\n      }\n\n      const child = destinationRow.children[position];\n      if (child && this.isFocusable(child)) {\n        const focusableGrandChild = this.getValidFocusableChild(child);\n        if (focusableGrandChild) {\n          focusableGrandChild.focus();\n        } else {\n          child.focus();\n        }\n      }\n    }\n  }\n\n  private verticalCellNavigation(event: KeyboardEvent) {\n    if (!(event.target instanceof Element)) {\n      return;\n    }\n    const row = event.target.closest(this.selectors.Row) as Element;\n    const cell = event.target.closest(this.selectors.Cell) as Element;\n\n    if (row && cell) {\n      const cellPosition = this.getColumnIndex(cell);\n      const rowPosition = this.getRowIndex(row);\n      this.debugLog('gridNavigation', `Initial row position: ${rowPosition}`);\n      this.debugLog('gridNavigation', `Initial cell position: ${cellPosition}`);\n      if (cellPosition === undefined || rowPosition === undefined) {\n        this.debugLog(\n          'verticalCellNavigation',\n          'row or cell position not found',\n        );\n        return;\n      }\n\n      const direction = event.key === Keys.ArrowUp ? 'prev' : 'next';\n\n      /** Find previous rowgroup and focus on the proper cell */\n      if (rowPosition === 0 && direction === 'prev') {\n        const currentRowGroup = row.parentElement?.closest(\n          this.selectors.RowGroup,\n        );\n        const siblingRowGroups = [\n          ...(currentRowGroup?.parentElement?.children || []),\n        ];\n        const currentRowGroupIdx = siblingRowGroups.findIndex(\n          (el) => el === currentRowGroup,\n        );\n        if (currentRowGroupIdx !== 0) {\n          const previousRowGroup = siblingRowGroups[currentRowGroupIdx - 1];\n          const rows = [\n            ...previousRowGroup.querySelectorAll(this.selectors.Row),\n          ];\n          const child = rows[rows.length - 1].children[cellPosition];\n          if (child && this.isFocusable(child)) {\n            const focusableGrandChild = this.getValidFocusableChild(child);\n            if (focusableGrandChild) {\n              focusableGrandChild.focus();\n            } else {\n              child.focus();\n            }\n          }\n          return;\n        }\n      }\n\n      const siblingRows = [\n        ...(row.parentElement?.querySelectorAll(this.selectors.Row) || []),\n      ];\n      /** Find next rowgroup and focus on the proper cell */\n      if (rowPosition === siblingRows.length - 1 && direction === 'next') {\n        const currentRowGroup = row.parentElement?.closest(\n          this.selectors.RowGroup,\n        );\n        const siblingRowGroups = [\n          ...(currentRowGroup?.parentElement?.children || []),\n        ];\n        const currentRowGroupIdx = siblingRowGroups.findIndex(\n          (el) => el === currentRowGroup,\n        );\n        if (currentRowGroupIdx !== siblingRowGroups.length - 1) {\n          const nextRowGroup = siblingRowGroups[currentRowGroupIdx + 1];\n          const rows = [...nextRowGroup.querySelectorAll(this.selectors.Row)];\n          const child = rows[0].children[cellPosition];\n          if (child && this.isFocusable(child)) {\n            const focusableGrandChild = this.getValidFocusableChild(child);\n            if (focusableGrandChild) {\n              focusableGrandChild.focus();\n            } else {\n              child.focus();\n            }\n          }\n          return;\n        }\n        return;\n      }\n\n      /** Navigation in the same rowgroup */\n      const destinationRow = this.findUntil(direction, row, this.selectors.Row);\n      if (!destinationRow) {\n        return;\n      }\n\n      const child = destinationRow.children[cellPosition];\n      if (child && this.isFocusable(child)) {\n        const focusableGrandChild = this.getValidFocusableChild(child);\n        if (focusableGrandChild) {\n          focusableGrandChild.focus();\n        } else {\n          child.focus();\n        }\n      }\n    }\n  }\n\n  /**\n   * Sending a row `Element` and then the first cell will be focused.\n   *\n   * If you want to focus the last cell then the row children can be passed in\n   * reversed order\n   */\n  private focusOnFirstCell(el: Element[]) {\n    for (let index = 0; index < el.length; index++) {\n      const child = el[index];\n      if (this.isFocusable(child)) {\n        child.focus();\n        return;\n      }\n    }\n  }\n\n  /**\n   * Get the column index of a `cell` based on the first `row` parent.\n   * `cellIndex` could be used, but it's not supported in HTML tables.\n   */\n  private getColumnIndex(cell: Element) {\n    let position = 0;\n    const siblings = cell?.parentNode?.children;\n    if (!siblings) {\n      return undefined;\n    }\n\n    while (cell !== siblings[position] && siblings[position] !== undefined) {\n      position++;\n    }\n\n    // Cell position find was not possible, maybe should log here\n    if (siblings[position] === undefined) {\n      this.debugLog('getColumnIndex', 'position finding was not successful');\n      return undefined;\n    }\n    return position;\n  }\n\n  /**\n   * Get the row index of a `row` based\n   * on its sibling rows\n   */\n  private getRowIndex(row: Element) {\n    let position = 0;\n    const siblings = row?.parentNode?.children;\n    if (!siblings) {\n      return undefined;\n    }\n\n    while (row !== siblings[position] && siblings[position] !== undefined) {\n      position++;\n    }\n\n    // Cell position find was not possible\n    if (siblings[position] === undefined) {\n      this.debugLog('getRowIndex', 'position finding was not successful');\n      return undefined;\n    }\n    return position;\n  }\n\n  /**\n   * Equivalent to prevUntil/nextUntil in jQuery\n   * https://api.jquery.com/prevUntil/\n   */\n  private findUntil(\n    direction: 'next' | 'prev',\n    el: Element | ChildNode,\n    matchSelector: string,\n    exitSelector?: string,\n  ): FocusableElement | null {\n    let element: ChildNode = el;\n    const method = direction === 'next' ? 'nextSibling' : 'previousSibling';\n\n    while (element[method]) {\n      const sibling = element[method];\n      if (!sibling) {\n        return null;\n      }\n      if (\n        exitSelector &&\n        sibling instanceof Element &&\n        sibling.matches(exitSelector)\n      ) {\n        return null;\n      }\n\n      if (sibling instanceof Element && sibling.matches(matchSelector)) {\n        return sibling as FocusableElement;\n      }\n\n      element = sibling;\n    }\n\n    return null;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,cAAb,MAAyB;CASvB,YAAY,SAAiB,CAAC,GAAG;EANjC,KAAQ,OAAiB,CAAC;EAe1B,KAAQ,YAAY,cAAsB,YAAoB;GAC5D,IAAI,KAAK,OACP,Q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