react-aria 3.49.0 → 3.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/private/autocomplete/useAutocomplete.cjs +16 -7
- package/dist/private/autocomplete/useAutocomplete.cjs.map +1 -1
- package/dist/private/autocomplete/useAutocomplete.js +16 -7
- package/dist/private/autocomplete/useAutocomplete.js.map +1 -1
- package/dist/private/autocomplete/useAutocomplete.mjs +16 -7
- package/dist/private/autocomplete/useAutocomplete.mjs.map +1 -1
- package/dist/private/breadcrumbs/useBreadcrumbs.cjs.map +1 -1
- package/dist/private/breadcrumbs/useBreadcrumbs.js.map +1 -1
- package/dist/private/breadcrumbs/useBreadcrumbs.mjs.map +1 -1
- package/dist/private/calendar/useCalendarBase.cjs.map +1 -1
- package/dist/private/calendar/useCalendarBase.js.map +1 -1
- package/dist/private/calendar/useCalendarBase.mjs.map +1 -1
- package/dist/private/calendar/useCalendarCell.cjs.map +1 -1
- package/dist/private/calendar/useCalendarCell.js.map +1 -1
- package/dist/private/calendar/useCalendarCell.mjs.map +1 -1
- package/dist/private/calendar/useCalendarYearPicker.cjs +4 -4
- package/dist/private/calendar/useCalendarYearPicker.cjs.map +1 -1
- package/dist/private/calendar/useCalendarYearPicker.js +4 -4
- package/dist/private/calendar/useCalendarYearPicker.js.map +1 -1
- package/dist/private/calendar/useCalendarYearPicker.mjs +4 -4
- package/dist/private/calendar/useCalendarYearPicker.mjs.map +1 -1
- package/dist/private/calendar/utils.cjs.map +1 -1
- package/dist/private/calendar/utils.js.map +1 -1
- package/dist/private/calendar/utils.mjs.map +1 -1
- package/dist/private/color/useColorArea.cjs.map +1 -1
- package/dist/private/color/useColorArea.js.map +1 -1
- package/dist/private/color/useColorArea.mjs.map +1 -1
- package/dist/private/color/useColorSwatch.cjs.map +1 -1
- package/dist/private/color/useColorSwatch.js.map +1 -1
- package/dist/private/color/useColorSwatch.mjs.map +1 -1
- package/dist/private/combobox/useComboBox.cjs +2 -0
- package/dist/private/combobox/useComboBox.cjs.map +1 -1
- package/dist/private/combobox/useComboBox.js +2 -0
- package/dist/private/combobox/useComboBox.js.map +1 -1
- package/dist/private/combobox/useComboBox.mjs +2 -0
- package/dist/private/combobox/useComboBox.mjs.map +1 -1
- package/dist/private/datepicker/useDateField.cjs.map +1 -1
- package/dist/private/datepicker/useDateField.js.map +1 -1
- package/dist/private/datepicker/useDateField.mjs.map +1 -1
- package/dist/private/datepicker/useDatePicker.cjs.map +1 -1
- package/dist/private/datepicker/useDatePicker.js.map +1 -1
- package/dist/private/datepicker/useDatePicker.mjs.map +1 -1
- package/dist/private/datepicker/useDateRangePicker.cjs.map +1 -1
- package/dist/private/datepicker/useDateRangePicker.js.map +1 -1
- package/dist/private/datepicker/useDateRangePicker.mjs.map +1 -1
- package/dist/private/datepicker/useDisplayNames.cjs +1 -2
- package/dist/private/datepicker/useDisplayNames.cjs.map +1 -1
- package/dist/private/datepicker/useDisplayNames.js +1 -2
- package/dist/private/datepicker/useDisplayNames.js.map +1 -1
- package/dist/private/datepicker/useDisplayNames.mjs +1 -2
- package/dist/private/datepicker/useDisplayNames.mjs.map +1 -1
- package/dist/private/dnd/DragManager.cjs +4 -1
- package/dist/private/dnd/DragManager.cjs.map +1 -1
- package/dist/private/dnd/DragManager.js +4 -1
- package/dist/private/dnd/DragManager.js.map +1 -1
- package/dist/private/dnd/DragManager.mjs +4 -1
- package/dist/private/dnd/DragManager.mjs.map +1 -1
- package/dist/private/dnd/useDrag.cjs.map +1 -1
- package/dist/private/dnd/useDrag.js.map +1 -1
- package/dist/private/dnd/useDrag.mjs.map +1 -1
- package/dist/private/dnd/useDraggableItem.cjs.map +1 -1
- package/dist/private/dnd/useDraggableItem.js.map +1 -1
- package/dist/private/dnd/useDraggableItem.mjs.map +1 -1
- package/dist/private/dnd/useDropIndicator.cjs.map +1 -1
- package/dist/private/dnd/useDropIndicator.js.map +1 -1
- package/dist/private/dnd/useDropIndicator.mjs.map +1 -1
- package/dist/private/dnd/useVirtualDrop.cjs.map +1 -1
- package/dist/private/dnd/useVirtualDrop.js.map +1 -1
- package/dist/private/dnd/useVirtualDrop.mjs.map +1 -1
- package/dist/private/dnd/utils.cjs +13 -3
- package/dist/private/dnd/utils.cjs.map +1 -1
- package/dist/private/dnd/utils.js +13 -3
- package/dist/private/dnd/utils.js.map +1 -1
- package/dist/private/dnd/utils.mjs +13 -3
- package/dist/private/dnd/utils.mjs.map +1 -1
- package/dist/private/form/useFormValidation.cjs +1 -1
- package/dist/private/form/useFormValidation.cjs.map +1 -1
- package/dist/private/form/useFormValidation.js +1 -1
- package/dist/private/form/useFormValidation.js.map +1 -1
- package/dist/private/form/useFormValidation.mjs +1 -1
- package/dist/private/form/useFormValidation.mjs.map +1 -1
- package/dist/private/grid/useGridSelectionAnnouncement.cjs.map +1 -1
- package/dist/private/grid/useGridSelectionAnnouncement.js.map +1 -1
- package/dist/private/grid/useGridSelectionAnnouncement.mjs.map +1 -1
- package/dist/private/grid/useGridSelectionCheckbox.cjs.map +1 -1
- package/dist/private/grid/useGridSelectionCheckbox.js.map +1 -1
- package/dist/private/grid/useGridSelectionCheckbox.mjs.map +1 -1
- package/dist/private/grid/useHighlightSelectionDescription.cjs.map +1 -1
- package/dist/private/grid/useHighlightSelectionDescription.js.map +1 -1
- package/dist/private/grid/useHighlightSelectionDescription.mjs.map +1 -1
- package/dist/private/gridlist/useGridList.cjs +2 -1
- package/dist/private/gridlist/useGridList.cjs.map +1 -1
- package/dist/private/gridlist/useGridList.js +2 -1
- package/dist/private/gridlist/useGridList.js.map +1 -1
- package/dist/private/gridlist/useGridList.mjs +2 -1
- package/dist/private/gridlist/useGridList.mjs.map +1 -1
- package/dist/private/gridlist/useGridListItem.cjs +62 -21
- package/dist/private/gridlist/useGridListItem.cjs.map +1 -1
- package/dist/private/gridlist/useGridListItem.js +63 -22
- package/dist/private/gridlist/useGridListItem.js.map +1 -1
- package/dist/private/gridlist/useGridListItem.mjs +62 -21
- package/dist/private/gridlist/useGridListItem.mjs.map +1 -1
- package/dist/private/interactions/createEventHandler.cjs +3 -0
- package/dist/private/interactions/createEventHandler.cjs.map +1 -1
- package/dist/private/interactions/createEventHandler.js +3 -0
- package/dist/private/interactions/createEventHandler.js.map +1 -1
- package/dist/private/interactions/createEventHandler.mjs +3 -0
- package/dist/private/interactions/createEventHandler.mjs.map +1 -1
- package/dist/private/interactions/useFocusVisible.cjs +16 -5
- package/dist/private/interactions/useFocusVisible.cjs.map +1 -1
- package/dist/private/interactions/useFocusVisible.js +16 -5
- package/dist/private/interactions/useFocusVisible.js.map +1 -1
- package/dist/private/interactions/useFocusVisible.mjs +16 -5
- package/dist/private/interactions/useFocusVisible.mjs.map +1 -1
- package/dist/private/menu/useMenu.cjs.map +1 -1
- package/dist/private/menu/useMenu.js.map +1 -1
- package/dist/private/menu/useMenu.mjs.map +1 -1
- package/dist/private/menu/useMenuItem.cjs +1 -1
- package/dist/private/menu/useMenuItem.cjs.map +1 -1
- package/dist/private/menu/useMenuItem.js +1 -1
- package/dist/private/menu/useMenuItem.js.map +1 -1
- package/dist/private/menu/useMenuItem.mjs +1 -1
- package/dist/private/menu/useMenuItem.mjs.map +1 -1
- package/dist/private/menu/useMenuTrigger.cjs.map +1 -1
- package/dist/private/menu/useMenuTrigger.js.map +1 -1
- package/dist/private/menu/useMenuTrigger.mjs.map +1 -1
- package/dist/private/menu/utils.cjs.map +1 -1
- package/dist/private/menu/utils.js.map +1 -1
- package/dist/private/menu/utils.mjs.map +1 -1
- package/dist/private/numberfield/useNumberField.cjs.map +1 -1
- package/dist/private/numberfield/useNumberField.js.map +1 -1
- package/dist/private/numberfield/useNumberField.mjs.map +1 -1
- package/dist/private/overlays/DismissButton.cjs.map +1 -1
- package/dist/private/overlays/DismissButton.js.map +1 -1
- package/dist/private/overlays/DismissButton.mjs.map +1 -1
- package/dist/private/overlays/calculatePosition.cjs +7 -7
- package/dist/private/overlays/calculatePosition.cjs.map +1 -1
- package/dist/private/overlays/calculatePosition.js +7 -7
- package/dist/private/overlays/calculatePosition.js.map +1 -1
- package/dist/private/overlays/calculatePosition.mjs +7 -7
- package/dist/private/overlays/calculatePosition.mjs.map +1 -1
- package/dist/private/overlays/useOverlayPosition.cjs +3 -2
- package/dist/private/overlays/useOverlayPosition.cjs.map +1 -1
- package/dist/private/overlays/useOverlayPosition.js +3 -2
- package/dist/private/overlays/useOverlayPosition.js.map +1 -1
- package/dist/private/overlays/useOverlayPosition.mjs +3 -2
- package/dist/private/overlays/useOverlayPosition.mjs.map +1 -1
- package/dist/private/searchfield/useSearchField.cjs.map +1 -1
- package/dist/private/searchfield/useSearchField.js.map +1 -1
- package/dist/private/searchfield/useSearchField.mjs.map +1 -1
- package/dist/private/select/useSelect.cjs +1 -2
- package/dist/private/select/useSelect.cjs.map +1 -1
- package/dist/private/select/useSelect.js +1 -2
- package/dist/private/select/useSelect.js.map +1 -1
- package/dist/private/select/useSelect.mjs +1 -2
- package/dist/private/select/useSelect.mjs.map +1 -1
- package/dist/private/selection/ListKeyboardDelegate.cjs +31 -3
- package/dist/private/selection/ListKeyboardDelegate.cjs.map +1 -1
- package/dist/private/selection/ListKeyboardDelegate.js +31 -3
- package/dist/private/selection/ListKeyboardDelegate.js.map +1 -1
- package/dist/private/selection/ListKeyboardDelegate.mjs +31 -3
- package/dist/private/selection/ListKeyboardDelegate.mjs.map +1 -1
- package/dist/private/selection/useSelectableCollection.cjs +20 -14
- package/dist/private/selection/useSelectableCollection.cjs.map +1 -1
- package/dist/private/selection/useSelectableCollection.js +26 -19
- package/dist/private/selection/useSelectableCollection.js.map +1 -1
- package/dist/private/selection/useSelectableCollection.mjs +20 -14
- package/dist/private/selection/useSelectableCollection.mjs.map +1 -1
- package/dist/private/selection/useTypeSelect.cjs +50 -18
- package/dist/private/selection/useTypeSelect.cjs.map +1 -1
- package/dist/private/selection/useTypeSelect.js +51 -19
- package/dist/private/selection/useTypeSelect.js.map +1 -1
- package/dist/private/selection/useTypeSelect.mjs +51 -19
- package/dist/private/selection/useTypeSelect.mjs.map +1 -1
- package/dist/private/spinbutton/useSpinButton.cjs.map +1 -1
- package/dist/private/spinbutton/useSpinButton.js.map +1 -1
- package/dist/private/spinbutton/useSpinButton.mjs.map +1 -1
- package/dist/private/steplist/useStepList.cjs.map +1 -1
- package/dist/private/steplist/useStepList.js.map +1 -1
- package/dist/private/steplist/useStepList.mjs.map +1 -1
- package/dist/private/table/useTable.cjs.map +1 -1
- package/dist/private/table/useTable.js.map +1 -1
- package/dist/private/table/useTable.mjs.map +1 -1
- package/dist/private/table/useTableColumnHeader.cjs.map +1 -1
- package/dist/private/table/useTableColumnHeader.js.map +1 -1
- package/dist/private/table/useTableColumnHeader.mjs.map +1 -1
- package/dist/private/table/useTableColumnResize.cjs.map +1 -1
- package/dist/private/table/useTableColumnResize.js.map +1 -1
- package/dist/private/table/useTableColumnResize.mjs.map +1 -1
- package/dist/private/table/useTableRow.cjs.map +1 -1
- package/dist/private/table/useTableRow.js.map +1 -1
- package/dist/private/table/useTableRow.mjs.map +1 -1
- package/dist/private/table/useTableSelectionCheckbox.cjs.map +1 -1
- package/dist/private/table/useTableSelectionCheckbox.js.map +1 -1
- package/dist/private/table/useTableSelectionCheckbox.mjs.map +1 -1
- package/dist/private/tabs/TabsKeyboardDelegate.cjs +2 -2
- package/dist/private/tabs/TabsKeyboardDelegate.cjs.map +1 -1
- package/dist/private/tabs/TabsKeyboardDelegate.js +2 -2
- package/dist/private/tabs/TabsKeyboardDelegate.js.map +1 -1
- package/dist/private/tabs/TabsKeyboardDelegate.mjs +2 -2
- package/dist/private/tabs/TabsKeyboardDelegate.mjs.map +1 -1
- package/dist/private/tag/useTag.cjs.map +1 -1
- package/dist/private/tag/useTag.js.map +1 -1
- package/dist/private/tag/useTag.mjs.map +1 -1
- package/dist/private/toast/useToast.cjs.map +1 -1
- package/dist/private/toast/useToast.js.map +1 -1
- package/dist/private/toast/useToast.mjs.map +1 -1
- package/dist/private/toast/useToastRegion.cjs.map +1 -1
- package/dist/private/toast/useToastRegion.js.map +1 -1
- package/dist/private/toast/useToastRegion.mjs.map +1 -1
- package/dist/private/toolbar/useToolbar.cjs +0 -1
- package/dist/private/toolbar/useToolbar.cjs.map +1 -1
- package/dist/private/toolbar/useToolbar.js +0 -1
- package/dist/private/toolbar/useToolbar.js.map +1 -1
- package/dist/private/toolbar/useToolbar.mjs +0 -1
- package/dist/private/toolbar/useToolbar.mjs.map +1 -1
- package/dist/private/tree/useTree.cjs.map +1 -1
- package/dist/private/tree/useTree.js.map +1 -1
- package/dist/private/tree/useTree.mjs.map +1 -1
- package/dist/private/tree/useTreeItem.cjs.map +1 -1
- package/dist/private/tree/useTreeItem.js.map +1 -1
- package/dist/private/tree/useTreeItem.mjs.map +1 -1
- package/dist/private/utils/isElementVisible.cjs +1 -1
- package/dist/private/utils/isElementVisible.cjs.map +1 -1
- package/dist/private/utils/isElementVisible.js +1 -1
- package/dist/private/utils/isElementVisible.js.map +1 -1
- package/dist/private/utils/isElementVisible.mjs +1 -1
- package/dist/private/utils/isElementVisible.mjs.map +1 -1
- package/dist/private/utils/isFocusable.cjs +3 -1
- package/dist/private/utils/isFocusable.cjs.map +1 -1
- package/dist/private/utils/isFocusable.js +3 -1
- package/dist/private/utils/isFocusable.js.map +1 -1
- package/dist/private/utils/isFocusable.mjs +3 -1
- package/dist/private/utils/isFocusable.mjs.map +1 -1
- package/dist/types/src/dnd/utils.d.ts +2 -2
- package/dist/types/src/gridlist/useGridList.d.ts +7 -0
- package/dist/types/src/menu/useMenu.d.ts +1 -1
- package/dist/types/src/menu/utils.d.ts +1 -1
- package/dist/types/src/overlays/calculatePosition.d.ts +1 -0
- package/dist/types/src/overlays/useOverlayPosition.d.ts +8 -0
- package/dist/types/src/selection/ListKeyboardDelegate.d.ts +1 -0
- package/dist/types/src/selection/useSelectableCollection.d.ts +7 -0
- package/dist/types/src/tree/useTree.d.ts +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAcD,MAAM,iCAAW;IACf,UAAU;IACV,OAAO;IACP,SAAS;AACX;AAEO,SAAS;IACd,IAAI,kBAAkB,CAAA,GAAA,yCAA0B,EAAE,CAAA,GAAA,8CAAW,GAAG;IAChE,IAAI,WAAW,CAAA,GAAA,yCAAc;IAC7B,IAAI,cAAc;IAClB,IAAI,mBAAmB,CAAA,GAAA,yCAAa,EAClC,cAAc,gBAAgB,MAAM,CAAC,8BAAQ,CAAC,SAAS,IAAI;IAG7D,OAAO;QACL,WAAW;YACT,GAAG,gBAAgB;YACnB,yFAAyF;YACzF,0FAA0F;YAC1F,0FAA0F;YAC1F,yCAAyC;YACzC,4EAA4E;YAC5E,SAAS,KAAO;QAClB;IACF;AACF","sources":["packages/react-aria/src/dnd/useVirtualDrop.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 {AriaButtonProps} from '../button/useButton';\nimport {DOMAttributes} from 'react';\nimport * as DragManager from './DragManager';\nimport intlMessages from '../../intl/dnd/*.json';\nimport {useDescription} from '../utils/useDescription';\nimport {useDragModality} from './utils';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\n\ninterface VirtualDropResult {\n dropProps: AriaButtonProps & DOMAttributes<HTMLDivElement>;\n}\n\nconst MESSAGES = {\n keyboard: 'dropDescriptionKeyboard',\n touch: 'dropDescriptionTouch',\n virtual: 'dropDescriptionVirtual'\n};\n\nexport function useVirtualDrop(): VirtualDropResult {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let modality = useDragModality();\n let dragSession = DragManager.useDragSession();\n let descriptionProps = useDescription(\n dragSession ? stringFormatter.format(MESSAGES[modality]) : ''\n );\n\n return {\n dropProps: {\n ...descriptionProps,\n // Mobile Safari does not properly bubble click events on elements except links or inputs\n // unless there is an onclick handler bound directly to the element itself. By adding this\n // handler, React will take care of adding that for us, and we are able to handle document\n // level click events in the DragManager.\n // See https://www.quirksmode.org/blog/archives/2010/09/click_event_del.html\n onClick: () => {}\n }\n };\n}\n"],"names":[],"version":3,"file":"useVirtualDrop.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAcD,MAAM,iCAAW;IACf,UAAU;IACV,OAAO;IACP,SAAS;AACX;AAEO,SAAS;IACd,IAAI,kBAAkB,CAAA,GAAA,yCAA0B,EAAE,CAAA,GAAA,+CAAW,GAAG;IAChE,IAAI,WAAW,CAAA,GAAA,yCAAc;IAC7B,IAAI,cAAc;IAClB,IAAI,mBAAmB,CAAA,GAAA,yCAAa,EAClC,cAAc,gBAAgB,MAAM,CAAC,8BAAQ,CAAC,SAAS,IAAI;IAG7D,OAAO;QACL,WAAW;YACT,GAAG,gBAAgB;YACnB,yFAAyF;YACzF,0FAA0F;YAC1F,0FAA0F;YAC1F,yCAAyC;YACzC,4EAA4E;YAC5E,SAAS,KAAO;QAClB;IACF;AACF","sources":["packages/react-aria/src/dnd/useVirtualDrop.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 {AriaButtonProps} from '../button/useButton';\nimport {DOMAttributes} from 'react';\nimport * as DragManager from './DragManager';\nimport intlMessages from '../../intl/dnd/*.json';\nimport {useDescription} from '../utils/useDescription';\nimport {useDragModality} from './utils';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\n\ninterface VirtualDropResult {\n dropProps: AriaButtonProps & DOMAttributes<HTMLDivElement>;\n}\n\nconst MESSAGES = {\n keyboard: 'dropDescriptionKeyboard',\n touch: 'dropDescriptionTouch',\n virtual: 'dropDescriptionVirtual'\n};\n\nexport function useVirtualDrop(): VirtualDropResult {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let modality = useDragModality();\n let dragSession = DragManager.useDragSession();\n let descriptionProps = useDescription(\n dragSession ? stringFormatter.format(MESSAGES[modality]) : ''\n );\n\n return {\n dropProps: {\n ...descriptionProps,\n // Mobile Safari does not properly bubble click events on elements except links or inputs\n // unless there is an onclick handler bound directly to the element itself. By adding this\n // handler, React will take care of adding that for us, and we are able to handle document\n // level click events in the DragManager.\n // See https://www.quirksmode.org/blog/archives/2010/09/click_event_del.html\n onClick: () => {}\n }\n };\n}\n"],"names":[],"version":3,"file":"useVirtualDrop.mjs.map"}
|
|
@@ -62,7 +62,7 @@ function $c67ff3d36836a1c1$export$e1d41611756c6326(items) {
|
|
|
62
62
|
function $c67ff3d36836a1c1$var$mapModality(modality) {
|
|
63
63
|
if (!modality) modality = 'virtual';
|
|
64
64
|
if (modality === 'pointer') modality = 'virtual';
|
|
65
|
-
if (modality === 'virtual' && typeof window !== 'undefined' && '
|
|
65
|
+
if (modality === 'virtual' && typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(pointer: coarse)').matches) modality = 'touch';
|
|
66
66
|
return modality;
|
|
67
67
|
}
|
|
68
68
|
function $c67ff3d36836a1c1$export$49bac5d6d4b352ea() {
|
|
@@ -134,8 +134,18 @@ class $c67ff3d36836a1c1$export$7f04ce188c91447c {
|
|
|
134
134
|
this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');
|
|
135
135
|
}
|
|
136
136
|
has(type) {
|
|
137
|
-
if (
|
|
138
|
-
|
|
137
|
+
if (Array.isArray(type)) return type.some((t)=>this.has(t));
|
|
138
|
+
if (this.includesUnknownTypes || type === $c67ff3d36836a1c1$export$990fced5dfac2637 && this.types.has((0, $47f95f5edd0c867d$exports.GENERIC_TYPE)) || type === '*/*') return true;
|
|
139
|
+
if (typeof type === 'string') {
|
|
140
|
+
if (type.endsWith('/*')) {
|
|
141
|
+
for (let key of this.types){
|
|
142
|
+
if (key.startsWith(type.slice(0, -2))) return true;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return this.types.has(type);
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
139
149
|
}
|
|
140
150
|
}
|
|
141
151
|
function $c67ff3d36836a1c1$export$d9e760437831f8b3(dataTransfer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM,4CACX,IAAI;AACC,MAAM,4CAA8B;AAEpC,SAAS,0CAAyB,KAA+B;IACtE,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CACd,KAA+B;IAE/B,IAAI,OAAC,GAAG,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IAClD,IAAI,CAAC,KACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAAS,KAAiB;IACxC,IAAI,QAAQ,IAAI;IAChB,KAAK,IAAI,QAAQ,MACf,KAAK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AK;AAC3B;AAGO,SAAS,yCAAe,QAAkB;IAC/C,OAAO,SAAS,IAAI,KAAK;AAC3B;AAGO,SAAS,0CAAoB,QAAkB;IACpD,OAAO,SAAS,IAAI,KAAK;AAC3B;AAYO,IAAI,4CAA2B;IAAC,cAAc,IAAI;AAAK;AAEvD,SAAS,0CAAyB,GAAkC;IACzE,0CAAe,qBAAqB,GAAG;AACzC;AAEO,SAAS,0CAAgB,IAAc;IAC5C,0CAAe,YAAY,GAAG;AAChC;AAEO,SAAS,0CAAqB,GAAmC;IACtE,0CAAe,iBAAiB,GAAG;AACrC;AAEO,SAAS;IACd,4CAAiB;QAAC,cAAc,IAAI;IAAK;AAC3C;AAEO,SAAS,0CAAkB,KAAe;IAC/C,4CAAiB;AACnB;AAIO,SAAS,0CAAwB,GAAmC;IACzE,IAAI,yBAAC,qBAAqB,qBAAE,iBAAiB,EAAC,GAAG;IACjD,OACE,uBAAuB,WAAW,QAClC,sBAAsB,OAAO,KAAM,CAAA,KAAK,WAAW,mBAAmB,OAAM;AAEhF;AAGO,IAAI;AACJ,SAAS,0CAAoB,UAAkC;IACpE,4CAAmB;AACrB;AAEO,IAAI,4CAA8C,CAAA,GAAA,wCAAa,EAAE,IAAI;AACrE,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/react-aria/src/dnd/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {\n DirectoryDropItem,\n DragItem,\n DropItem,\n FileDropItem,\n DragTypes as IDragTypes,\n Key,\n RefObject,\n TextDropItem\n} from '@react-types/shared';\nimport {DroppableCollectionState} from 'react-stately/useDroppableCollectionState';\nimport {getInteractionModality, useInteractionModality} from '../interactions/useFocusVisible';\n\ninterface DroppableCollectionMap {\n id: string;\n ref: RefObject<HTMLElement | null>;\n}\n\nexport const droppableCollectionMap: WeakMap<DroppableCollectionState, DroppableCollectionMap> =\n new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE: symbol = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(\n state: DroppableCollectionState\n): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (modality === 'virtual' && typeof window !== 'undefined' && 'ontouchstart' in window) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: string | symbol): boolean {\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE))\n ) {\n return true;\n }\n\n return typeof type === 'string' && this.types.has(type);\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: type => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: type => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader();\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function* getEntries(\n item: FileSystemDirectoryEntry\n): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>;\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>;\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>;\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return (\n draggingCollectionRef?.current != null &&\n draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current)\n );\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations: DROP_OPERATION = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.cjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAsBM,MAAM,4CACX,IAAI;AACC,MAAM,4CAA8B;AAEpC,SAAS,0CAAyB,KAA+B;IACtE,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CACd,KAA+B;IAE/B,IAAI,OAAC,GAAG,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IAClD,IAAI,CAAC,KACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAAS,KAAiB;IACxC,IAAI,QAAQ,IAAI;IAChB,KAAK,IAAI,QAAQ,MACf,KAAK,IAAI,QAAQ,OAAO,IAAI,CAAC,MAC3B,MAAM,GAAG,CAAC;IAId,OAAO;AACT;AAEA,SAAS,kCAAY,QAAuB;IAC1C,IAAI,CAAC,UACH,WAAW;IAGb,IAAI,aAAa,WACf,WAAW;IAGb,IACE,aAAa,aACb,OAAO,WAAW,eAClB,OAAO,OAAO,UAAU,KAAK,cAC7B,OAAO,UAAU,CAAC,qBAAqB,OAAO,EAE9C,WAAW;IAGb,OAAO;AACT;AAEO,SAAS;IACd,OAAO,kCAAY,CAAA,GAAA,gDAAqB;AAC1C;AAEO,SAAS;IACd,OAAO,kCAAY,CAAA,GAAA,gDAAqB;AAC1C;AAEO,SAAS,0CAAoB,YAA0B,EAAE,KAAiB;IAC/E,oFAAoF;IACpF,mGAAmG;IACnG,0FAA0F;IAC1F,wFAAwF;IACxF,wFAAwF;IACxF,yFAAyF;IACzF,qBAAqB;IACrB,EAAE;IACF,4FAA4F;IAC5F,8F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zE,0CAAe,qBAAqB,GAAG;AACzC;AAEO,SAAS,0CAAgB,IAAc;IAC5C,0CAAe,YAAY,GAAG;AAChC;AAEO,SAAS,0CAAqB,GAAmC;IACtE,0CAAe,iBAAiB,GAAG;AACrC;AAEO,SAAS;IACd,4CAAiB;QAAC,cAAc,IAAI;IAAK;AAC3C;AAEO,SAAS,0CAAkB,KAAe;IAC/C,4CAAiB;AACnB;AAIO,SAAS,0CAAwB,GAAmC;IACzE,IAAI,yBAAC,qBAAqB,qBAAE,iBAAiB,EAAC,GAAG;IACjD,OACE,uBAAuB,WAAW,QAClC,sBAAsB,OAAO,KAAM,CAAA,KAAK,WAAW,mBAAmB,OAAM;AAEhF;AAGO,IAAI;AACJ,SAAS,0CAAoB,UAAkC;IACpE,4CAAmB;AACrB;AAEO,IAAI,4CAA8C,CAAA,GAAA,wCAAa,EAAE,IAAI;AACrE,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/react-aria/src/dnd/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {\n DirectoryDropItem,\n DragItem,\n DragType,\n DropItem,\n FileDropItem,\n DragTypes as IDragTypes,\n Key,\n RefObject,\n TextDropItem\n} from '@react-types/shared';\nimport {DroppableCollectionState} from 'react-stately/useDroppableCollectionState';\nimport {getInteractionModality, useInteractionModality} from '../interactions/useFocusVisible';\n\ninterface DroppableCollectionMap {\n id: string;\n ref: RefObject<HTMLElement | null>;\n}\n\nexport const droppableCollectionMap: WeakMap<DroppableCollectionState, DroppableCollectionMap> =\n new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE: symbol = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(\n state: DroppableCollectionState\n): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (\n modality === 'virtual' &&\n typeof window !== 'undefined' &&\n typeof window.matchMedia === 'function' &&\n window.matchMedia('(pointer: coarse)').matches\n ) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: DragType | DragType[]): boolean {\n if (Array.isArray(type)) {\n return type.some(t => this.has(t));\n }\n\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE)) ||\n type === '*/*'\n ) {\n return true;\n }\n\n if (typeof type === 'string') {\n if (type.endsWith('/*')) {\n for (let key of this.types) {\n if (key.startsWith(type.slice(0, -2))) {\n return true;\n }\n }\n return false;\n }\n return this.types.has(type);\n }\n\n return false;\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: type => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: type => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader();\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function* getEntries(\n item: FileSystemDirectoryEntry\n): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>;\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>;\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>;\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return (\n draggingCollectionRef?.current != null &&\n draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current)\n );\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations: DROP_OPERATION = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.cjs.map"}
|
|
@@ -33,7 +33,7 @@ function $a279fa400589a731$export$e1d41611756c6326(items) {
|
|
|
33
33
|
function $a279fa400589a731$var$mapModality(modality) {
|
|
34
34
|
if (!modality) modality = 'virtual';
|
|
35
35
|
if (modality === 'pointer') modality = 'virtual';
|
|
36
|
-
if (modality === 'virtual' && typeof window !== 'undefined' && '
|
|
36
|
+
if (modality === 'virtual' && typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(pointer: coarse)').matches) modality = 'touch';
|
|
37
37
|
return modality;
|
|
38
38
|
}
|
|
39
39
|
function $a279fa400589a731$export$49bac5d6d4b352ea() {
|
|
@@ -88,8 +88,18 @@ function $a279fa400589a731$export$f9c1490890ddd063(dataTransfer, items) {
|
|
|
88
88
|
}
|
|
89
89
|
class $a279fa400589a731$export$7f04ce188c91447c {
|
|
90
90
|
has(type) {
|
|
91
|
-
if (
|
|
92
|
-
|
|
91
|
+
if (Array.isArray(type)) return type.some((t)=>this.has(t));
|
|
92
|
+
if (this.includesUnknownTypes || type === $a279fa400589a731$export$990fced5dfac2637 && this.types.has((0, $a5876944c9299b39$export$f8fc6581787339b3)) || type === '*/*') return true;
|
|
93
|
+
if (typeof type === 'string') {
|
|
94
|
+
if (type.endsWith('/*')) {
|
|
95
|
+
for (let key of this.types){
|
|
96
|
+
if (key.startsWith(type.slice(0, -2))) return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return this.types.has(type);
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
93
103
|
}
|
|
94
104
|
constructor(dataTransfer){
|
|
95
105
|
this.types = new Set();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM,4CACX,IAAI;AACC,MAAM,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E,IAAI;AACrE,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/react-aria/src/dnd/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {\n DirectoryDropItem,\n DragItem,\n DropItem,\n FileDropItem,\n DragTypes as IDragTypes,\n Key,\n RefObject,\n TextDropItem\n} from '@react-types/shared';\nimport {DroppableCollectionState} from 'react-stately/useDroppableCollectionState';\nimport {getInteractionModality, useInteractionModality} from '../interactions/useFocusVisible';\n\ninterface DroppableCollectionMap {\n id: string;\n ref: RefObject<HTMLElement | null>;\n}\n\nexport const droppableCollectionMap: WeakMap<DroppableCollectionState, DroppableCollectionMap> =\n new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE: symbol = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(\n state: DroppableCollectionState\n): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (modality === 'virtual' && typeof window !== 'undefined' && 'ontouchstart' in window) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: string | symbol): boolean {\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE))\n ) {\n return true;\n }\n\n return typeof type === 'string' && this.types.has(type);\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: type => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: type => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader();\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function* getEntries(\n item: FileSystemDirectoryEntry\n): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>;\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>;\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>;\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return (\n draggingCollectionRef?.current != null &&\n draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current)\n );\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations: DROP_OPERATION = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.js.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAsBM,MAAM,4CACX,IAAI;AACC,MAAM,4CAA8B;AAEpC,SAAS,0CAAyB,KAA+B;IACtE,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CACd,KAA+B;IAE/B,IAAI,OAAC,GAAG,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IAClD,IAAI,CAAC,KACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAAS,KAAiB;IACxC,IAAI,QAAQ,IAAI;IAChB,KAAK,IAAI,QAAQ,MACf,KAAK,IAAI,QAAQ,OAAO,IAAI,CAAC,MAC3B,MAAM,GAAG,CAAC;IAId,OAAO;AACT;AAEA,SAAS,kCAAY,QAAuB;IAC1C,IAAI,CAAC,UACH,WAAW;IAGb,IAAI,a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AW,EAC1B,MAAM,0CAAoB;QAE9B;IACF,QAAS,QAAQ,MAAM,GAAG,GAAG;AAC/B;AAEA,SAAS,mCAAa,KAA0B;IAC9C,OAAO,IAAI,QAAQ,CAAC,SAAS,SAAW,MAAM,IAAI,CAAC,SAAS;AAC9D;AAGO,SAAS,0CAAe,QAAkB;IAC/C,OAAO,SAAS,IAAI,KAAK;AAC3B;AAGO,SAAS,yCAAe,QAAkB;IAC/C,OAAO,SAAS,IAAI,KAAK;AAC3B;AAGO,SAAS,0CAAoB,QAAkB;IACpD,OAAO,SAAS,IAAI,KAAK;AAC3B;AAYO,IAAI,4CAA2B;IAAC,cAAc,IAAI;AAAK;AAEvD,SAAS,0CAAyB,GAAkC;IACzE,0CAAe,qBAAqB,GAAG;AACzC;AAEO,SAAS,0CAAgB,IAAc;IAC5C,0CAAe,YAAY,GAAG;AAChC;AAEO,SAAS,0CAAqB,GAAmC;IACtE,0CAAe,iBAAiB,GAAG;AACrC;AAEO,SAAS;IACd,4CAAiB;QAAC,cAAc,IAAI;IAAK;AAC3C;AAEO,SAAS,0CAAkB,KAAe;IAC/C,4CAAiB;AACnB;AAIO,SAAS,0CAAwB,GAAmC;IACzE,IAAI,yBAAC,qBAAqB,qBAAE,iBAAiB,EAAC,GAAG;IACjD,OACE,CAAA,kCAAA,4CAAA,sBAAuB,OAAO,KAAI,QAClC,sBAAsB,OAAO,KAAM,CAAA,CAAA,gBAAA,0BAAA,IAAK,OAAO,MAAI,8BAAA,wCAAA,kBAAmB,OAAO,CAAD;AAEhF;AAGO,IAAI;AACJ,SAAS,0CAAoB,UAAkC;IACpE,4CAAmB;AACrB;AAEO,IAAI,4CAA8C,CAAA,GAAA,yCAAa,EAAE,IAAI;AACrE,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/react-aria/src/dnd/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {\n DirectoryDropItem,\n DragItem,\n DragType,\n DropItem,\n FileDropItem,\n DragTypes as IDragTypes,\n Key,\n RefObject,\n TextDropItem\n} from '@react-types/shared';\nimport {DroppableCollectionState} from 'react-stately/useDroppableCollectionState';\nimport {getInteractionModality, useInteractionModality} from '../interactions/useFocusVisible';\n\ninterface DroppableCollectionMap {\n id: string;\n ref: RefObject<HTMLElement | null>;\n}\n\nexport const droppableCollectionMap: WeakMap<DroppableCollectionState, DroppableCollectionMap> =\n new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE: symbol = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(\n state: DroppableCollectionState\n): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (\n modality === 'virtual' &&\n typeof window !== 'undefined' &&\n typeof window.matchMedia === 'function' &&\n window.matchMedia('(pointer: coarse)').matches\n ) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: DragType | DragType[]): boolean {\n if (Array.isArray(type)) {\n return type.some(t => this.has(t));\n }\n\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE)) ||\n type === '*/*'\n ) {\n return true;\n }\n\n if (typeof type === 'string') {\n if (type.endsWith('/*')) {\n for (let key of this.types) {\n if (key.startsWith(type.slice(0, -2))) {\n return true;\n }\n }\n return false;\n }\n return this.types.has(type);\n }\n\n return false;\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: type => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: type => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader();\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function* getEntries(\n item: FileSystemDirectoryEntry\n): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>;\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>;\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>;\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return (\n draggingCollectionRef?.current != null &&\n draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current)\n );\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations: DROP_OPERATION = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.js.map"}
|
|
@@ -33,7 +33,7 @@ function $d40e85a29b831dd6$export$e1d41611756c6326(items) {
|
|
|
33
33
|
function $d40e85a29b831dd6$var$mapModality(modality) {
|
|
34
34
|
if (!modality) modality = 'virtual';
|
|
35
35
|
if (modality === 'pointer') modality = 'virtual';
|
|
36
|
-
if (modality === 'virtual' && typeof window !== 'undefined' && '
|
|
36
|
+
if (modality === 'virtual' && typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(pointer: coarse)').matches) modality = 'touch';
|
|
37
37
|
return modality;
|
|
38
38
|
}
|
|
39
39
|
function $d40e85a29b831dd6$export$49bac5d6d4b352ea() {
|
|
@@ -105,8 +105,18 @@ class $d40e85a29b831dd6$export$7f04ce188c91447c {
|
|
|
105
105
|
this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');
|
|
106
106
|
}
|
|
107
107
|
has(type) {
|
|
108
|
-
if (
|
|
109
|
-
|
|
108
|
+
if (Array.isArray(type)) return type.some((t)=>this.has(t));
|
|
109
|
+
if (this.includesUnknownTypes || type === $d40e85a29b831dd6$export$990fced5dfac2637 && this.types.has((0, $2991e2e71ca29774$export$f8fc6581787339b3)) || type === '*/*') return true;
|
|
110
|
+
if (typeof type === 'string') {
|
|
111
|
+
if (type.endsWith('/*')) {
|
|
112
|
+
for (let key of this.types){
|
|
113
|
+
if (key.startsWith(type.slice(0, -2))) return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return this.types.has(type);
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
function $d40e85a29b831dd6$export$d9e760437831f8b3(dataTransfer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM,4CACX,IAAI;AACC,MAAM,4CAA8B;AAEpC,SAAS,0CAAyB,KAA+B;IACtE,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CACd,KAA+B;IAE/B,IAAI,OAAC,GAAG,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IAClD,IAAI,CAAC,KACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAAS,KAAiB;IACxC,IAAI,QAAQ,IAAI;IAChB,KAAK,IAAI,QAAQ,MACf,KAAK,IAAI,QAAQ,OAAO,IAAI,CAAC,MAC3B,MAAM,GAAG,CAAC;IAId,OAAO;AACT;AAEA,SAAS,kCAAY,QAAuB;IAC1C,IAAI,CAAC,UACH,WAAW;IAGb,IAAI,aAAa,WACf,WAAW;IAGb,IAAI,aAAa,aAAa,OAAO,WAAW,eAAe,kBAAkB,QAC/E,WAAW;IAGb,OAAO;AACT;AAEO,SAAS;IACd,OAAO,kCAA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,IAAc;IAC5C,0CAAe,YAAY,GAAG;AAChC;AAEO,SAAS,0CAAqB,GAAmC;IACtE,0CAAe,iBAAiB,GAAG;AACrC;AAEO,SAAS;IACd,4CAAiB;QAAC,cAAc,IAAI;IAAK;AAC3C;AAEO,SAAS,0CAAkB,KAAe;IAC/C,4CAAiB;AACnB;AAIO,SAAS,0CAAwB,GAAmC;IACzE,IAAI,yBAAC,qBAAqB,qBAAE,iBAAiB,EAAC,GAAG;IACjD,OACE,uBAAuB,WAAW,QAClC,sBAAsB,OAAO,KAAM,CAAA,KAAK,WAAW,mBAAmB,OAAM;AAEhF;AAGO,IAAI;AACJ,SAAS,0CAAoB,UAAkC;IACpE,4CAAmB;AACrB;AAEO,IAAI,4CAA8C,CAAA,GAAA,yCAAa,EAAE,IAAI;AACrE,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/react-aria/src/dnd/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {\n DirectoryDropItem,\n DragItem,\n DropItem,\n FileDropItem,\n DragTypes as IDragTypes,\n Key,\n RefObject,\n TextDropItem\n} from '@react-types/shared';\nimport {DroppableCollectionState} from 'react-stately/useDroppableCollectionState';\nimport {getInteractionModality, useInteractionModality} from '../interactions/useFocusVisible';\n\ninterface DroppableCollectionMap {\n id: string;\n ref: RefObject<HTMLElement | null>;\n}\n\nexport const droppableCollectionMap: WeakMap<DroppableCollectionState, DroppableCollectionMap> =\n new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE: symbol = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(\n state: DroppableCollectionState\n): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (modality === 'virtual' && typeof window !== 'undefined' && 'ontouchstart' in window) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: string | symbol): boolean {\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE))\n ) {\n return true;\n }\n\n return typeof type === 'string' && this.types.has(type);\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: type => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: type => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader();\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function* getEntries(\n item: FileSystemDirectoryEntry\n): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>;\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>;\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>;\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return (\n draggingCollectionRef?.current != null &&\n draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current)\n );\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations: DROP_OPERATION = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.mjs.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAsBM,MAAM,4CACX,IAAI;AACC,MAAM,4CAA8B;AAEpC,SAAS,0CAAyB,KAA+B;IACtE,IAAI,MAAC,EAAE,E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,qBAAqB,qBAAE,iBAAiB,EAAC,GAAG;IACjD,OACE,uBAAuB,WAAW,QAClC,sBAAsB,OAAO,KAAM,CAAA,KAAK,WAAW,mBAAmB,OAAM;AAEhF;AAGO,IAAI;AACJ,SAAS,0CAAoB,UAAkC;IACpE,4CAAmB;AACrB;AAEO,IAAI,4CAA8C,CAAA,GAAA,yCAAa,EAAE,IAAI;AACrE,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/react-aria/src/dnd/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {\n DirectoryDropItem,\n DragItem,\n DragType,\n DropItem,\n FileDropItem,\n DragTypes as IDragTypes,\n Key,\n RefObject,\n TextDropItem\n} from '@react-types/shared';\nimport {DroppableCollectionState} from 'react-stately/useDroppableCollectionState';\nimport {getInteractionModality, useInteractionModality} from '../interactions/useFocusVisible';\n\ninterface DroppableCollectionMap {\n id: string;\n ref: RefObject<HTMLElement | null>;\n}\n\nexport const droppableCollectionMap: WeakMap<DroppableCollectionState, DroppableCollectionMap> =\n new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE: symbol = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(\n state: DroppableCollectionState\n): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (\n modality === 'virtual' &&\n typeof window !== 'undefined' &&\n typeof window.matchMedia === 'function' &&\n window.matchMedia('(pointer: coarse)').matches\n ) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: DragType | DragType[]): boolean {\n if (Array.isArray(type)) {\n return type.some(t => this.has(t));\n }\n\n if (\n this.includesUnknownTypes ||\n (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE)) ||\n type === '*/*'\n ) {\n return true;\n }\n\n if (typeof type === 'string') {\n if (type.endsWith('/*')) {\n for (let key of this.types) {\n if (key.startsWith(type.slice(0, -2))) {\n return true;\n }\n }\n return false;\n }\n return this.types.has(type);\n }\n\n return false;\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: type => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: type => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader();\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function* getEntries(\n item: FileSystemDirectoryEntry\n): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>;\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>;\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>;\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return (\n draggingCollectionRef?.current != null &&\n draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current)\n );\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations: DROP_OPERATION = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.mjs.map"}
|
|
@@ -29,7 +29,7 @@ function $2dfbb9cb434f8768$export$b8473d3665f3a75a(props, state, ref) {
|
|
|
29
29
|
let { validationBehavior: validationBehavior, focus: focus } = props;
|
|
30
30
|
// This is a useLayoutEffect so that it runs before the useEffect in useFormValidationState, which commits the validation change.
|
|
31
31
|
(0, $429333cab433657c$exports.useLayoutEffect)(()=>{
|
|
32
|
-
if (validationBehavior === 'native' && ref?.current && !ref.current.disabled) {
|
|
32
|
+
if (validationBehavior === 'native' && ref?.current && 'setCustomValidity' in ref.current && !ref.current.disabled) {
|
|
33
33
|
let errorMessage = state.realtimeValidation.isInvalid ? state.realtimeValidation.validationErrors.join(' ') || 'Invalid value.' : '';
|
|
34
34
|
ref.current.setCustomValidity(errorMessage);
|
|
35
35
|
// Prevent default tooltip for validation message.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAiBM,SAAS,0CACd,KAA6B,EAC7B,KAA0B,EAC1B,GAAqD;IAErD,IAAI,sBAAC,kBAAkB,SAAE,KAAK,EAAC,GAAG;IAElC,iIAAiI;IACjI,CAAA,GAAA,yCAAc,EAAE;QACd,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAiBM,SAAS,0CACd,KAA6B,EAC7B,KAA0B,EAC1B,GAAqD;IAErD,IAAI,sBAAC,kBAAkB,SAAE,KAAK,EAAC,GAAG;IAElC,iIAAiI;IACjI,CAAA,GAAA,yCAAc,EAAE;QACd,IACE,uBAAuB,YACvB,KAAK,WACL,uBAAuB,IAAI,OAAO,IAClC,CAAC,IAAI,OAAO,CAAC,QAAQ,EACrB;YACA,IAAI,eAAe,MAAM,kBAAkB,CAAC,SAAS,GACjD,MAAM,kBAAkB,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,mBACvD;YACJ,IAAI,OAAO,CAAC,iBAAiB,CAAC;YAE9B,kDAAkD;YAClD,sDAAsD;YACtD,IAAI,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,UAC5B,IAAI,OAAO,CAAC,KAAK,GAAG;YAGtB,IAAI,CAAC,MAAM,kBAAkB,CAAC,SAAS,EACrC,MAAM,gBAAgB,CAAC,wCAAkB,IAAI,OAAO;QAExD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oBAAoB,SAAS;YACnC,IAAI,MACF,aAAa;YACb,KAAK,KAAK,GAAG;QAEjB;IACF,GAAG;QAAC;QAAK;KAAmB;AAC9B;AAEA,SAAS,kCAAY,KAAyB;IAC5C,6GAA6G;IAC7G,+HAA+H;IAC/H,IAAI,WAAW,MAAM,QAAQ;IAC7B,OAAO;QACL,UAAU,SAAS,QAAQ;QAC3B,aAAa,SAAS,WAAW;QACjC,iBAAiB,SAAS,eAAe;QACzC,eAAe,SAAS,aAAa;QACrC,gBAAgB,SAAS,cAAc;QACvC,cAAc,SAAS,YAAY;QACnC,SAAS,SAAS,OAAO;QACzB,UAAU,SAAS,QAAQ;QAC3B,cAAc,SAAS,YAAY;QACnC,cAAc,SAAS,YAAY;QACnC,OAAO,SAAS,KAAK;IACvB;AACF;AAEA,SAAS,wCAAkB,KAAyB;IAClD,OAAO;QACL,WAAW,CAAC,MAAM,QAAQ,CAAC,KAAK;QAChC,mBAAmB,kCAAY;QAC/B,kBAAkB,MAAM,iBAAiB,GAAG;YAAC,MAAM,iBAAiB;SAAC,GAAG,EAAE;IAC5E;AACF;AAEA,SAAS,2CAAqB,IAAqB;IACjD,IAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,CAAC,MAAM,EAAE,IAAK;QAC7C,IAAI,UAAU,KAAK,QAAQ,CAAC,EAAE;QAC9B,IAAI,QAAQ,QAAQ,EAAE,UAAU,OAC9B,OAAO;IAEX;IAEA,OAAO;AACT","sources":["packages/react-aria/src/form/useFormValidation.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {FormValidationState} from 'react-stately/private/form/useFormValidationState';\n\nimport {getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport {RefObject, Validation, ValidationResult} from '@react-types/shared';\nimport {setInteractionModality} from '../interactions/useFocusVisible';\nimport {useEffect, useRef} from 'react';\nimport {useEffectEvent} from '../utils/useEffectEvent';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\n\ntype ValidatableElement = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;\n\ninterface FormValidationProps<T> extends Validation<T> {\n focus?: () => void;\n}\n\nexport function useFormValidation<T>(\n props: FormValidationProps<T>,\n state: FormValidationState,\n ref: RefObject<ValidatableElement | null> | undefined\n): void {\n let {validationBehavior, focus} = props;\n\n // This is a useLayoutEffect so that it runs before the useEffect in useFormValidationState, which commits the validation change.\n useLayoutEffect(() => {\n if (\n validationBehavior === 'native' &&\n ref?.current &&\n 'setCustomValidity' in ref.current &&\n !ref.current.disabled\n ) {\n let errorMessage = state.realtimeValidation.isInvalid\n ? state.realtimeValidation.validationErrors.join(' ') || 'Invalid value.'\n : '';\n ref.current.setCustomValidity(errorMessage);\n\n // Prevent default tooltip for validation message.\n // https://bugzilla.mozilla.org/show_bug.cgi?id=605277\n if (!ref.current.hasAttribute('title')) {\n ref.current.title = '';\n }\n\n if (!state.realtimeValidation.isInvalid) {\n state.updateValidation(getNativeValidity(ref.current));\n }\n }\n });\n\n let isIgnoredReset = useRef(false);\n let onReset = useEffectEvent(() => {\n if (!isIgnoredReset.current) {\n state.resetValidation();\n }\n });\n\n let onInvalid = useEffectEvent((e: Event) => {\n // Only commit validation if we are not already displaying one.\n // This avoids clearing server errors that the user didn't actually fix.\n if (!state.displayValidation.isInvalid) {\n state.commitValidation();\n }\n\n // Auto focus the first invalid input in a form, unless the error already had its default prevented.\n let form = ref?.current?.form;\n if (!e.defaultPrevented && ref && form && getFirstInvalidInput(form) === ref.current) {\n if (focus) {\n focus();\n } else {\n ref.current?.focus();\n }\n\n // Always show focus ring.\n setInteractionModality('keyboard');\n }\n\n // Prevent default browser error UI from appearing.\n e.preventDefault();\n });\n\n let onChange = useEffectEvent(() => {\n state.commitValidation();\n });\n\n useEffect(() => {\n let input = ref?.current;\n if (!input) {\n return;\n }\n\n let form = input.form;\n\n let reset = form?.reset;\n if (form) {\n // Try to detect React's automatic form reset behavior so we don't clear\n // validation errors that are returned by server actions.\n // To do this, we ignore programmatic form resets that occur outside a user event.\n // This is best-effort. There may be false positives, e.g. setTimeout.\n form.reset = () => {\n // React uses MessageChannel for scheduling, so ignore 'message' events.\n isIgnoredReset.current =\n !window.event ||\n (window.event.type === 'message' && getEventTarget(window.event) instanceof MessagePort);\n reset?.call(form);\n isIgnoredReset.current = false;\n };\n }\n\n input.addEventListener('invalid', onInvalid);\n input.addEventListener('change', onChange);\n form?.addEventListener('reset', onReset);\n return () => {\n input!.removeEventListener('invalid', onInvalid);\n input!.removeEventListener('change', onChange);\n form?.removeEventListener('reset', onReset);\n if (form) {\n // @ts-ignore\n form.reset = reset;\n }\n };\n }, [ref, validationBehavior]);\n}\n\nfunction getValidity(input: ValidatableElement) {\n // The native ValidityState object is live, meaning each property is a getter that returns the current state.\n // We need to create a snapshot of the validity state at the time this function is called to avoid unpredictable React renders.\n let validity = input.validity;\n return {\n badInput: validity.badInput,\n customError: validity.customError,\n patternMismatch: validity.patternMismatch,\n rangeOverflow: validity.rangeOverflow,\n rangeUnderflow: validity.rangeUnderflow,\n stepMismatch: validity.stepMismatch,\n tooLong: validity.tooLong,\n tooShort: validity.tooShort,\n typeMismatch: validity.typeMismatch,\n valueMissing: validity.valueMissing,\n valid: validity.valid\n };\n}\n\nfunction getNativeValidity(input: ValidatableElement): ValidationResult {\n return {\n isInvalid: !input.validity.valid,\n validationDetails: getValidity(input),\n validationErrors: input.validationMessage ? [input.validationMessage] : []\n };\n}\n\nfunction getFirstInvalidInput(form: HTMLFormElement): ValidatableElement | null {\n for (let i = 0; i < form.elements.length; i++) {\n let element = form.elements[i] as ValidatableElement;\n if (element.validity?.valid === false) {\n return element;\n }\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"useFormValidation.cjs.map"}
|
|
@@ -23,7 +23,7 @@ function $3bea40a930a50ce5$export$b8473d3665f3a75a(props, state, ref) {
|
|
|
23
23
|
let { validationBehavior: validationBehavior, focus: focus } = props;
|
|
24
24
|
// This is a useLayoutEffect so that it runs before the useEffect in useFormValidationState, which commits the validation change.
|
|
25
25
|
(0, $53fed047b798be36$export$e5c5a5f917a5871c)(()=>{
|
|
26
|
-
if (validationBehavior === 'native' && (ref === null || ref === void 0 ? void 0 : ref.current) && !ref.current.disabled) {
|
|
26
|
+
if (validationBehavior === 'native' && (ref === null || ref === void 0 ? void 0 : ref.current) && 'setCustomValidity' in ref.current && !ref.current.disabled) {
|
|
27
27
|
let errorMessage = state.realtimeValidation.isInvalid ? state.realtimeValidation.validationErrors.join(' ') || 'Invalid value.' : '';
|
|
28
28
|
ref.current.setCustomValidity(errorMessage);
|
|
29
29
|
// Prevent default tooltip for validation message.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAiBM,SAAS,0CACd,KAA6B,EAC7B,KAA0B,EAC1B,GAAqD;IAErD,IAAI,sBAAC,kBAAkB,SAAE,KAAK,EAAC,GAAG;IAElC,iIAAiI;IACjI,CAAA,GAAA,yCAAc,EAAE;QACd,
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAiBM,SAAS,0CACd,KAA6B,EAC7B,KAA0B,EAC1B,GAAqD;IAErD,IAAI,sBAAC,kBAAkB,SAAE,KAAK,EAAC,GAAG;IAElC,iIAAiI;IACjI,CAAA,GAAA,yCAAc,EAAE;QACd,IACE,uBAAuB,aACvB,gBAAA,0BAAA,IAAK,OAAO,KACZ,uBAAuB,IAAI,OAAO,IAClC,CAAC,IAAI,OAAO,CAAC,QAAQ,EACrB;YACA,IAAI,eAAe,MAAM,kBAAkB,CAAC,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IAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,CAAC,MAAM,EAAE,IAAK;YAEzC;QADJ,IAAI,UAAU,KAAK,QAAQ,CAAC,EAAE;QAC9B,IAAI,EAAA,oBAAA,QAAQ,QAAQ,cAAhB,wCAAA,kBAAkB,KAAK,MAAK,OAC9B,OAAO;IAEX;IAEA,OAAO;AACT","sources":["packages/react-aria/src/form/useFormValidation.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {FormValidationState} from 'react-stately/private/form/useFormValidationState';\n\nimport {getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport {RefObject, Validation, ValidationResult} from '@react-types/shared';\nimport {setInteractionModality} from '../interactions/useFocusVisible';\nimport {useEffect, useRef} from 'react';\nimport {useEffectEvent} from '../utils/useEffectEvent';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\n\ntype ValidatableElement = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;\n\ninterface FormValidationProps<T> extends Validation<T> {\n focus?: () => void;\n}\n\nexport function useFormValidation<T>(\n props: FormValidationProps<T>,\n state: FormValidationState,\n ref: RefObject<ValidatableElement | null> | undefined\n): void {\n let {validationBehavior, focus} = props;\n\n // This is a useLayoutEffect so that it runs before the useEffect in useFormValidationState, which commits the validation change.\n useLayoutEffect(() => {\n if (\n validationBehavior === 'native' &&\n ref?.current &&\n 'setCustomValidity' in ref.current &&\n !ref.current.disabled\n ) {\n let errorMessage = state.realtimeValidation.isInvalid\n ? state.realtimeValidation.validationErrors.join(' ') || 'Invalid value.'\n : '';\n ref.current.setCustomValidity(errorMessage);\n\n // Prevent default tooltip for validation message.\n // https://bugzilla.mozilla.org/show_bug.cgi?id=605277\n if (!ref.current.hasAttribute('title')) {\n ref.current.title = '';\n }\n\n if (!state.realtimeValidation.isInvalid) {\n state.updateValidation(getNativeValidity(ref.current));\n }\n }\n });\n\n let isIgnoredReset = useRef(false);\n let onReset = useEffectEvent(() => {\n if (!isIgnoredReset.current) {\n state.resetValidation();\n }\n });\n\n let onInvalid = useEffectEvent((e: Event) => {\n // Only commit validation if we are not already displaying one.\n // This avoids clearing server errors that the user didn't actually fix.\n if (!state.displayValidation.isInvalid) {\n state.commitValidation();\n }\n\n // Auto focus the first invalid input in a form, unless the error already had its default prevented.\n let form = ref?.current?.form;\n if (!e.defaultPrevented && ref && form && getFirstInvalidInput(form) === ref.current) {\n if (focus) {\n focus();\n } else {\n ref.current?.focus();\n }\n\n // Always show focus ring.\n setInteractionModality('keyboard');\n }\n\n // Prevent default browser error UI from appearing.\n e.preventDefault();\n });\n\n let onChange = useEffectEvent(() => {\n state.commitValidation();\n });\n\n useEffect(() => {\n let input = ref?.current;\n if (!input) {\n return;\n }\n\n let form = input.form;\n\n let reset = form?.reset;\n if (form) {\n // Try to detect React's automatic form reset behavior so we don't clear\n // validation errors that are returned by server actions.\n // To do this, we ignore programmatic form resets that occur outside a user event.\n // This is best-effort. There may be false positives, e.g. setTimeout.\n form.reset = () => {\n // React uses MessageChannel for scheduling, so ignore 'message' events.\n isIgnoredReset.current =\n !window.event ||\n (window.event.type === 'message' && getEventTarget(window.event) instanceof MessagePort);\n reset?.call(form);\n isIgnoredReset.current = false;\n };\n }\n\n input.addEventListener('invalid', onInvalid);\n input.addEventListener('change', onChange);\n form?.addEventListener('reset', onReset);\n return () => {\n input!.removeEventListener('invalid', onInvalid);\n input!.removeEventListener('change', onChange);\n form?.removeEventListener('reset', onReset);\n if (form) {\n // @ts-ignore\n form.reset = reset;\n }\n };\n }, [ref, validationBehavior]);\n}\n\nfunction getValidity(input: ValidatableElement) {\n // The native ValidityState object is live, meaning each property is a getter that returns the current state.\n // We need to create a snapshot of the validity state at the time this function is called to avoid unpredictable React renders.\n let validity = input.validity;\n return {\n badInput: validity.badInput,\n customError: validity.customError,\n patternMismatch: validity.patternMismatch,\n rangeOverflow: validity.rangeOverflow,\n rangeUnderflow: validity.rangeUnderflow,\n stepMismatch: validity.stepMismatch,\n tooLong: validity.tooLong,\n tooShort: validity.tooShort,\n typeMismatch: validity.typeMismatch,\n valueMissing: validity.valueMissing,\n valid: validity.valid\n };\n}\n\nfunction getNativeValidity(input: ValidatableElement): ValidationResult {\n return {\n isInvalid: !input.validity.valid,\n validationDetails: getValidity(input),\n validationErrors: input.validationMessage ? [input.validationMessage] : []\n };\n}\n\nfunction getFirstInvalidInput(form: HTMLFormElement): ValidatableElement | null {\n for (let i = 0; i < form.elements.length; i++) {\n let element = form.elements[i] as ValidatableElement;\n if (element.validity?.valid === false) {\n return element;\n }\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"useFormValidation.js.map"}
|
|
@@ -23,7 +23,7 @@ function $860f7da480e22816$export$b8473d3665f3a75a(props, state, ref) {
|
|
|
23
23
|
let { validationBehavior: validationBehavior, focus: focus } = props;
|
|
24
24
|
// This is a useLayoutEffect so that it runs before the useEffect in useFormValidationState, which commits the validation change.
|
|
25
25
|
(0, $c4867b2f328c2698$export$e5c5a5f917a5871c)(()=>{
|
|
26
|
-
if (validationBehavior === 'native' && ref?.current && !ref.current.disabled) {
|
|
26
|
+
if (validationBehavior === 'native' && ref?.current && 'setCustomValidity' in ref.current && !ref.current.disabled) {
|
|
27
27
|
let errorMessage = state.realtimeValidation.isInvalid ? state.realtimeValidation.validationErrors.join(' ') || 'Invalid value.' : '';
|
|
28
28
|
ref.current.setCustomValidity(errorMessage);
|
|
29
29
|
// Prevent default tooltip for validation message.
|