@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/import.mjs
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
|
|
package/dist/main.js
CHANGED
|
@@ -2952,11 +2952,17 @@ function $12cc069a1c69155b$export$6323452ca4533ed8(ref) {
|
|
|
2952
2952
|
|
|
2953
2953
|
|
|
2954
2954
|
|
|
2955
|
+
|
|
2955
2956
|
const $7f93a158ac20b90a$var$DROP_POSITIONS = [
|
|
2956
2957
|
"before",
|
|
2957
2958
|
"on",
|
|
2958
2959
|
"after"
|
|
2959
2960
|
];
|
|
2961
|
+
const $7f93a158ac20b90a$var$DROP_POSITIONS_RTL = [
|
|
2962
|
+
"after",
|
|
2963
|
+
"on",
|
|
2964
|
+
"before"
|
|
2965
|
+
];
|
|
2960
2966
|
function $7f93a158ac20b90a$export$f4e2f423c21f7b04(props, state, ref) {
|
|
2961
2967
|
let localState = (0, $4vY0V$react.useRef)({
|
|
2962
2968
|
props: props,
|
|
@@ -3173,25 +3179,35 @@ function $7f93a158ac20b90a$export$f4e2f423c21f7b04(props, state, ref) {
|
|
|
3173
3179
|
droppingState.current = null;
|
|
3174
3180
|
}
|
|
3175
3181
|
});
|
|
3182
|
+
let { direction: direction } = (0, $4vY0V$reactariai18n.useLocale)();
|
|
3176
3183
|
(0, $4vY0V$react.useEffect)(()=>{
|
|
3177
|
-
let getNextTarget = (target, wrap = true)=>{
|
|
3184
|
+
let getNextTarget = (target, wrap = true, horizontal = false)=>{
|
|
3178
3185
|
if (!target) return {
|
|
3179
3186
|
type: "root"
|
|
3180
3187
|
};
|
|
3181
3188
|
let { keyboardDelegate: keyboardDelegate } = localState.props;
|
|
3182
|
-
let nextKey
|
|
3183
|
-
|
|
3189
|
+
let nextKey;
|
|
3190
|
+
if ((target === null || target === void 0 ? void 0 : target.type) === "item") nextKey = horizontal ? keyboardDelegate.getKeyRightOf(target.key) : keyboardDelegate.getKeyBelow(target.key);
|
|
3191
|
+
else nextKey = horizontal && direction === "rtl" ? keyboardDelegate.getLastKey() : keyboardDelegate.getFirstKey();
|
|
3192
|
+
let dropPositions = horizontal && direction === "rtl" ? $7f93a158ac20b90a$var$DROP_POSITIONS_RTL : $7f93a158ac20b90a$var$DROP_POSITIONS;
|
|
3193
|
+
let dropPosition = dropPositions[0];
|
|
3184
3194
|
if (target.type === "item") {
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
dropPosition
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
+
// If the the keyboard delegate returned the next key in the collection,
|
|
3196
|
+
// first try the other positions in the current key. Otherwise (e.g. in a grid layout),
|
|
3197
|
+
// jump to the same drop position in the new key.
|
|
3198
|
+
let nextCollectionKey = horizontal && direction === "rtl" ? localState.state.collection.getKeyBefore(target.key) : localState.state.collection.getKeyAfter(target.key);
|
|
3199
|
+
if (nextKey == null || nextKey === nextCollectionKey) {
|
|
3200
|
+
let positionIndex = dropPositions.indexOf(target.dropPosition);
|
|
3201
|
+
let nextDropPosition = dropPositions[positionIndex + 1];
|
|
3202
|
+
if (positionIndex < dropPositions.length - 1 && !(nextDropPosition === dropPositions[2] && nextKey != null)) return {
|
|
3203
|
+
type: "item",
|
|
3204
|
+
key: target.key,
|
|
3205
|
+
dropPosition: nextDropPosition
|
|
3206
|
+
};
|
|
3207
|
+
// If the last drop position was 'after', then 'before' on the next key is equivalent.
|
|
3208
|
+
// Switch to 'on' instead.
|
|
3209
|
+
if (target.dropPosition === dropPositions[2]) dropPosition = "on";
|
|
3210
|
+
} else dropPosition = target.dropPosition;
|
|
3195
3211
|
}
|
|
3196
3212
|
if (nextKey == null) {
|
|
3197
3213
|
if (wrap) return {
|
|
@@ -3205,21 +3221,30 @@ function $7f93a158ac20b90a$export$f4e2f423c21f7b04(props, state, ref) {
|
|
|
3205
3221
|
dropPosition: dropPosition
|
|
3206
3222
|
};
|
|
3207
3223
|
};
|
|
3208
|
-
let getPreviousTarget = (target, wrap = true)=>{
|
|
3224
|
+
let getPreviousTarget = (target, wrap = true, horizontal = false)=>{
|
|
3209
3225
|
let { keyboardDelegate: keyboardDelegate } = localState.props;
|
|
3210
|
-
let nextKey
|
|
3211
|
-
|
|
3226
|
+
let nextKey;
|
|
3227
|
+
if ((target === null || target === void 0 ? void 0 : target.type) === "item") nextKey = horizontal ? keyboardDelegate.getKeyLeftOf(target.key) : keyboardDelegate.getKeyAbove(target.key);
|
|
3228
|
+
else nextKey = horizontal && direction === "rtl" ? keyboardDelegate.getFirstKey() : keyboardDelegate.getLastKey();
|
|
3229
|
+
let dropPositions = horizontal && direction === "rtl" ? $7f93a158ac20b90a$var$DROP_POSITIONS_RTL : $7f93a158ac20b90a$var$DROP_POSITIONS;
|
|
3230
|
+
let dropPosition = !target || target.type === "root" ? dropPositions[2] : "on";
|
|
3212
3231
|
if ((target === null || target === void 0 ? void 0 : target.type) === "item") {
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
dropPosition
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3232
|
+
// If the the keyboard delegate returned the previous key in the collection,
|
|
3233
|
+
// first try the other positions in the current key. Otherwise (e.g. in a grid layout),
|
|
3234
|
+
// jump to the same drop position in the new key.
|
|
3235
|
+
let prevCollectionKey = horizontal && direction === "rtl" ? localState.state.collection.getKeyAfter(target.key) : localState.state.collection.getKeyBefore(target.key);
|
|
3236
|
+
if (nextKey == null || nextKey === prevCollectionKey) {
|
|
3237
|
+
let positionIndex = dropPositions.indexOf(target.dropPosition);
|
|
3238
|
+
let nextDropPosition = dropPositions[positionIndex - 1];
|
|
3239
|
+
if (positionIndex > 0 && nextDropPosition !== dropPositions[2]) return {
|
|
3240
|
+
type: "item",
|
|
3241
|
+
key: target.key,
|
|
3242
|
+
dropPosition: nextDropPosition
|
|
3243
|
+
};
|
|
3244
|
+
// If the last drop position was 'before', then 'after' on the previous key is equivalent.
|
|
3245
|
+
// Switch to 'on' instead.
|
|
3246
|
+
if (target.dropPosition === dropPositions[0]) dropPosition = "on";
|
|
3247
|
+
} else dropPosition = target.dropPosition;
|
|
3223
3248
|
}
|
|
3224
3249
|
if (nextKey == null) {
|
|
3225
3250
|
if (wrap) return {
|
|
@@ -3353,6 +3378,18 @@ function $7f93a158ac20b90a$export$f4e2f423c21f7b04(props, state, ref) {
|
|
|
3353
3378
|
localState.state.setTarget(target);
|
|
3354
3379
|
}
|
|
3355
3380
|
break;
|
|
3381
|
+
case "ArrowLeft":
|
|
3382
|
+
if (keyboardDelegate.getKeyLeftOf) {
|
|
3383
|
+
let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getPreviousTarget(target, wrap, true));
|
|
3384
|
+
localState.state.setTarget(target);
|
|
3385
|
+
}
|
|
3386
|
+
break;
|
|
3387
|
+
case "ArrowRight":
|
|
3388
|
+
if (keyboardDelegate.getKeyRightOf) {
|
|
3389
|
+
let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, true));
|
|
3390
|
+
localState.state.setTarget(target);
|
|
3391
|
+
}
|
|
3392
|
+
break;
|
|
3356
3393
|
case "Home":
|
|
3357
3394
|
if (keyboardDelegate.getFirstKey) {
|
|
3358
3395
|
let target = nextValidTarget(null, types, drag.allowedDropOperations, getNextTarget);
|
|
@@ -3446,7 +3483,8 @@ function $7f93a158ac20b90a$export$f4e2f423c21f7b04(props, state, ref) {
|
|
|
3446
3483
|
}, [
|
|
3447
3484
|
localState,
|
|
3448
3485
|
ref,
|
|
3449
|
-
onDrop
|
|
3486
|
+
onDrop,
|
|
3487
|
+
direction
|
|
3450
3488
|
]);
|
|
3451
3489
|
let id = (0, $4vY0V$reactariautils.useId)();
|
|
3452
3490
|
(0, $4620ae0dc40f0031$export$dfdf5deeaf27473f).set(state, {
|
|
@@ -3873,13 +3911,40 @@ let $2dccaca1f4baa446$export$905ab40ac2179daa = /*#__PURE__*/ (0, ($parcel$inter
|
|
|
3873
3911
|
|
|
3874
3912
|
|
|
3875
3913
|
class $2268795bbb597ecb$export$fbd65d14c79e28cc {
|
|
3914
|
+
getPrimaryStart(rect) {
|
|
3915
|
+
return this.orientation === "horizontal" ? rect.left : rect.top;
|
|
3916
|
+
}
|
|
3917
|
+
getPrimaryEnd(rect) {
|
|
3918
|
+
return this.orientation === "horizontal" ? rect.right : rect.bottom;
|
|
3919
|
+
}
|
|
3920
|
+
getSecondaryStart(rect) {
|
|
3921
|
+
return this.orientation === "horizontal" ? rect.top : rect.left;
|
|
3922
|
+
}
|
|
3923
|
+
getSecondaryEnd(rect) {
|
|
3924
|
+
return this.orientation === "horizontal" ? rect.bottom : rect.right;
|
|
3925
|
+
}
|
|
3926
|
+
getFlowStart(rect) {
|
|
3927
|
+
return this.layout === "stack" ? this.getPrimaryStart(rect) : this.getSecondaryStart(rect);
|
|
3928
|
+
}
|
|
3929
|
+
getFlowEnd(rect) {
|
|
3930
|
+
return this.layout === "stack" ? this.getPrimaryEnd(rect) : this.getSecondaryEnd(rect);
|
|
3931
|
+
}
|
|
3932
|
+
getFlowSize(rect) {
|
|
3933
|
+
return this.getFlowEnd(rect) - this.getFlowStart(rect);
|
|
3934
|
+
}
|
|
3876
3935
|
getDropTargetFromPoint(x, y, isValidDropTarget) {
|
|
3877
3936
|
if (this.collection.size === 0) return {
|
|
3878
3937
|
type: "root"
|
|
3879
3938
|
};
|
|
3880
3939
|
let rect = this.ref.current.getBoundingClientRect();
|
|
3881
|
-
|
|
3882
|
-
|
|
3940
|
+
let primary = this.orientation === "horizontal" ? x : y;
|
|
3941
|
+
let secondary = this.orientation === "horizontal" ? y : x;
|
|
3942
|
+
primary += this.getPrimaryStart(rect);
|
|
3943
|
+
secondary += this.getSecondaryStart(rect);
|
|
3944
|
+
let flow = this.layout === "stack" ? primary : secondary;
|
|
3945
|
+
let isPrimaryRTL = this.orientation === "horizontal" && this.direction === "rtl";
|
|
3946
|
+
let isSecondaryRTL = this.layout === "grid" && this.orientation === "vertical" && this.direction === "rtl";
|
|
3947
|
+
let isFlowRTL = this.layout === "stack" ? isPrimaryRTL : isSecondaryRTL;
|
|
3883
3948
|
let elements = this.ref.current.querySelectorAll("[data-key]");
|
|
3884
3949
|
let elementMap = new Map();
|
|
3885
3950
|
for (let item of elements)if (item instanceof HTMLElement) elementMap.set(item.dataset.key, item);
|
|
@@ -3893,8 +3958,14 @@ class $2268795bbb597ecb$export$fbd65d14c79e28cc {
|
|
|
3893
3958
|
let item = items[mid];
|
|
3894
3959
|
let element = elementMap.get(String(item.key));
|
|
3895
3960
|
let rect = element.getBoundingClientRect();
|
|
3896
|
-
|
|
3897
|
-
|
|
3961
|
+
let update = (isGreater)=>{
|
|
3962
|
+
if (isGreater) low = mid + 1;
|
|
3963
|
+
else high = mid;
|
|
3964
|
+
};
|
|
3965
|
+
if (primary < this.getPrimaryStart(rect)) update(isPrimaryRTL);
|
|
3966
|
+
else if (primary > this.getPrimaryEnd(rect)) update(!isPrimaryRTL);
|
|
3967
|
+
else if (secondary < this.getSecondaryStart(rect)) update(isSecondaryRTL);
|
|
3968
|
+
else if (secondary > this.getSecondaryEnd(rect)) update(!isSecondaryRTL);
|
|
3898
3969
|
else {
|
|
3899
3970
|
let target = {
|
|
3900
3971
|
type: "item",
|
|
@@ -3903,26 +3974,26 @@ class $2268795bbb597ecb$export$fbd65d14c79e28cc {
|
|
|
3903
3974
|
};
|
|
3904
3975
|
if (isValidDropTarget(target)) {
|
|
3905
3976
|
// Otherwise, if dropping on the item is accepted, try the before/after positions if within 5px
|
|
3906
|
-
// of the
|
|
3907
|
-
if (
|
|
3977
|
+
// of the start or end of the item.
|
|
3978
|
+
if (flow <= this.getFlowStart(rect) + 5 && isValidDropTarget({
|
|
3908
3979
|
...target,
|
|
3909
3980
|
dropPosition: "before"
|
|
3910
|
-
})) target.dropPosition = "before";
|
|
3911
|
-
else if (
|
|
3981
|
+
})) target.dropPosition = isFlowRTL ? "after" : "before";
|
|
3982
|
+
else if (flow >= this.getFlowEnd(rect) - 5 && isValidDropTarget({
|
|
3912
3983
|
...target,
|
|
3913
3984
|
dropPosition: "after"
|
|
3914
|
-
})) target.dropPosition = "after";
|
|
3985
|
+
})) target.dropPosition = isFlowRTL ? "before" : "after";
|
|
3915
3986
|
} else {
|
|
3916
|
-
// If dropping on the item isn't accepted, try the target before or after depending on the
|
|
3917
|
-
let
|
|
3918
|
-
if (
|
|
3987
|
+
// If dropping on the item isn't accepted, try the target before or after depending on the position.
|
|
3988
|
+
let mid = this.getFlowStart(rect) + this.getFlowSize(rect) / 2;
|
|
3989
|
+
if (flow <= mid && isValidDropTarget({
|
|
3919
3990
|
...target,
|
|
3920
3991
|
dropPosition: "before"
|
|
3921
|
-
})) target.dropPosition = "before";
|
|
3922
|
-
else if (
|
|
3992
|
+
})) target.dropPosition = isFlowRTL ? "after" : "before";
|
|
3993
|
+
else if (flow >= mid && isValidDropTarget({
|
|
3923
3994
|
...target,
|
|
3924
3995
|
dropPosition: "after"
|
|
3925
|
-
})) target.dropPosition = "after";
|
|
3996
|
+
})) target.dropPosition = isFlowRTL ? "before" : "after";
|
|
3926
3997
|
}
|
|
3927
3998
|
return target;
|
|
3928
3999
|
}
|
|
@@ -3930,20 +4001,23 @@ class $2268795bbb597ecb$export$fbd65d14c79e28cc {
|
|
|
3930
4001
|
let item = items[Math.min(low, items.length - 1)];
|
|
3931
4002
|
let element = elementMap.get(String(item.key));
|
|
3932
4003
|
rect = element.getBoundingClientRect();
|
|
3933
|
-
if (Math.abs(
|
|
4004
|
+
if (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect))) return {
|
|
3934
4005
|
type: "item",
|
|
3935
4006
|
key: item.key,
|
|
3936
|
-
dropPosition: "before"
|
|
4007
|
+
dropPosition: isFlowRTL ? "after" : "before"
|
|
3937
4008
|
};
|
|
3938
4009
|
return {
|
|
3939
4010
|
type: "item",
|
|
3940
4011
|
key: item.key,
|
|
3941
|
-
dropPosition: "after"
|
|
4012
|
+
dropPosition: isFlowRTL ? "before" : "after"
|
|
3942
4013
|
};
|
|
3943
4014
|
}
|
|
3944
|
-
constructor(collection, ref){
|
|
4015
|
+
constructor(collection, ref, options){
|
|
3945
4016
|
this.collection = collection;
|
|
3946
4017
|
this.ref = ref;
|
|
4018
|
+
this.layout = (options === null || options === void 0 ? void 0 : options.layout) || "stack";
|
|
4019
|
+
this.orientation = (options === null || options === void 0 ? void 0 : options.orientation) || "vertical";
|
|
4020
|
+
this.direction = (options === null || options === void 0 ? void 0 : options.direction) || "ltr";
|
|
3947
4021
|
}
|
|
3948
4022
|
}
|
|
3949
4023
|
|