@react-aria/dnd 3.2.2-nightly.3993 → 3.3.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/import.mjs +121 -47
- package/dist/main.js +120 -46
- package/dist/main.js.map +1 -1
- package/dist/module.js +121 -47
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +20 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/ListDropTargetDelegate.ts +102 -22
- package/src/useDroppableCollection.ts +78 -37
package/dist/module.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useInteractionModality as $fP8tg$useInteractionModality, getInteractionModality as $fP8tg$getInteractionModality, setInteractionModality as $fP8tg$setInteractionModality, useFocus as $fP8tg$useFocus} from "@react-aria/interactions";
|
|
2
2
|
import $fP8tg$react, {useRef as $fP8tg$useRef, useState as $fP8tg$useState, useEffect as $fP8tg$useEffect, useCallback as $fP8tg$useCallback, useImperativeHandle as $fP8tg$useImperativeHandle} from "react";
|
|
3
3
|
import {useGlobalListeners as $fP8tg$useGlobalListeners, useLayoutEffect as $fP8tg$useLayoutEffect, useDescription as $fP8tg$useDescription, isVirtualPointerEvent as $fP8tg$isVirtualPointerEvent, isVirtualClick as $fP8tg$isVirtualClick, useEffectEvent as $fP8tg$useEffectEvent, isMac as $fP8tg$isMac, isIPad as $fP8tg$isIPad, useId as $fP8tg$useId, mergeProps as $fP8tg$mergeProps, isScrollable as $fP8tg$isScrollable, getScrollParent as $fP8tg$getScrollParent, isWebKit as $fP8tg$isWebKit, isIOS as $fP8tg$isIOS, chain as $fP8tg$chain} from "@react-aria/utils";
|
|
4
|
-
import {useLocalizedStringFormatter as $fP8tg$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
4
|
+
import {useLocalizedStringFormatter as $fP8tg$useLocalizedStringFormatter, useLocale as $fP8tg$useLocale} from "@react-aria/i18n";
|
|
5
5
|
import {announce as $fP8tg$announce} from "@react-aria/live-announcer";
|
|
6
6
|
import {ariaHideOutside as $fP8tg$ariaHideOutside} from "@react-aria/overlays";
|
|
7
7
|
import {flushSync as $fP8tg$flushSync} from "react-dom";
|
|
@@ -2933,11 +2933,17 @@ function $80d9daea3067eff3$export$6323452ca4533ed8(ref) {
|
|
|
2933
2933
|
|
|
2934
2934
|
|
|
2935
2935
|
|
|
2936
|
+
|
|
2936
2937
|
const $4b52e4eff84e5217$var$DROP_POSITIONS = [
|
|
2937
2938
|
"before",
|
|
2938
2939
|
"on",
|
|
2939
2940
|
"after"
|
|
2940
2941
|
];
|
|
2942
|
+
const $4b52e4eff84e5217$var$DROP_POSITIONS_RTL = [
|
|
2943
|
+
"after",
|
|
2944
|
+
"on",
|
|
2945
|
+
"before"
|
|
2946
|
+
];
|
|
2941
2947
|
function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
|
|
2942
2948
|
let localState = (0, $fP8tg$useRef)({
|
|
2943
2949
|
props: props,
|
|
@@ -3154,25 +3160,35 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
|
|
|
3154
3160
|
droppingState.current = null;
|
|
3155
3161
|
}
|
|
3156
3162
|
});
|
|
3163
|
+
let { direction: direction } = (0, $fP8tg$useLocale)();
|
|
3157
3164
|
(0, $fP8tg$useEffect)(()=>{
|
|
3158
|
-
let getNextTarget = (target, wrap = true)=>{
|
|
3165
|
+
let getNextTarget = (target, wrap = true, horizontal = false)=>{
|
|
3159
3166
|
if (!target) return {
|
|
3160
3167
|
type: "root"
|
|
3161
3168
|
};
|
|
3162
3169
|
let { keyboardDelegate: keyboardDelegate } = localState.props;
|
|
3163
|
-
let nextKey
|
|
3164
|
-
|
|
3170
|
+
let nextKey;
|
|
3171
|
+
if ((target === null || target === void 0 ? void 0 : target.type) === "item") nextKey = horizontal ? keyboardDelegate.getKeyRightOf(target.key) : keyboardDelegate.getKeyBelow(target.key);
|
|
3172
|
+
else nextKey = horizontal && direction === "rtl" ? keyboardDelegate.getLastKey() : keyboardDelegate.getFirstKey();
|
|
3173
|
+
let dropPositions = horizontal && direction === "rtl" ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS;
|
|
3174
|
+
let dropPosition = dropPositions[0];
|
|
3165
3175
|
if (target.type === "item") {
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
dropPosition
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
+
// If the the keyboard delegate returned the next key in the collection,
|
|
3177
|
+
// first try the other positions in the current key. Otherwise (e.g. in a grid layout),
|
|
3178
|
+
// jump to the same drop position in the new key.
|
|
3179
|
+
let nextCollectionKey = horizontal && direction === "rtl" ? localState.state.collection.getKeyBefore(target.key) : localState.state.collection.getKeyAfter(target.key);
|
|
3180
|
+
if (nextKey == null || nextKey === nextCollectionKey) {
|
|
3181
|
+
let positionIndex = dropPositions.indexOf(target.dropPosition);
|
|
3182
|
+
let nextDropPosition = dropPositions[positionIndex + 1];
|
|
3183
|
+
if (positionIndex < dropPositions.length - 1 && !(nextDropPosition === dropPositions[2] && nextKey != null)) return {
|
|
3184
|
+
type: "item",
|
|
3185
|
+
key: target.key,
|
|
3186
|
+
dropPosition: nextDropPosition
|
|
3187
|
+
};
|
|
3188
|
+
// If the last drop position was 'after', then 'before' on the next key is equivalent.
|
|
3189
|
+
// Switch to 'on' instead.
|
|
3190
|
+
if (target.dropPosition === dropPositions[2]) dropPosition = "on";
|
|
3191
|
+
} else dropPosition = target.dropPosition;
|
|
3176
3192
|
}
|
|
3177
3193
|
if (nextKey == null) {
|
|
3178
3194
|
if (wrap) return {
|
|
@@ -3186,21 +3202,30 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
|
|
|
3186
3202
|
dropPosition: dropPosition
|
|
3187
3203
|
};
|
|
3188
3204
|
};
|
|
3189
|
-
let getPreviousTarget = (target, wrap = true)=>{
|
|
3205
|
+
let getPreviousTarget = (target, wrap = true, horizontal = false)=>{
|
|
3190
3206
|
let { keyboardDelegate: keyboardDelegate } = localState.props;
|
|
3191
|
-
let nextKey
|
|
3192
|
-
|
|
3207
|
+
let nextKey;
|
|
3208
|
+
if ((target === null || target === void 0 ? void 0 : target.type) === "item") nextKey = horizontal ? keyboardDelegate.getKeyLeftOf(target.key) : keyboardDelegate.getKeyAbove(target.key);
|
|
3209
|
+
else nextKey = horizontal && direction === "rtl" ? keyboardDelegate.getFirstKey() : keyboardDelegate.getLastKey();
|
|
3210
|
+
let dropPositions = horizontal && direction === "rtl" ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS;
|
|
3211
|
+
let dropPosition = !target || target.type === "root" ? dropPositions[2] : "on";
|
|
3193
3212
|
if ((target === null || target === void 0 ? void 0 : target.type) === "item") {
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
dropPosition
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3213
|
+
// If the the keyboard delegate returned the previous key in the collection,
|
|
3214
|
+
// first try the other positions in the current key. Otherwise (e.g. in a grid layout),
|
|
3215
|
+
// jump to the same drop position in the new key.
|
|
3216
|
+
let prevCollectionKey = horizontal && direction === "rtl" ? localState.state.collection.getKeyAfter(target.key) : localState.state.collection.getKeyBefore(target.key);
|
|
3217
|
+
if (nextKey == null || nextKey === prevCollectionKey) {
|
|
3218
|
+
let positionIndex = dropPositions.indexOf(target.dropPosition);
|
|
3219
|
+
let nextDropPosition = dropPositions[positionIndex - 1];
|
|
3220
|
+
if (positionIndex > 0 && nextDropPosition !== dropPositions[2]) return {
|
|
3221
|
+
type: "item",
|
|
3222
|
+
key: target.key,
|
|
3223
|
+
dropPosition: nextDropPosition
|
|
3224
|
+
};
|
|
3225
|
+
// If the last drop position was 'before', then 'after' on the previous key is equivalent.
|
|
3226
|
+
// Switch to 'on' instead.
|
|
3227
|
+
if (target.dropPosition === dropPositions[0]) dropPosition = "on";
|
|
3228
|
+
} else dropPosition = target.dropPosition;
|
|
3204
3229
|
}
|
|
3205
3230
|
if (nextKey == null) {
|
|
3206
3231
|
if (wrap) return {
|
|
@@ -3334,6 +3359,18 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
|
|
|
3334
3359
|
localState.state.setTarget(target);
|
|
3335
3360
|
}
|
|
3336
3361
|
break;
|
|
3362
|
+
case "ArrowLeft":
|
|
3363
|
+
if (keyboardDelegate.getKeyLeftOf) {
|
|
3364
|
+
let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getPreviousTarget(target, wrap, true));
|
|
3365
|
+
localState.state.setTarget(target);
|
|
3366
|
+
}
|
|
3367
|
+
break;
|
|
3368
|
+
case "ArrowRight":
|
|
3369
|
+
if (keyboardDelegate.getKeyRightOf) {
|
|
3370
|
+
let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, true));
|
|
3371
|
+
localState.state.setTarget(target);
|
|
3372
|
+
}
|
|
3373
|
+
break;
|
|
3337
3374
|
case "Home":
|
|
3338
3375
|
if (keyboardDelegate.getFirstKey) {
|
|
3339
3376
|
let target = nextValidTarget(null, types, drag.allowedDropOperations, getNextTarget);
|
|
@@ -3427,7 +3464,8 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
|
|
|
3427
3464
|
}, [
|
|
3428
3465
|
localState,
|
|
3429
3466
|
ref,
|
|
3430
|
-
onDrop
|
|
3467
|
+
onDrop,
|
|
3468
|
+
direction
|
|
3431
3469
|
]);
|
|
3432
3470
|
let id = (0, $fP8tg$useId)();
|
|
3433
3471
|
(0, $7252cd45fc48c07c$export$dfdf5deeaf27473f).set(state, {
|
|
@@ -3854,13 +3892,40 @@ let $ad0e3f3d9c50e4ba$export$905ab40ac2179daa = /*#__PURE__*/ (0, $fP8tg$react).
|
|
|
3854
3892
|
|
|
3855
3893
|
|
|
3856
3894
|
class $3ca85212bf8898e4$export$fbd65d14c79e28cc {
|
|
3895
|
+
getPrimaryStart(rect) {
|
|
3896
|
+
return this.orientation === "horizontal" ? rect.left : rect.top;
|
|
3897
|
+
}
|
|
3898
|
+
getPrimaryEnd(rect) {
|
|
3899
|
+
return this.orientation === "horizontal" ? rect.right : rect.bottom;
|
|
3900
|
+
}
|
|
3901
|
+
getSecondaryStart(rect) {
|
|
3902
|
+
return this.orientation === "horizontal" ? rect.top : rect.left;
|
|
3903
|
+
}
|
|
3904
|
+
getSecondaryEnd(rect) {
|
|
3905
|
+
return this.orientation === "horizontal" ? rect.bottom : rect.right;
|
|
3906
|
+
}
|
|
3907
|
+
getFlowStart(rect) {
|
|
3908
|
+
return this.layout === "stack" ? this.getPrimaryStart(rect) : this.getSecondaryStart(rect);
|
|
3909
|
+
}
|
|
3910
|
+
getFlowEnd(rect) {
|
|
3911
|
+
return this.layout === "stack" ? this.getPrimaryEnd(rect) : this.getSecondaryEnd(rect);
|
|
3912
|
+
}
|
|
3913
|
+
getFlowSize(rect) {
|
|
3914
|
+
return this.getFlowEnd(rect) - this.getFlowStart(rect);
|
|
3915
|
+
}
|
|
3857
3916
|
getDropTargetFromPoint(x, y, isValidDropTarget) {
|
|
3858
3917
|
if (this.collection.size === 0) return {
|
|
3859
3918
|
type: "root"
|
|
3860
3919
|
};
|
|
3861
3920
|
let rect = this.ref.current.getBoundingClientRect();
|
|
3862
|
-
|
|
3863
|
-
|
|
3921
|
+
let primary = this.orientation === "horizontal" ? x : y;
|
|
3922
|
+
let secondary = this.orientation === "horizontal" ? y : x;
|
|
3923
|
+
primary += this.getPrimaryStart(rect);
|
|
3924
|
+
secondary += this.getSecondaryStart(rect);
|
|
3925
|
+
let flow = this.layout === "stack" ? primary : secondary;
|
|
3926
|
+
let isPrimaryRTL = this.orientation === "horizontal" && this.direction === "rtl";
|
|
3927
|
+
let isSecondaryRTL = this.layout === "grid" && this.orientation === "vertical" && this.direction === "rtl";
|
|
3928
|
+
let isFlowRTL = this.layout === "stack" ? isPrimaryRTL : isSecondaryRTL;
|
|
3864
3929
|
let elements = this.ref.current.querySelectorAll("[data-key]");
|
|
3865
3930
|
let elementMap = new Map();
|
|
3866
3931
|
for (let item of elements)if (item instanceof HTMLElement) elementMap.set(item.dataset.key, item);
|
|
@@ -3874,8 +3939,14 @@ class $3ca85212bf8898e4$export$fbd65d14c79e28cc {
|
|
|
3874
3939
|
let item = items[mid];
|
|
3875
3940
|
let element = elementMap.get(String(item.key));
|
|
3876
3941
|
let rect = element.getBoundingClientRect();
|
|
3877
|
-
|
|
3878
|
-
|
|
3942
|
+
let update = (isGreater)=>{
|
|
3943
|
+
if (isGreater) low = mid + 1;
|
|
3944
|
+
else high = mid;
|
|
3945
|
+
};
|
|
3946
|
+
if (primary < this.getPrimaryStart(rect)) update(isPrimaryRTL);
|
|
3947
|
+
else if (primary > this.getPrimaryEnd(rect)) update(!isPrimaryRTL);
|
|
3948
|
+
else if (secondary < this.getSecondaryStart(rect)) update(isSecondaryRTL);
|
|
3949
|
+
else if (secondary > this.getSecondaryEnd(rect)) update(!isSecondaryRTL);
|
|
3879
3950
|
else {
|
|
3880
3951
|
let target = {
|
|
3881
3952
|
type: "item",
|
|
@@ -3884,26 +3955,26 @@ class $3ca85212bf8898e4$export$fbd65d14c79e28cc {
|
|
|
3884
3955
|
};
|
|
3885
3956
|
if (isValidDropTarget(target)) {
|
|
3886
3957
|
// Otherwise, if dropping on the item is accepted, try the before/after positions if within 5px
|
|
3887
|
-
// of the
|
|
3888
|
-
if (
|
|
3958
|
+
// of the start or end of the item.
|
|
3959
|
+
if (flow <= this.getFlowStart(rect) + 5 && isValidDropTarget({
|
|
3889
3960
|
...target,
|
|
3890
3961
|
dropPosition: "before"
|
|
3891
|
-
})) target.dropPosition = "before";
|
|
3892
|
-
else if (
|
|
3962
|
+
})) target.dropPosition = isFlowRTL ? "after" : "before";
|
|
3963
|
+
else if (flow >= this.getFlowEnd(rect) - 5 && isValidDropTarget({
|
|
3893
3964
|
...target,
|
|
3894
3965
|
dropPosition: "after"
|
|
3895
|
-
})) target.dropPosition = "after";
|
|
3966
|
+
})) target.dropPosition = isFlowRTL ? "before" : "after";
|
|
3896
3967
|
} else {
|
|
3897
|
-
// If dropping on the item isn't accepted, try the target before or after depending on the
|
|
3898
|
-
let
|
|
3899
|
-
if (
|
|
3968
|
+
// If dropping on the item isn't accepted, try the target before or after depending on the position.
|
|
3969
|
+
let mid = this.getFlowStart(rect) + this.getFlowSize(rect) / 2;
|
|
3970
|
+
if (flow <= mid && isValidDropTarget({
|
|
3900
3971
|
...target,
|
|
3901
3972
|
dropPosition: "before"
|
|
3902
|
-
})) target.dropPosition = "before";
|
|
3903
|
-
else if (
|
|
3973
|
+
})) target.dropPosition = isFlowRTL ? "after" : "before";
|
|
3974
|
+
else if (flow >= mid && isValidDropTarget({
|
|
3904
3975
|
...target,
|
|
3905
3976
|
dropPosition: "after"
|
|
3906
|
-
})) target.dropPosition = "after";
|
|
3977
|
+
})) target.dropPosition = isFlowRTL ? "before" : "after";
|
|
3907
3978
|
}
|
|
3908
3979
|
return target;
|
|
3909
3980
|
}
|
|
@@ -3911,20 +3982,23 @@ class $3ca85212bf8898e4$export$fbd65d14c79e28cc {
|
|
|
3911
3982
|
let item = items[Math.min(low, items.length - 1)];
|
|
3912
3983
|
let element = elementMap.get(String(item.key));
|
|
3913
3984
|
rect = element.getBoundingClientRect();
|
|
3914
|
-
if (Math.abs(
|
|
3985
|
+
if (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect))) return {
|
|
3915
3986
|
type: "item",
|
|
3916
3987
|
key: item.key,
|
|
3917
|
-
dropPosition: "before"
|
|
3988
|
+
dropPosition: isFlowRTL ? "after" : "before"
|
|
3918
3989
|
};
|
|
3919
3990
|
return {
|
|
3920
3991
|
type: "item",
|
|
3921
3992
|
key: item.key,
|
|
3922
|
-
dropPosition: "after"
|
|
3993
|
+
dropPosition: isFlowRTL ? "before" : "after"
|
|
3923
3994
|
};
|
|
3924
3995
|
}
|
|
3925
|
-
constructor(collection, ref){
|
|
3996
|
+
constructor(collection, ref, options){
|
|
3926
3997
|
this.collection = collection;
|
|
3927
3998
|
this.ref = ref;
|
|
3999
|
+
this.layout = (options === null || options === void 0 ? void 0 : options.layout) || "stack";
|
|
4000
|
+
this.orientation = (options === null || options === void 0 ? void 0 : options.orientation) || "vertical";
|
|
4001
|
+
this.direction = (options === null || options === void 0 ? void 0 : options.direction) || "ltr";
|
|
3928
4002
|
}
|
|
3929
4003
|
}
|
|
3930
4004
|
|