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AQ,UAAU,SAAS,SAAS,SAAS,GAAG,GAAG;QACrD,OACE,QAAQ,OAAO,GAAG;QAGpB,IAAI,UAAU,QAAQ,SAAS,MAC7B,QAAQ,gBAAgB,MAAM,CAAC,iBAAiB;YAC9C,gBAAgB,QAAQ;YACxB,eAAe,QAAQ;QACzB;aACK,IAAI,UAAU,MACnB,QAAQ,gBAAgB,MAAM,CAAC,eAAe;YAC5C,UAAU,QAAQ;QACpB;aACK,IAAI,SAAS,MAClB,QAAQ,gBAAgB,MAAM,CAAC,gBAAgB;YAC7C,UAAU,QAAQ;QACpB;IAEJ;IAEA,IAAI,eAAe,MAAM,YAAY,CAAC;IACtC,IAAI,aAAa,CAAC,cAAc,SAAS,SAAS,CAAC,cAAc;IACjE,OAAO;QACL,oBAAoB;YAClB,GAAG,SAAS;gBACZ;YACA,wBAAwB,gBAAgB,MAAM,CAAC;YAC/C,cAAc;YACd,mBAAmB;YACnB,eAAe;YACf,UAAU;QACZ;sBACA;QACA,qFAAqF;QACrF,yGAAyG;QACzG,0FAA0F;QAC1F,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC/B;AACF","sources":["packages/react-aria/src/dnd/useDropIndicator.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 * as DragManager from './DragManager';\nimport {DroppableCollectionState} from 'react-stately/useDroppableCollectionState';\nimport {DropTarget, FocusableElement, Key, RefObject} from '@react-types/shared';\nimport {getDroppableCollectionId} from './utils';\nimport {HTMLAttributes} from 'react';\n// @ts-ignore\nimport intlMessages from '../../intl/dnd/*.json';\nimport {useDroppableItem} from './useDroppableItem';\nimport {useId} from '../utils/useId';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\n\nexport interface DropIndicatorProps {\n /** The drop target that the drop indicator represents. */\n target: DropTarget;\n /** The ref to the activate button. */\n activateButtonRef?: RefObject<FocusableElement | null>;\n}\n\nexport interface DropIndicatorAria {\n /** Props for the drop indicator element. */\n dropIndicatorProps: HTMLAttributes<HTMLElement>;\n /** Whether the drop indicator is currently the active drop target. */\n isDropTarget: boolean;\n /**\n * Whether the drop indicator is hidden, both visually and from assistive technology.\n * Use this to determine whether to omit the element from the DOM entirely.\n */\n isHidden: boolean;\n}\n\n/**\n * Handles drop interactions for a target within a droppable collection.\n */\nexport function useDropIndicator(\n props: DropIndicatorProps,\n state: DroppableCollectionState,\n ref: RefObject<HTMLElement | null>\n): DropIndicatorAria {\n let {target} = props;\n let {collection} = state;\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let dragSession = DragManager.useDragSession();\n let {dropProps} = useDroppableItem(props, state, ref);\n let id = useId();\n let getText = (key: Key | null) => {\n if (key == null) {\n return '';\n } else {\n return collection.getTextValue?.(key) ?? collection.getItem(key)?.textValue ?? '';\n }\n };\n\n let label = '';\n let labelledBy: string | undefined;\n if (target.type === 'root') {\n label = stringFormatter.format('dropOnRoot');\n labelledBy = `${id} ${getDroppableCollectionId(state)}`;\n } else if (target.dropPosition === 'on') {\n label = stringFormatter.format('dropOnItem', {\n itemText: getText(target.key)\n });\n } else {\n let before: Key | null | undefined;\n let after: Key | null | undefined;\n if (target.dropPosition === 'before') {\n let prevKey = collection.getItem(target.key)?.prevKey;\n let prevNode = prevKey != null ? collection.getItem(prevKey) : null;\n before = prevNode?.type === 'item' ? prevNode.key : null;\n } else {\n before = target.key;\n }\n\n if (target.dropPosition === 'after') {\n let nextKey = collection.getItem(target.key)?.nextKey;\n let nextNode = nextKey != null ? collection.getItem(nextKey) : null;\n after = nextNode?.type === 'item' ? nextNode.key : null;\n } else {\n after = target.key;\n }\n\n if (before != null && after != null) {\n label = stringFormatter.format('insertBetween', {\n beforeItemText: getText(before),\n afterItemText: getText(after)\n });\n } else if (before != null) {\n label = stringFormatter.format('insertAfter', {\n itemText: getText(before)\n });\n } else if (after != null) {\n label = stringFormatter.format('insertBefore', {\n itemText: getText(after)\n });\n }\n }\n\n let isDropTarget = state.isDropTarget(target);\n let ariaHidden = !dragSession ? 'true' : dropProps['aria-hidden'];\n return {\n dropIndicatorProps: {\n ...dropProps,\n id,\n 'aria-roledescription': stringFormatter.format('dropIndicator'),\n 'aria-label': label,\n 'aria-labelledby': labelledBy,\n 'aria-hidden': ariaHidden,\n tabIndex: -1\n },\n isDropTarget,\n // If aria-hidden, we are either not in a drag session or the drop target is invalid.\n // In that case, there's no need to render anything at all unless we need to show the indicator visually.\n // This can happen when dragging using the native DnD API as opposed to keyboard dragging.\n isHidden: !isDropTarget && !!ariaHidden\n };\n}\n"],"names":[],"version":3,"file":"useDropIndicator.mjs.map"}