@react-stately/dnd 3.2.9-nightly.4555 → 3.2.9-nightly.4558

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.
@@ -0,0 +1,109 @@
1
+ import {useState as $lyPoT$useState, useRef as $lyPoT$useRef, useCallback as $lyPoT$useCallback} from "react";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
15
+ let { acceptedDragTypes: acceptedDragTypes = "all", isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props;
16
+ let [target, setTarget] = (0, $lyPoT$useState)(null);
17
+ let targetRef = (0, $lyPoT$useRef)(null);
18
+ let getOppositeTarget = (target)=>{
19
+ if (target.dropPosition === "before") {
20
+ let key = collection.getKeyBefore(target.key);
21
+ return key != null ? {
22
+ type: "item",
23
+ key: key,
24
+ dropPosition: "after"
25
+ } : null;
26
+ } else if (target.dropPosition === "after") {
27
+ let key = collection.getKeyAfter(target.key);
28
+ return key != null ? {
29
+ type: "item",
30
+ key: key,
31
+ dropPosition: "before"
32
+ } : null;
33
+ }
34
+ };
35
+ let defaultGetDropOperation = (0, $lyPoT$useCallback)((e)=>{
36
+ if (isDisabled) return "cancel";
37
+ let { target: target, types: types, allowedOperations: allowedOperations, isInternal: isInternal, draggingKeys: draggingKeys } = e;
38
+ if (acceptedDragTypes === "all" || acceptedDragTypes.some((type)=>types.has(type))) {
39
+ let isValidInsert = onInsert && target.type === "item" && !isInternal && (target.dropPosition === "before" || target.dropPosition === "after");
40
+ let isValidReorder = onReorder && target.type === "item" && isInternal && (target.dropPosition === "before" || target.dropPosition === "after");
41
+ // Feedback was that internal root drop was weird so preventing that from happening
42
+ let isValidRootDrop = onRootDrop && target.type === "root" && !isInternal;
43
+ // Automatically prevent items (i.e. folders) from being dropped on themselves.
44
+ let isValidOnItemDrop = onItemDrop && target.type === "item" && target.dropPosition === "on" && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));
45
+ if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {
46
+ if (getDropOperation) return getDropOperation(target, types, allowedOperations);
47
+ else return allowedOperations[0];
48
+ }
49
+ }
50
+ return "cancel";
51
+ }, [
52
+ isDisabled,
53
+ acceptedDragTypes,
54
+ getDropOperation,
55
+ onInsert,
56
+ onRootDrop,
57
+ onItemDrop,
58
+ shouldAcceptItemDrop,
59
+ onReorder,
60
+ onDrop
61
+ ]);
62
+ return {
63
+ collection: collection,
64
+ selectionManager: selectionManager,
65
+ isDisabled: isDisabled,
66
+ target: target,
67
+ setTarget (newTarget) {
68
+ if (this.isDropTarget(newTarget)) return;
69
+ let target = targetRef.current;
70
+ if (target && typeof props.onDropExit === "function") props.onDropExit({
71
+ type: "dropexit",
72
+ x: 0,
73
+ y: 0,
74
+ target: target
75
+ });
76
+ if (newTarget && typeof onDropEnter === "function") onDropEnter({
77
+ type: "dropenter",
78
+ x: 0,
79
+ y: 0,
80
+ target: newTarget
81
+ });
82
+ targetRef.current = newTarget;
83
+ setTarget(newTarget);
84
+ },
85
+ isDropTarget (dropTarget) {
86
+ let target = targetRef.current;
87
+ if ($e672e8bc247525d1$var$isEqualDropTarget(dropTarget, target)) return true;
88
+ // Check if the targets point at the same point between two items, one referring before, and the other after.
89
+ if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === "item" && (target === null || target === void 0 ? void 0 : target.type) === "item" && dropTarget.key !== target.key && dropTarget.dropPosition !== target.dropPosition && dropTarget.dropPosition !== "on" && target.dropPosition !== "on") return $e672e8bc247525d1$var$isEqualDropTarget(getOppositeTarget(dropTarget), target) || $e672e8bc247525d1$var$isEqualDropTarget(dropTarget, getOppositeTarget(target));
90
+ return false;
91
+ },
92
+ getDropOperation (e) {
93
+ return defaultGetDropOperation(e);
94
+ }
95
+ };
96
+ }
97
+ function $e672e8bc247525d1$var$isEqualDropTarget(a, b) {
98
+ if (!a) return !b;
99
+ switch(a.type){
100
+ case "root":
101
+ return (b === null || b === void 0 ? void 0 : b.type) === "root";
102
+ case "item":
103
+ return (b === null || b === void 0 ? void 0 : b.type) === "item" && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null || b === void 0 ? void 0 : b.dropPosition) === a.dropPosition;
104
+ }
105
+ }
106
+
107
+
108
+ export {$e672e8bc247525d1$export$926850f6ecef79d0 as useDroppableCollectionState};
109
+ //# sourceMappingURL=useDroppableCollectionState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AA2CM,SAAS,0CAA4B,KAAsC;IAChF,IAAI,qBACF,oBAAoB,mBACpB,UAAU,YACV,QAAQ,cACR,UAAU,cACV,UAAU,aACV,SAAS,wBACT,oBAAoB,cACpB,UAAU,oBACV,gBAAgB,eAChB,WAAW,oBACX,gBAAgB,UAChB,MAAM,EACP,GAAG;IACJ,IAAI,CAAC,QAAQ,UAAU,GAAG,CAAA,GAAA,eAAO,EAAc;IAC/C,IAAI,YAAY,CAAA,GAAA,aAAK,EAAc;IAEnC,IAAI,oBAAoB,CAAC;QACvB,IAAI,OAAO,YAAY,KAAK,UAAU;YACpC,IAAI,MAAM,WAAW,YAAY,CAAC,OAAO,GAAG;YAC5C,OAAO,OAAO,O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gBACA;QACA,WAAU,SAAS;YACjB,IAAI,IAAI,CAAC,YAAY,CAAC,YACpB;YAGF,IAAI,SAAS,UAAU,OAAO;YAC9B,IAAI,UAAU,OAAO,MAAM,UAAU,KAAK,YACxC,MAAM,UAAU,CAAC;gBACf,MAAM;gBACN,GAAG;gBACH,GAAG;wBACH;YACF;YAGF,IAAI,aAAa,OAAO,gBAAgB,YACtC,YAAY;gBACV,MAAM;gBACN,GAAG;gBACH,GAAG;gBACH,QAAQ;YACV;YAGF,UAAU,OAAO,GAAG;YACpB,UAAU;QACZ;QACA,cAAa,UAAU;YACrB,IAAI,SAAS,UAAU,OAAO;YAC9B,IAAI,wCAAkB,YAAY,SAChC,OAAO;YAGT,6GAA6G;YAC7G,IACE,CAAA,uBAAA,iCAAA,WAAY,IAAI,MAAK,UACrB,CAAA,mBAAA,6BAAA,OAAQ,IAAI,MAAK,UACjB,WAAW,GAAG,KAAK,OAAO,GAAG,IAC7B,WAAW,YAAY,KAAK,OAAO,YAAY,IAC/C,WAAW,YAAY,KAAK,QAC5B,OAAO,YAAY,KAAK,MAExB,OAAO,wCAAkB,kBAAkB,aAAa,WACtD,wCAAkB,YAAY,kBAAkB;YAGpD,OAAO;QACT;QACA,kBAAiB,CAAC;YAChB,OAAO,wBAAwB;QACjC;IACF;AACF;AAEA,SAAS,wCAAkB,CAAa,EAAE,CAAa;IACrD,IAAI,CAAC,GACH,OAAO,CAAC;IAGV,OAAQ,EAAE,IAAI;QACZ,KAAK;YACH,OAAO,CAAA,cAAA,wBAAA,EAAG,IAAI,MAAK;QACrB,KAAK;YACH,OAAO,CAAA,cAAA,wBAAA,EAAG,IAAI,MAAK,UAAU,CAAA,cAAA,wBAAA,EAAG,GAAG,MAAK,EAAE,GAAG,IAAI,CAAA,cAAA,wBAAA,EAAG,YAAY,MAAK,EAAE,YAAY;IACvF;AACF","sources":["packages/@react-stately/dnd/src/useDroppableCollectionState.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 {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarget, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useCallback, useRef, useState} from 'react';\n\ninterface DropOperationEvent {\n target: DropTarget,\n types: DragTypes,\n allowedOperations: DropOperation[],\n isInternal: boolean,\n draggingKeys: Set<Key>\n}\n\nexport interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** Whether the drop events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface DroppableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The current drop target. */\n target: DropTarget | null,\n /** Whether drop events are disabled. */\n isDisabled?: boolean,\n /** Sets the current drop target. */\n setTarget(target: DropTarget): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget): boolean,\n /** Returns the drop operation for the given parameters. */\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\n/**\n * Manages state for a droppable collection.\n */\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\n isDisabled,\n onInsert,\n onRootDrop,\n onItemDrop,\n onReorder,\n shouldAcceptItemDrop,\n collection,\n selectionManager,\n onDropEnter,\n getDropOperation,\n onDrop\n } = props;\n let [target, setTarget] = useState<DropTarget>(null);\n let targetRef = useRef<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\n if (target.dropPosition === 'before') {\n let key = collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n if (isDisabled) {\n return 'cancel';\n }\n\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\n\n if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {\n let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n // Feedback was that internal root drop was weird so preventing that from happening\n let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;\n // Automatically prevent items (i.e. folders) from being dropped on themselves.\n let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));\n\n if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {\n if (getDropOperation) {\n return getDropOperation(target, types, allowedOperations);\n } else {\n return allowedOperations[0];\n }\n }\n }\n\n return 'cancel';\n }, [isDisabled, acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\n isDisabled,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\n let target = targetRef.current;\n if (target && typeof props.onDropExit === 'function') {\n props.onDropExit({\n type: 'dropexit',\n x: 0, // todo\n y: 0,\n target\n });\n }\n\n if (newTarget && typeof onDropEnter === 'function') {\n onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n targetRef.current = newTarget;\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\n if (isEqualDropTarget(dropTarget, target)) {\n return true;\n }\n\n // Check if the targets point at the same point between two items, one referring before, and the other after.\n if (\n dropTarget?.type === 'item' &&\n target?.type === 'item' &&\n dropTarget.key !== target.key &&\n dropTarget.dropPosition !== target.dropPosition &&\n dropTarget.dropPosition !== 'on' &&\n target.dropPosition !== 'on'\n ) {\n return isEqualDropTarget(getOppositeTarget(dropTarget), target) ||\n isEqualDropTarget(dropTarget, getOppositeTarget(target));\n }\n\n return false;\n },\n getDropOperation(e) {\n return defaultGetDropOperation(e);\n }\n };\n}\n\nfunction isEqualDropTarget(a: DropTarget, b: DropTarget) {\n if (!a) {\n return !b;\n }\n\n switch (a.type) {\n case 'root':\n return b?.type === 'root';\n case 'item':\n return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;\n }\n}\n"],"names":[],"version":3,"file":"useDroppableCollectionState.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/dnd",
3
- "version": "3.2.9-nightly.4555+81162ea39",
3
+ "version": "3.2.9-nightly.4558+c5e4b3701",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,8 +22,8 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/selection": "3.0.0-nightly.2843+81162ea39",
26
- "@react-types/shared": "3.0.0-nightly.2843+81162ea39",
25
+ "@react-stately/selection": "3.0.0-nightly.2846+c5e4b3701",
26
+ "@react-types/shared": "3.0.0-nightly.2846+c5e4b3701",
27
27
  "@swc/helpers": "^0.5.0"
28
28
  },
29
29
  "peerDependencies": {
@@ -32,5 +32,5 @@
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "81162ea392926d06ec3d25c228e6f9b6b5479d59"
35
+ "gitHead": "c5e4b3701fdb89eb551f1b3697ac253f06ef68fa"
36
36
  }