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AwB,OAAO,IAAK,EAAE,WAAW,KAAK,OAAM,KAAM,MAAM,cAAc,IAAI,MAC3H,UAAU;QAEd;IACF;IACA,IAAI,uBAAC,mBAAmB,EAAC,GAAG,CAAA,GAAA,2CAAgB;IAE5C,OAAO;QACL,cAAc,CAAA,GAAA,oCAAS,EACrB,eACA;YAAC,GAAG,SAAS;uBAAE;QAAS,GACxB,YACA;YAAC,OAAO;gBAAC,aAAa;YAAM;QAAC;QAE/B,YAAY,CAAA,GAAA,oCAAS,EACnB,qBACA;gBACE;YACA,QAAQ;gBACN,UAAU;YACZ;sBACA;YACA,UAAU;QACZ,GACA;oBAEF;IACF;AACF","sources":["packages/react-aria/src/table/useTableColumnResize.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ChangeEvent, useCallback, useEffect, useRef} from 'react';\nimport {ColumnSize} from 'react-stately/useTableState';\nimport {DOMAttributes, FocusableElement, Key, RefObject} from '@react-types/shared';\nimport {focusSafely} from '../interactions/focusSafely';\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport {getColumnHeaderId} from './utils';\nimport {GridNode} from 'react-stately/private/grid/GridCollection';\nimport intlMessages from '../../intl/table/*.json';\nimport {mergeProps} from '../utils/mergeProps';\nimport {TableColumnResizeState} from 'react-stately/useTableState';\nimport {useDescription} from '../utils/useDescription';\nimport {useEffectEvent} from '../utils/useEffectEvent';\nimport {useId} from '../utils/useId';\nimport {useInteractionModality} from '../interactions/useFocusVisible';\nimport {useKeyboard} from '../interactions/useKeyboard';\nimport {useLocale} from '../i18n/I18nProvider';\n// @ts-ignore\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useMove} from '../interactions/useMove';\nimport {usePress} from '../interactions/usePress';\nimport {useVisuallyHidden} from '../visually-hidden/VisuallyHidden';\n\nexport interface TableColumnResizeAria {\n  /** Props for the visually hidden input element. */\n  inputProps: DOMAttributes,\n  /** Props for the resizer element. */\n  resizerProps: DOMAttributes,\n  /** Whether this column is currently being resized. */\n  isResizing: boolean\n}\n\nexport interface AriaTableColumnResizeProps<T> {\n  /** An object representing the [column header](https://www.w3.org/TR/wai-aria-1.1/#columnheader). Contains all the relevant information that makes up the column header. */\n  column: GridNode<T>,\n  /** Aria label for the hidden input. Gets read when resizing. */\n  'aria-label': string,\n  /**\n   * Ref to the trigger if resizing was started from a column header menu. If it's provided,\n   * focus will be returned there when resizing is done. If it isn't provided, it is assumed that the resizer is\n   * visible at all time and keyboard resizing is started via pressing Enter on the resizer and not on focus.\n   * */\n  triggerRef?: RefObject<FocusableElement | null>,\n  /** If resizing is disabled. */\n  isDisabled?: boolean,\n  /** Called when resizing starts. */\n  onResizeStart?: (widths: Map<Key, ColumnSize>) => void,\n  /** Called for every resize event that results in new column sizes. */\n  onResize?: (widths: Map<Key, ColumnSize>) => void,\n  /** Called when resizing ends. */\n  onResizeEnd?: (widths: Map<Key, ColumnSize>) => void\n}\n\n/**\n * Provides the behavior and accessibility implementation for a table column resizer element.\n * @param props - Props for the resizer.\n * @param state - State for the table's resizable columns, as returned by `useTableColumnResizeState`.\n * @param ref - The ref attached to the resizer's visually hidden input element.\n */\nexport function useTableColumnResize<T>(props: AriaTableColumnResizeProps<T>, state: TableColumnResizeState<T>, ref: RefObject<HTMLInputElement | null>): TableColumnResizeAria {\n  let {column: item, triggerRef, isDisabled, onResizeStart, onResize, onResizeEnd, 'aria-label': ariaLabel} = props;\n  const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/table');\n  let id = useId();\n  let isResizing = state.resizingColumn === item.key;\n  let isResizingRef = useRef(isResizing);\n  let lastSize = useRef<Map<Key, ColumnSize> | null>(null);\n  let wasFocusedOnResizeStart = useRef(false);\n  let editModeEnabled = state.tableState.isKeyboardNavigationDisabled;\n\n  let {direction} = useLocale();\n\n  let startResize = useCallback((item) => {\n    if (!isResizingRef.current) {\n      lastSize.current = state.updateResizedColumns(item.key, state.getColumnWidth(item.key));\n      state.startResize(item.key);\n      state.tableState.setKeyboardNavigationDisabled(true);\n      onResizeStart?.(lastSize.current);\n    }\n    isResizingRef.current = true;\n  }, [state, onResizeStart]);\n\n  let resize = useCallback((item, newWidth) => {\n    let sizes = state.updateResizedColumns(item.key, newWidth);\n    onResize?.(sizes);\n    lastSize.current = sizes;\n  }, [state, onResize]);\n\n  let endResize = useCallback((item) => {\n    if (isResizingRef.current) {\n      if (lastSize.current == null) {\n        lastSize.current = state.updateResizedColumns(item.key, state.getColumnWidth(item.key));\n      }\n\n      state.endResize();\n      state.tableState.setKeyboardNavigationDisabled(false);\n      onResizeEnd?.(lastSize.current);\n      isResizingRef.current = false;\n\n      if (triggerRef?.current && !wasFocusedOnResizeStart.current) {\n        // switch focus back to the column header unless the resizer was already focused when resizing started.\n        focusSafely(triggerRef.current);\n      }\n    }\n    lastSize.current = null;\n  }, [state, triggerRef, onResizeEnd]);\n\n  let {keyboardProps} = useKeyboard({\n    onKeyDown: (e) => {\n      if (editModeEnabled) {\n        if (e.key === 'Escape' || e.key === 'Enter' || e.key === ' ' || e.key === 'Tab') {\n          e.preventDefault();\n          endResize(item);\n        }\n      } else {\n        // Continue propagation on keydown events so they still bubbles to useSelectableCollection and are handled there\n        e.continuePropagation();\n\n        if (e.key === 'Enter') {\n          startResize(item);\n        }\n      }\n    }\n  });\n\n  const columnResizeWidthRef = useRef<number>(0);\n  const {moveProps} = useMove({\n    onMoveStart() {\n      columnResizeWidthRef.current = state.getColumnWidth(item.key);\n      startResize(item);\n    },\n    onMove(e) {\n      let {deltaX, deltaY, pointerType} = e;\n      if (direction === 'rtl') {\n        deltaX *= -1;\n      }\n      if (pointerType === 'keyboard') {\n        if (deltaY !== 0 && deltaX === 0) {\n          deltaX = deltaY * -1;\n        }\n        deltaX *= 10;\n      }\n      // if moving up/down only, no need to resize\n      if (deltaX !== 0) {\n        columnResizeWidthRef.current += deltaX;\n        resize(item, columnResizeWidthRef.current);\n      }\n    },\n    onMoveEnd(e) {\n      let {pointerType} = e;\n      columnResizeWidthRef.current = 0;\n      if (pointerType === 'mouse' || (pointerType === 'touch' && wasFocusedOnResizeStart.current)) {\n        endResize(item);\n      }\n    }\n  });\n\n  let onKeyDown = useCallback((e) => {\n    if (editModeEnabled) {\n      moveProps.onKeyDown?.(e);\n    }\n  }, [editModeEnabled, moveProps]);\n\n\n  let min = Math.floor(state.getColumnMinWidth(item.key));\n  let max = Math.floor(state.getColumnMaxWidth(item.key));\n  if (max === Infinity) {\n    max = Number.MAX_SAFE_INTEGER;\n  }\n  let value = Math.floor(state.getColumnWidth(item.key));\n  let modality: string | null = useInteractionModality();\n  if (modality === 'virtual' &&  (typeof window !== 'undefined' && 'ontouchstart' in window)) {\n    modality = 'touch';\n  }\n  let description = triggerRef?.current == null && (modality === 'keyboard' || modality === 'virtual') && !isResizing ? stringFormatter.format('resizerDescription') : undefined;\n  let descriptionProps = useDescription(description);\n  let ariaProps = {\n    'aria-label': ariaLabel,\n    'aria-orientation': 'horizontal' as 'horizontal',\n    'aria-labelledby': `${id} ${getColumnHeaderId(state.tableState, item.key)}`,\n    'aria-valuetext': stringFormatter.format('columnSize', {value}),\n    'type': 'range',\n    min,\n    max,\n    value,\n    ...descriptionProps\n  };\n\n  const focusInput = useCallback(() => {\n    if (ref.current) {\n      focusSafely(ref.current);\n    }\n  }, [ref]);\n\n  let resizingColumn = state.resizingColumn;\n  let prevResizingColumn = useRef<Key | null>(null);\n  let startResizeEvent = useEffectEvent(startResize);\n  useEffect(() => {\n    if (prevResizingColumn.current !== resizingColumn && resizingColumn != null && resizingColumn === item.key) {\n      wasFocusedOnResizeStart.current = getActiveElement() === ref.current;\n      startResizeEvent(item);\n      // Delay focusing input until Android Chrome's delayed click after touchend happens: https://bugs.chromium.org/p/chromium/issues/detail?id=1150073\n      let timeout = setTimeout(() => focusInput(), 0);\n      // VoiceOver on iOS has problems focusing the input from a menu.\n      let VOTimeout = setTimeout(focusInput, 400);\n      return () => {\n        clearTimeout(timeout);\n        clearTimeout(VOTimeout);\n      };\n    }\n    prevResizingColumn.current = resizingColumn;\n  }, [resizingColumn, item, focusInput, ref]);\n\n  let onChange = (e: ChangeEvent<HTMLInputElement>) => {\n    let currentWidth = state.getColumnWidth(item.key);\n    let nextValue = parseFloat(getEventTarget(e).value);\n\n    if (nextValue > currentWidth) {\n      nextValue = currentWidth + 10;\n    } else {\n      nextValue = currentWidth - 10;\n    }\n    resize(item, nextValue);\n  };\n\n  let {pressProps} = usePress({\n    preventFocusOnPress: true,\n    onPressStart: (e) => {\n      if (e.ctrlKey || e.altKey || e.metaKey || e.shiftKey || e.pointerType === 'keyboard') {\n        return;\n      }\n      if (e.pointerType === 'virtual' && state.resizingColumn != null) {\n        endResize(item);\n        return;\n      }\n\n      // Sometimes onPress won't trigger for quick taps on mobile so we want to focus the input so blurring away\n      // can cancel resize mode for us.\n      focusInput();\n\n      // If resizer is always visible, mobile screenreader user can access the visually hidden resizer directly and thus we don't need\n      // to handle a virtual click to start the resizer.\n      if (e.pointerType !== 'virtual') {\n        startResize(item);\n      }\n    },\n    onPress: (e) => {\n      if (((e.pointerType === 'touch' && wasFocusedOnResizeStart.current) || e.pointerType === 'mouse') && state.resizingColumn != null) {\n        endResize(item);\n      }\n    }\n  });\n  let {visuallyHiddenProps} = useVisuallyHidden();\n\n  return {\n    resizerProps: mergeProps(\n      keyboardProps,\n      {...moveProps, onKeyDown},\n      pressProps,\n      {style: {touchAction: 'none'}}\n    ),\n    inputProps: mergeProps(\n      visuallyHiddenProps,\n      {\n        id,\n        onBlur: () => {\n          endResize(item);\n        },\n        onChange,\n        disabled: isDisabled\n      },\n      ariaProps\n    ),\n    isResizing\n  };\n}\n"],"names":[],"version":3,"file":"useTableColumnResize.cjs.map"}