{"version":3,"sources":["../src/selectors.ts","../src/index.ts"],"sourcesContent":["export const Selectors = {\n  Cell: '[role=\"cell\"],[role=\"gridcell\"],[role=\"columnheader\"],[role=\"rowheader\"],td,th',\n  Row: '[role=\"row\"],tr',\n  RowGroup: '[role=\"rowgroup\"],thead,tbody,tfoot',\n  /** Selector from here: https://github.com/Shopify/polaris/blob/main/polaris-react/src/utilities/focus.ts#L10 */\n  Focusable:\n    'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not([aria-disabled=\"true\"]):not([tabindex=\"-1\"]):not(:disabled),*[tabindex]',\n} as const;\n","import { Keys } from './keys';\nimport { Selectors } from './selectors';\n\ntype FocusableElement = HTMLElement | SVGElement;\n\nexport type Config =\n  | {\n      /** Enable debug logs */\n      debug?: 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, debug = false } = config;\n    this.selectors = { ...Selectors, ...selectors };\n    this.pageUpDown = pageUpDown;\n    this.keys = [];\n    this.debug = debug;\n    this.disabled = false;\n  }\n\n  private debugLog = (functionName: string, message: string) => {\n    if (this.debug) console.info(`[${functionName}]: ${message}`);\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  private isArrowKey(key: string): boolean {\n    return (\n      key === Keys.ArrowUp ||\n      key === Keys.ArrowDown ||\n      key === Keys.ArrowLeft ||\n      key === Keys.ArrowRight\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 = (e: KeyboardEvent) => {\n    this.debugLog('tableKeyDown', `Key pressed: ${e.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 === e.key ||\n      Keys.ArrowUp === e.key ||\n      Keys.ArrowLeft === e.key ||\n      Keys.ArrowRight === e.key\n    ) {\n      e.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 (this.keys.length === 0 || this.keys[this.keys.length - 1] !== e.key) {\n      this.keys.push(e.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 (!(e.target instanceof Element)) return;\n    const cell = e.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(e);\n    } else {\n      this.debugLog('tableKeyDown', 'event captured in cell');\n      this.gridNavigation(e);\n    }\n  };\n\n  /**\n   * Handles the navigation inside a cell\n   */\n  public cellNavigation(e: KeyboardEvent) {\n    if (!(e.target instanceof Element)) return;\n\n    /**\n     * Keys: Escape\n     * Restore grid navigation\n     */\n    if (e.key === Keys.Escape) {\n      const cell = e.target.closest(this.selectors.Cell);\n      if (cell && this.isFocusable(cell)) {\n        cell.focus();\n        return;\n      }\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 (e.key === Keys.ArrowRight || e.key === Keys.ArrowDown) {\n      const cell = e.target.closest(this.selectors.Cell);\n      if (!cell) {\n        this.debugLog('cellNavigation', 'cell not found');\n        return;\n      }\n\n      const focusableWidgets = [\n        ...cell.querySelectorAll(this.selectors.Focusable),\n      ];\n\n      const widgetIdx = focusableWidgets.findIndex((el) => el === e.target);\n\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\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 (e.key === Keys.ArrowLeft || e.key === Keys.ArrowUp) {\n      const cell = e.target.closest(this.selectors.Cell);\n\n      if (!cell) {\n        this.debugLog('cellNavigation', 'cell not found');\n        return;\n      }\n\n      const focusableWidgets = [\n        ...cell.querySelectorAll(this.selectors.Focusable),\n      ];\n\n      const widgetIdx = focusableWidgets.findIndex((el) => el === e.target);\n\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\n      return;\n    }\n  }\n\n  /**\n   * Handles the navigation outside a cell\n   * on the grid level\n   */\n  public gridNavigation(e: KeyboardEvent) {\n    const { target } = e;\n    if (!(e.target instanceof Element)) return;\n    if (!(target instanceof Element)) return;\n\n    // During rapid navigation, users may press the next arrow key\n    // before releasing the previous one. This ensures navigation\n    // still works when multiple arrow keys are held.\n    const isArrowCombo =\n      this.keys.length >= 2 && this.keys.every((key) => this.isArrowKey(key));\n\n    if (this.keys.length === 1 || isArrowCombo) {\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 (e.key === Keys.Enter) {\n        const cell = e.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 e.preventDefault causes issues, we can offset the execution with setTimeout\n          cell.focus();\n          e.preventDefault();\n        }\n      }\n\n      /**\n       * Keys: ArrowLeft, ArrowRight\n       * Should move focus to the next/previous cell\n       */\n      if (e.key === Keys.ArrowLeft || e.key === Keys.ArrowRight) {\n        const direction = e.key === Keys.ArrowLeft ? 'prev' : 'next';\n        // Get the closest cell we are currently in\n        const cell = e.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            closeFocusable.focus();\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 (e.key === Keys.ArrowDown || e.key === Keys.ArrowUp) {\n        this.verticalCellNavigation(e);\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 (e.key === Keys.PageUp || e.key === Keys.PageDown) {\n        this.pageCellNavigation(e);\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 (e.key === Keys.Home || e.key === Keys.End) {\n        const row = e.target.closest(this.selectors.Row) as Element;\n        const rowChildren = [...(row?.children || [])];\n        if (e.key === 'End') rowChildren.reverse();\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 = e.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) rowChildren.reverse();\n        this.focusOnFirstCell(rowChildren);\n      }\n    }\n  }\n\n  private pageCellNavigation(e: KeyboardEvent) {\n    if (!(e.target instanceof Element)) return;\n    const row = e.target.closest(this.selectors.Row) as Element;\n    const cell = e.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 = e.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) return;\n\n        let lastVisitedSibling = sibling;\n\n        for (let i = 0; i < this.pageUpDown - 1 && sibling; i++) {\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)) return;\n\n      const child = destinationRow.children[position];\n      if (child && this.isFocusable(child)) child.focus();\n    }\n  }\n\n  private verticalCellNavigation(e: KeyboardEvent) {\n    if (!(e.target instanceof Element)) return;\n    const row = e.target.closest(this.selectors.Row) as Element;\n    const cell = e.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 = e.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)) child.focus();\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)) child.focus();\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) return;\n\n      const child = destinationRow.children[cellPosition];\n      if (child && this.isFocusable(child)) child.focus();\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 i = 0; i < el.length; i++) {\n      const child = el[i];\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) return undefined;\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) return undefined;\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) return null;\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":";;;;;;;;;;;;;;;;;;AAAO,IAAM,YAAY;AAAA,EACvB,MAAM;AAAA,EACN,KAAK;AAAA,EACL,UAAU;AAAA;AAAA,EAEV,WACE;AACJ;;;ACSO,IAAM,cAAN,MAAkB;AAAA,EASvB,YAAY,SAAiB,CAAC,GAAG;AANjC,SAAQ,OAAiB,CAAC;AAe1B,SAAQ,WAAW,CAAC,cAAsB,YAAoB;AAC5D,UAAI,KAAK;AAAO,gBAAQ,KAAK,IAAI,YAAY,MAAM,OAAO,EAAE;AAAA,IAC9D;AAgCA;AAAA,SAAO,aAAa,MAAM;AAIxB,WAAK,OAAO,CAAC;AAAA,IACf;AAGA;AAAA,SAAO,eAAe,CAAC,MAAqB;AA5E9C;AA6EI,WAAK,SAAS,gBAAgB,gBAAgB,EAAE,GAAG,EAAE;AACrD,UAAI,KAAK,UAAU;AACjB,aAAK,SAAS,gBAAgB,yBAAyB;AACvD;AAAA,MACF;AAWA,0CACqB,EAAE,mCACJ,EAAE,uCACA,EAAE,yCACD,EAAE,KACtB;AACA,UAAE,eAAe;AAAA,MACnB;AAMA,UAAI,KAAK,KAAK,WAAW,KAAK,KAAK,KAAK,KAAK,KAAK,SAAS,CAAC,MAAM,EAAE,KAAK;AACvE,aAAK,KAAK,KAAK,EAAE,GAAG;AAAA,MACtB;AAMA,UAAI,EAAE,EAAE,kBAAkB;AAAU;AACpC,YAAM,QAAO,OAAE,OAAO,kBAAT,mBAAwB;AAA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