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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 {AriaButtonProps} from '../button/useButton';\nimport {clearGlobalDnDState, isInternalDropOperation, setDraggingKeys, useDragModality} from './utils';\nimport {DraggableCollectionState} from 'react-stately/useDraggableCollectionState';\nimport {HTMLAttributes} from 'react';\n// @ts-ignore\nimport intlMessages from '../../intl/dnd/*.json';\nimport {Key} from '@react-types/shared';\nimport {useDescription} from '../utils/useDescription';\nimport {useDrag} from './useDrag';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\n\nexport interface DraggableItemProps {\n  /** The key of the draggable item within the collection. */\n  key: Key,\n  /**\n   * Whether the item has an explicit focusable drag affordance to initiate accessible drag and drop mode.\n   * If true, the dragProps will omit these event handlers, and they will be applied to dragButtonProps instead.\n   */\n  hasDragButton?: boolean,\n  /**\n   * Whether the item has a primary action (e.g. Enter key or long press) that would\n   * conflict with initiating accessible drag and drop. If true, the Alt key must be held to\n   * start dragging with a keyboard, and long press is disabled until selection mode is entered.\n   * This should be passed from the associated collection item hook (e.g. useOption, useGridListItem, etc.).\n   */\n  hasAction?: boolean\n}\n\nexport interface DraggableItemResult {\n  /** Props for the draggable item. */\n  dragProps: HTMLAttributes<HTMLElement>,\n  /** Props for the explicit drag button affordance, if any. */\n  dragButtonProps: AriaButtonProps\n}\n\nconst MESSAGES = {\n  keyboard: {\n    selected: 'dragSelectedKeyboard',\n    notSelected: 'dragDescriptionKeyboard'\n  },\n  touch: {\n    selected: 'dragSelectedLongPress',\n    notSelected: 'dragDescriptionLongPress'\n  },\n  virtual: {\n    selected: 'dragDescriptionVirtual',\n    notSelected: 'dragDescriptionVirtual'\n  }\n};\n\n/**\n * Handles drag interactions for an item within a draggable collection.\n */\nexport function useDraggableItem(props: DraggableItemProps, state: DraggableCollectionState): DraggableItemResult {\n  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n  let isDisabled = state.isDisabled || state.selectionManager.isDisabled(props.key);\n  let {dragProps, dragButtonProps} = useDrag({\n    getItems() {\n      return state.getItems(props.key);\n    },\n    preview: state.preview,\n    getAllowedDropOperations: state.getAllowedDropOperations,\n    hasDragButton: props.hasDragButton,\n    onDragStart(e) {\n      state.startDrag(props.key, e);\n      // Track draggingKeys for useDroppableCollection's default onDrop handler and useDroppableCollectionState's default getDropOperation\n      setDraggingKeys(state.draggingKeys);\n    },\n    onDragMove(e) {\n      state.moveDrag(e);\n    },\n    onDragEnd(e) {\n      let {dropOperation} = e;\n      let isInternal = dropOperation === 'cancel' ? false : isInternalDropOperation();\n      state.endDrag({...e, keys: state.draggingKeys, isInternal});\n      clearGlobalDnDState();\n    }\n  });\n\n  let item = state.collection.getItem(props.key);\n  let numKeysForDrag = state.getKeysForDrag(props.key).size;\n  let isSelected = numKeysForDrag > 1 && state.selectionManager.isSelected(props.key);\n  let dragButtonLabel: string | undefined;\n  let description: string | undefined;\n\n  // Override description to include selected item count.\n  let modality = useDragModality();\n  if (!props.hasDragButton && state.selectionManager.selectionMode !== 'none') {\n    let msg = MESSAGES[modality][isSelected ? 'selected' : 'notSelected'];\n    if (props.hasAction && modality === 'keyboard') {\n      msg += 'Alt';\n    }\n\n    if (isSelected) {\n      description = stringFormatter.format(msg, {count: numKeysForDrag});\n    } else {\n      description = stringFormatter.format(msg);\n    }\n\n    // Remove the onClick handler from useDrag. Long pressing will be required on touch devices,\n    // and NVDA/JAWS are always in forms mode within collection components.\n    delete dragProps.onClick;\n  } else {\n    if (isSelected) {\n      dragButtonLabel = stringFormatter.format('dragSelectedItems', {count: numKeysForDrag});\n    } else {\n      let itemText = state.collection.getTextValue?.(props.key) ?? item?.textValue ?? '';\n      dragButtonLabel = stringFormatter.format('dragItem', {itemText});\n    }\n  }\n\n  let descriptionProps = useDescription(description);\n  if (description) {\n    Object.assign(dragProps, descriptionProps);\n  }\n\n  if (!props.hasDragButton && props.hasAction) {\n    let {onKeyDownCapture, onKeyUpCapture} = dragProps;\n    if (modality === 'touch') {\n      // Remove long press description if an action is present, because in that case long pressing selects the item.\n      delete dragProps['aria-describedby'];\n    }\n\n    // Require Alt key if there is a conflicting action.\n    dragProps.onKeyDownCapture = e => {\n      if (e.altKey) {\n        onKeyDownCapture?.(e);\n      }\n    };\n\n    dragProps.onKeyUpCapture = e => {\n      if (e.altKey) {\n        onKeyUpCapture?.(e);\n      }\n    };\n  }\n\n  return {\n    dragProps: isDisabled ? {} : dragProps,\n    dragButtonProps: {\n      ...dragButtonProps,\n      isDisabled,\n      'aria-label': dragButtonLabel\n    }\n  };\n}\n"],"names":[],"version":3,"file":"useDraggableItem.cjs.map"}