@cloudscape-design/board-components 3.0.2 → 3.0.4
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/board/interfaces.d.ts +2 -2
- package/board/internal.js +7 -7
- package/board/transition.d.ts +3 -2
- package/board/transition.js +20 -7
- package/board-item/styles.css.js +10 -10
- package/board-item/styles.scoped.css +13 -13
- package/board-item/styles.selectors.js +10 -10
- package/internal/dnd-controller/controller.d.ts +4 -5
- package/internal/dnd-controller/controller.js +13 -15
- package/internal/dnd-controller/get-hovered-droppables.d.ts +6 -0
- package/internal/dnd-controller/get-hovered-droppables.js +10 -0
- package/internal/drag-handle/icon.js +2 -2
- package/internal/environment.js +1 -1
- package/internal/item-container/get-collision-rect.d.ts +10 -0
- package/internal/item-container/get-collision-rect.js +23 -0
- package/internal/item-container/index.js +8 -1
- package/internal/manifest.json +1 -1
- package/internal/resize-handle/icon.js +1 -1
- package/package.json +1 -1
- package/internal/dnd-controller/collision.d.ts +0 -17
- package/internal/dnd-controller/collision.js +0 -32
package/board/interfaces.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { InteractionType, Operation } from "../internal/dnd-controller/controller";
|
|
3
|
-
import { BoardItemDefinition, BoardItemDefinitionBase, DataFallbackType, Direction, GridLayout, GridLayoutItem, ItemId } from "../internal/interfaces";
|
|
3
|
+
import { BoardItemDefinition, BoardItemDefinitionBase, DataFallbackType, Direction, GridLayout, GridLayoutItem, ItemId, Rect } from "../internal/interfaces";
|
|
4
4
|
import { LayoutShift } from "../internal/layout-engine/interfaces";
|
|
5
5
|
import { NonCancelableEventHandler } from "../internal/utils/events";
|
|
6
6
|
import { Position } from "../internal/utils/position";
|
|
@@ -124,7 +124,7 @@ export interface Transition<D> {
|
|
|
124
124
|
itemsLayout: GridLayout;
|
|
125
125
|
insertionDirection: null | Direction;
|
|
126
126
|
draggableItem: BoardItemDefinitionBase<D>;
|
|
127
|
-
|
|
127
|
+
draggableRect: Rect;
|
|
128
128
|
acquiredItem: null | BoardItemDefinitionBase<D>;
|
|
129
129
|
collisionIds: Set<ItemId>;
|
|
130
130
|
layoutShift: null | LayoutShift;
|
package/board/internal.js
CHANGED
|
@@ -71,16 +71,15 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
|
|
|
71
71
|
}, [removeTransition, items]);
|
|
72
72
|
const rows = selectTransitionRows(transitionState) || itemsLayout.rows;
|
|
73
73
|
const placeholdersLayout = createPlaceholdersLayout(rows, columns);
|
|
74
|
-
function isElementOverBoard(
|
|
74
|
+
function isElementOverBoard(rect) {
|
|
75
75
|
const board = containerAccessRef.current;
|
|
76
76
|
const boardContains = (target) => board === target || board.contains(target);
|
|
77
|
-
const rect = draggableElement.getBoundingClientRect();
|
|
78
77
|
return (boardContains(document.elementFromPoint(rect.left, rect.top)) ||
|
|
79
78
|
boardContains(document.elementFromPoint(rect.right, rect.top)) ||
|
|
80
79
|
boardContains(document.elementFromPoint(rect.right, rect.bottom)) ||
|
|
81
80
|
boardContains(document.elementFromPoint(rect.left, rect.bottom)));
|
|
82
81
|
}
|
|
83
|
-
useDragSubscription("start", ({ operation, interactionType, draggableItem,
|
|
82
|
+
useDragSubscription("start", ({ operation, interactionType, draggableItem, collisionRect, collisionIds }) => {
|
|
84
83
|
dispatch({
|
|
85
84
|
type: "init",
|
|
86
85
|
operation,
|
|
@@ -90,16 +89,17 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
|
|
|
90
89
|
// The code only works assuming the board can take any draggable.
|
|
91
90
|
// If draggables can be of different types a check of some sort is required here.
|
|
92
91
|
draggableItem: draggableItem,
|
|
93
|
-
|
|
94
|
-
collisionIds: interactionType === "keyboard" || isElementOverBoard(
|
|
92
|
+
draggableRect: collisionRect,
|
|
93
|
+
collisionIds: interactionType === "keyboard" || isElementOverBoard(collisionRect) ? collisionIds : [],
|
|
95
94
|
});
|
|
96
95
|
autoScrollHandlers.addPointerEventHandlers();
|
|
97
96
|
});
|
|
98
|
-
useDragSubscription("update", ({ interactionType, collisionIds, positionOffset,
|
|
97
|
+
useDragSubscription("update", ({ interactionType, collisionIds, positionOffset, collisionRect }) => {
|
|
99
98
|
dispatch({
|
|
100
99
|
type: "update-with-pointer",
|
|
101
|
-
collisionIds: interactionType === "keyboard" || isElementOverBoard(
|
|
100
|
+
collisionIds: interactionType === "keyboard" || isElementOverBoard(collisionRect) ? collisionIds : [],
|
|
102
101
|
positionOffset,
|
|
102
|
+
draggableRect: collisionRect,
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
105
|
useDragSubscription("submit", () => {
|
package/board/transition.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dispatch } from "react";
|
|
2
2
|
import { InteractionType, Operation } from "../internal/dnd-controller/controller";
|
|
3
|
-
import { BoardItemDefinitionBase, Direction, GridLayout, ItemId } from "../internal/interfaces";
|
|
3
|
+
import { BoardItemDefinitionBase, Direction, GridLayout, ItemId, Rect } from "../internal/interfaces";
|
|
4
4
|
import { Coordinates } from "../internal/utils/coordinates";
|
|
5
5
|
import { Position } from "../internal/utils/position";
|
|
6
6
|
import { BoardProps, RemoveTransition, Transition, TransitionAnnouncement } from "./interfaces";
|
|
@@ -16,7 +16,7 @@ interface InitAction<D> {
|
|
|
16
16
|
interactionType: InteractionType;
|
|
17
17
|
itemsLayout: GridLayout;
|
|
18
18
|
draggableItem: BoardItemDefinitionBase<D>;
|
|
19
|
-
|
|
19
|
+
draggableRect: Rect;
|
|
20
20
|
collisionIds: readonly ItemId[];
|
|
21
21
|
}
|
|
22
22
|
interface InitRemoveAction<D> {
|
|
@@ -35,6 +35,7 @@ interface UpdateWithPointerAction {
|
|
|
35
35
|
type: "update-with-pointer";
|
|
36
36
|
collisionIds: readonly ItemId[];
|
|
37
37
|
positionOffset: Coordinates;
|
|
38
|
+
draggableRect: Rect;
|
|
38
39
|
}
|
|
39
40
|
interface UpdateWithKeyboardAction {
|
|
40
41
|
type: "update-with-keyboard";
|
package/board/transition.js
CHANGED
|
@@ -33,14 +33,14 @@ function transitionReducer(state, action) {
|
|
|
33
33
|
return acquireTransitionItem(state, action);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
function initTransition({ operation, interactionType, itemsLayout, draggableItem,
|
|
36
|
+
function initTransition({ operation, interactionType, itemsLayout, draggableItem, draggableRect, collisionIds, }) {
|
|
37
37
|
const transition = {
|
|
38
38
|
operation,
|
|
39
39
|
interactionType,
|
|
40
40
|
itemsLayout,
|
|
41
41
|
insertionDirection: null,
|
|
42
42
|
draggableItem,
|
|
43
|
-
|
|
43
|
+
draggableRect,
|
|
44
44
|
acquiredItem: null,
|
|
45
45
|
collisionIds: new Set(),
|
|
46
46
|
layoutShift: null,
|
|
@@ -107,7 +107,7 @@ function discardTransition(state) {
|
|
|
107
107
|
announcement: itemBelongsToBoard ? { type: "dnd-discarded", item, operation } : null,
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
-
function updateTransitionWithPointerEvent(state, { collisionIds, positionOffset }) {
|
|
110
|
+
function updateTransitionWithPointerEvent(state, { collisionIds, positionOffset, draggableRect }) {
|
|
111
111
|
var _a, _b, _c;
|
|
112
112
|
const { transition } = state;
|
|
113
113
|
if (!transition) {
|
|
@@ -121,7 +121,13 @@ function updateTransitionWithPointerEvent(state, { collisionIds, positionOffset
|
|
|
121
121
|
const isOutOfBoundaries = transition.operation !== "resize" ? collisionIds.length < itemSize : collisionIds.length === 0;
|
|
122
122
|
if (isOutOfBoundaries) {
|
|
123
123
|
return {
|
|
124
|
-
transition: {
|
|
124
|
+
transition: {
|
|
125
|
+
...transition,
|
|
126
|
+
draggableRect,
|
|
127
|
+
collisionIds: new Set(),
|
|
128
|
+
layoutShift: null,
|
|
129
|
+
insertionDirection: null,
|
|
130
|
+
},
|
|
125
131
|
removeTransition: null,
|
|
126
132
|
announcement: null,
|
|
127
133
|
};
|
|
@@ -133,7 +139,14 @@ function updateTransitionWithPointerEvent(state, { collisionIds, positionOffset
|
|
|
133
139
|
const insertionDirection = (_c = transition.insertionDirection) !== null && _c !== void 0 ? _c : getInsertionDirection(positionOffset);
|
|
134
140
|
const layoutShift = getLayoutShift(transition, path, insertionDirection);
|
|
135
141
|
return {
|
|
136
|
-
transition: {
|
|
142
|
+
transition: {
|
|
143
|
+
...transition,
|
|
144
|
+
draggableRect,
|
|
145
|
+
collisionIds: new Set(collisionIds),
|
|
146
|
+
layoutShift,
|
|
147
|
+
path,
|
|
148
|
+
insertionDirection,
|
|
149
|
+
},
|
|
137
150
|
removeTransition: null,
|
|
138
151
|
announcement: null,
|
|
139
152
|
};
|
|
@@ -192,8 +205,8 @@ function acquireTransitionItem(state, { position, layoutElement }) {
|
|
|
192
205
|
}
|
|
193
206
|
const { columns } = transition.itemsLayout;
|
|
194
207
|
const layoutRect = layoutElement.getBoundingClientRect();
|
|
195
|
-
const itemRect = transition.
|
|
196
|
-
const offset = new Coordinates({ x: itemRect.
|
|
208
|
+
const itemRect = transition.draggableRect;
|
|
209
|
+
const offset = new Coordinates({ x: itemRect.left - layoutRect.x, y: itemRect.top - layoutRect.y });
|
|
197
210
|
const insertionDirection = getInsertionDirection(offset);
|
|
198
211
|
// Update original insertion position if the item can't fit into the layout by width.
|
|
199
212
|
const width = getDefaultColumnSpan(transition.draggableItem, columns);
|
package/board-item/styles.css.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
|
|
2
2
|
import './styles.scoped.css';
|
|
3
3
|
export default {
|
|
4
|
-
"root": "
|
|
5
|
-
"container-override": "awsui_container-
|
|
6
|
-
"active": "
|
|
7
|
-
"header": "
|
|
8
|
-
"flexible": "
|
|
9
|
-
"handle": "
|
|
10
|
-
"header-content": "awsui_header-
|
|
11
|
-
"settings": "
|
|
12
|
-
"fixed": "
|
|
13
|
-
"resizer": "
|
|
4
|
+
"root": "awsui_root_9ckv7_1wk39_1",
|
|
5
|
+
"container-override": "awsui_container-override_9ckv7_1wk39_6",
|
|
6
|
+
"active": "awsui_active_9ckv7_1wk39_6",
|
|
7
|
+
"header": "awsui_header_9ckv7_1wk39_10",
|
|
8
|
+
"flexible": "awsui_flexible_9ckv7_1wk39_16",
|
|
9
|
+
"handle": "awsui_handle_9ckv7_1wk39_20",
|
|
10
|
+
"header-content": "awsui_header-content_9ckv7_1wk39_24",
|
|
11
|
+
"settings": "awsui_settings_9ckv7_1wk39_28",
|
|
12
|
+
"fixed": "awsui_fixed_9ckv7_1wk39_33",
|
|
13
|
+
"resizer": "awsui_resizer_9ckv7_1wk39_37"
|
|
14
14
|
};
|
|
15
15
|
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
.
|
|
1
|
+
.awsui_root_9ckv7_1wk39_1:not(#\9) {
|
|
2
2
|
display: contents;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
/* TODO: use container API instead of styles override */
|
|
6
|
-
.awsui_container-
|
|
6
|
+
.awsui_container-override_9ckv7_1wk39_6.awsui_active_9ckv7_1wk39_6:not(#\9) {
|
|
7
7
|
box-shadow: var(--shadow-container-active-h4jsj2, 0px 4px 8px rgba(0, 28, 36, 0.45));
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
.
|
|
10
|
+
.awsui_header_9ckv7_1wk39_10:not(#\9) {
|
|
11
11
|
display: flex;
|
|
12
12
|
justify-items: center;
|
|
13
13
|
padding: var(--space-scaled-s-cu1hzn, 12px) calc(var(--space-container-horizontal-tlw03i, 20px) - var(--space-scaled-xs-6859qs, 8px));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
.
|
|
16
|
+
.awsui_flexible_9ckv7_1wk39_16:not(#\9) {
|
|
17
17
|
flex: 1 1 min-content;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
.
|
|
21
|
-
margin-top: var(--space-scaled-xxs-95dhkm, 4px);
|
|
20
|
+
.awsui_handle_9ckv7_1wk39_20:not(#\9) {
|
|
21
|
+
margin-top: calc(var(--space-scaled-xxs-95dhkm, 4px) + 1px);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
.awsui_header-
|
|
24
|
+
.awsui_header-content_9ckv7_1wk39_24:not(#\9) {
|
|
25
25
|
margin-left: var(--space-scaled-xxs-95dhkm, 4px);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
.
|
|
29
|
-
margin-top: var(--space-scaled-xxxs-b6dm8t, 2px);
|
|
28
|
+
.awsui_settings_9ckv7_1wk39_28:not(#\9) {
|
|
29
|
+
margin-top: calc(var(--space-scaled-xxxs-b6dm8t, 2px) + 1px);
|
|
30
30
|
margin-left: var(--space-static-xs-9adq92, 8px);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
.
|
|
33
|
+
.awsui_fixed_9ckv7_1wk39_33:not(#\9) {
|
|
34
34
|
flex: 0 0 auto;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
.
|
|
37
|
+
.awsui_resizer_9ckv7_1wk39_37:not(#\9) {
|
|
38
38
|
position: absolute;
|
|
39
|
-
bottom: calc(var(--space-
|
|
40
|
-
right: calc(var(--space-
|
|
39
|
+
bottom: calc(var(--space-static-xs-9adq92, 8px) - var(--space-static-xxxs-k3qmdh, 2px));
|
|
40
|
+
right: calc(var(--space-static-xs-9adq92, 8px) - var(--space-static-xxxs-k3qmdh, 2px));
|
|
41
41
|
}
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// es-module interop with Babel and Typescript
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
module.exports.default = {
|
|
5
|
-
"root": "
|
|
6
|
-
"container-override": "awsui_container-
|
|
7
|
-
"active": "
|
|
8
|
-
"header": "
|
|
9
|
-
"flexible": "
|
|
10
|
-
"handle": "
|
|
11
|
-
"header-content": "awsui_header-
|
|
12
|
-
"settings": "
|
|
13
|
-
"fixed": "
|
|
14
|
-
"resizer": "
|
|
5
|
+
"root": "awsui_root_9ckv7_1wk39_1",
|
|
6
|
+
"container-override": "awsui_container-override_9ckv7_1wk39_6",
|
|
7
|
+
"active": "awsui_active_9ckv7_1wk39_6",
|
|
8
|
+
"header": "awsui_header_9ckv7_1wk39_10",
|
|
9
|
+
"flexible": "awsui_flexible_9ckv7_1wk39_16",
|
|
10
|
+
"handle": "awsui_handle_9ckv7_1wk39_20",
|
|
11
|
+
"header-content": "awsui_header-content_9ckv7_1wk39_24",
|
|
12
|
+
"settings": "awsui_settings_9ckv7_1wk39_28",
|
|
13
|
+
"fixed": "awsui_fixed_9ckv7_1wk39_33",
|
|
14
|
+
"resizer": "awsui_resizer_9ckv7_1wk39_37"
|
|
15
15
|
};
|
|
16
16
|
|
|
@@ -22,10 +22,9 @@ export interface DragAndDropData {
|
|
|
22
22
|
operation: Operation;
|
|
23
23
|
interactionType: InteractionType;
|
|
24
24
|
draggableItem: Item;
|
|
25
|
-
|
|
25
|
+
collisionRect: Rect;
|
|
26
26
|
positionOffset: Coordinates;
|
|
27
27
|
coordinates: Coordinates;
|
|
28
|
-
collisionRect: Rect;
|
|
29
28
|
collisionIds: ItemId[];
|
|
30
29
|
dropTarget: null | DropTargetContext;
|
|
31
30
|
}
|
|
@@ -45,9 +44,9 @@ export interface DragAndDropEvents {
|
|
|
45
44
|
acquire: (data: AcquireData) => void;
|
|
46
45
|
}
|
|
47
46
|
export declare function useDragSubscription<K extends keyof DragAndDropEvents>(event: K, handler: DragAndDropEvents[K]): void;
|
|
48
|
-
export declare function useDraggable({
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
export declare function useDraggable({ draggableItem, getCollisionRect, }: {
|
|
48
|
+
draggableItem: Item;
|
|
49
|
+
getCollisionRect: (operation: Operation, coordinates: Coordinates, dropTarget: null | DropTargetContext) => Rect;
|
|
51
50
|
}): {
|
|
52
51
|
start(operation: Operation, interactionType: InteractionType, startCoordinates: Coordinates): void;
|
|
53
52
|
updateTransition(coordinates: Coordinates): void;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { useEffect } from "react";
|
|
4
4
|
import { Coordinates } from "../utils/coordinates";
|
|
5
|
-
import { getCollisionRect, getHoveredDroppables } from "./collision";
|
|
6
5
|
import { EventEmitter } from "./event-emitter";
|
|
6
|
+
import { getHoveredDroppables } from "./get-hovered-droppables";
|
|
7
7
|
class DragAndDropController extends EventEmitter {
|
|
8
8
|
constructor() {
|
|
9
9
|
super(...arguments);
|
|
@@ -15,15 +15,9 @@ class DragAndDropController extends EventEmitter {
|
|
|
15
15
|
*
|
|
16
16
|
* The method overrides the previous transition if exists (w/o a cancellation event)!
|
|
17
17
|
*/
|
|
18
|
-
start(
|
|
19
|
-
this.transition = {
|
|
20
|
-
|
|
21
|
-
interactionType,
|
|
22
|
-
draggableItem,
|
|
23
|
-
draggableElement,
|
|
24
|
-
startCoordinates,
|
|
25
|
-
};
|
|
26
|
-
this.emit("start", this.getDragAndDropData(startCoordinates));
|
|
18
|
+
start(transition) {
|
|
19
|
+
this.transition = { ...transition };
|
|
20
|
+
this.emit("start", this.getDragAndDropData(transition.startCoordinates));
|
|
27
21
|
}
|
|
28
22
|
/**
|
|
29
23
|
* Updates current transition with given coordinates and issues an "update" event.
|
|
@@ -76,12 +70,16 @@ class DragAndDropController extends EventEmitter {
|
|
|
76
70
|
if (!this.transition) {
|
|
77
71
|
throw new Error("Invariant violation: no transition present for interaction.");
|
|
78
72
|
}
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const collisionRect = getCollisionRect(operation, draggableElement, coordinates);
|
|
73
|
+
const positionOffset = Coordinates.cursorOffset(coordinates, this.transition.startCoordinates);
|
|
74
|
+
const collisionRect = this.getCollisionRect(this.transition, coordinates);
|
|
82
75
|
const { collisionIds, dropTarget } = this.getCollisions(collisionRect);
|
|
83
76
|
return { ...this.transition, positionOffset, coordinates, collisionRect, collisionIds, dropTarget };
|
|
84
77
|
}
|
|
78
|
+
getCollisionRect(transition, coordinates) {
|
|
79
|
+
const originalCollisionRect = transition.getCollisionRect(transition.operation, coordinates, null);
|
|
80
|
+
const { dropTarget } = this.getCollisions(originalCollisionRect);
|
|
81
|
+
return transition.getCollisionRect(transition.operation, coordinates, dropTarget);
|
|
82
|
+
}
|
|
85
83
|
getCollisions(collisionRect) {
|
|
86
84
|
const droppableEntries = [...this.droppables.entries()];
|
|
87
85
|
const droppableElements = droppableEntries.map(([id, entry]) => [id, entry.element]);
|
|
@@ -101,10 +99,10 @@ const controller = new DragAndDropController();
|
|
|
101
99
|
export function useDragSubscription(event, handler) {
|
|
102
100
|
useEffect(() => controller.on(event, handler), [event, handler]);
|
|
103
101
|
}
|
|
104
|
-
export function useDraggable({
|
|
102
|
+
export function useDraggable({ draggableItem, getCollisionRect, }) {
|
|
105
103
|
return {
|
|
106
104
|
start(operation, interactionType, startCoordinates) {
|
|
107
|
-
controller.start(operation, interactionType,
|
|
105
|
+
controller.start({ operation, interactionType, draggableItem, getCollisionRect, startCoordinates });
|
|
108
106
|
},
|
|
109
107
|
updateTransition(coordinates) {
|
|
110
108
|
controller.update(coordinates);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ItemId } from "../interfaces";
|
|
2
|
+
import { Rect } from "../interfaces";
|
|
3
|
+
/**
|
|
4
|
+
* Returns IDs of droppables hovered by the draggable rect.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getHoveredDroppables(collisionRect: Rect, droppables: readonly [ItemId, HTMLElement][]): string[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getGridPlacement, isInside } from "../utils/rects";
|
|
2
|
+
import { getNormalizedElementRect } from "../utils/screen";
|
|
3
|
+
/**
|
|
4
|
+
* Returns IDs of droppables hovered by the draggable rect.
|
|
5
|
+
*/
|
|
6
|
+
export function getHoveredDroppables(collisionRect, droppables) {
|
|
7
|
+
const droppableRects = droppables.map(([, element]) => getNormalizedElementRect(element));
|
|
8
|
+
const bounds = getGridPlacement(collisionRect, droppableRects);
|
|
9
|
+
return droppables.filter((_, index) => isInside(droppableRects[index], bounds)).map(([droppableId]) => droppableId);
|
|
10
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import Icon from "@cloudscape-design/components/icon";
|
|
@@ -7,6 +7,6 @@ function DragHandleIcon() {
|
|
|
7
7
|
return _jsx(Icon, { svg: _jsx(SVG, {}) });
|
|
8
8
|
}
|
|
9
9
|
function SVG() {
|
|
10
|
-
return (
|
|
10
|
+
return (_jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("circle", { cx: "5.5", cy: "2.5", r: "0.5", className: "filled", strokeWidth: "2" }), _jsx("circle", { cx: "5.5", cy: "13.5", r: "0.5", className: "filled", strokeWidth: "2" }), _jsx("circle", { cx: "5.5", cy: "8", r: "0.5", className: "filled", strokeWidth: "2" }), _jsx("circle", { cx: "10.5", cy: "2.5", r: "0.5", className: "filled", strokeWidth: "2" }), _jsx("circle", { cx: "10.5", cy: "13.5", r: "0.5", className: "filled", strokeWidth: "2" }), _jsx("circle", { cx: "10.5", cy: "8", r: "0.5", className: "filled", strokeWidth: "2" })] }));
|
|
11
11
|
}
|
|
12
12
|
export default memo(DragHandleIcon);
|
package/internal/environment.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Operation } from "../dnd-controller/controller";
|
|
2
|
+
import { Rect } from "../interfaces";
|
|
3
|
+
import { Coordinates } from "../utils/coordinates";
|
|
4
|
+
/**
|
|
5
|
+
* Produces a rect (in coordinates) to represent the draggable item.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getCollisionRect(operation: Operation, draggableElement: HTMLElement, coordinates: Coordinates, sizeOverride: null | {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}): Rect;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { getNormalizedElementRect } from "../utils/screen";
|
|
4
|
+
/**
|
|
5
|
+
* Produces a rect (in coordinates) to represent the draggable item.
|
|
6
|
+
*/
|
|
7
|
+
export function getCollisionRect(operation, draggableElement, coordinates, sizeOverride) {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const { left, top, width, height } = getNormalizedElementRect(draggableElement);
|
|
10
|
+
switch (operation) {
|
|
11
|
+
case "reorder":
|
|
12
|
+
return { left: coordinates.x, right: coordinates.x + width, top: coordinates.y, bottom: coordinates.y + height };
|
|
13
|
+
case "resize":
|
|
14
|
+
return { left: left, top: top, right: coordinates.x, bottom: coordinates.y };
|
|
15
|
+
case "insert":
|
|
16
|
+
return {
|
|
17
|
+
left: coordinates.x,
|
|
18
|
+
top: coordinates.y,
|
|
19
|
+
right: coordinates.x + ((_a = sizeOverride === null || sizeOverride === void 0 ? void 0 : sizeOverride.width) !== null && _a !== void 0 ? _a : width),
|
|
20
|
+
bottom: coordinates.y + ((_b = sizeOverride === null || sizeOverride === void 0 ? void 0 : sizeOverride.height) !== null && _b !== void 0 ? _b : height),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -9,6 +9,7 @@ import { Coordinates } from "../utils/coordinates";
|
|
|
9
9
|
import { getNormalizedElementRect } from "../utils/screen";
|
|
10
10
|
import { useStableEventHandler } from "../utils/use-stable-event-handler";
|
|
11
11
|
import { useThrottledEventHandler } from "../utils/use-throttled-event-handler";
|
|
12
|
+
import { getCollisionRect } from "./get-collision-rect";
|
|
12
13
|
import { getNextDroppable } from "./get-next-droppable";
|
|
13
14
|
import styles from "./styles.css.js";
|
|
14
15
|
const Context = createContext(null);
|
|
@@ -27,7 +28,13 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
27
28
|
const pointerBoundariesRef = useRef(null);
|
|
28
29
|
const [transition, setTransition] = useState(null);
|
|
29
30
|
const itemRef = useRef(null);
|
|
30
|
-
const draggableApi = useDraggable({
|
|
31
|
+
const draggableApi = useDraggable({
|
|
32
|
+
draggableItem: item,
|
|
33
|
+
getCollisionRect: (operation, coordinates, dropTarget) => {
|
|
34
|
+
const sizeOverride = operation === "insert" && dropTarget ? getItemSize(dropTarget) : null;
|
|
35
|
+
return getCollisionRect(operation, itemRef.current, coordinates, sizeOverride);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
31
38
|
const onPointerMove = useThrottledEventHandler((event) => {
|
|
32
39
|
var _a, _b, _c, _d;
|
|
33
40
|
const coordinates = Coordinates.fromEvent(event);
|
package/internal/manifest.json
CHANGED
|
@@ -7,6 +7,6 @@ export function ResizeHandleIcon() {
|
|
|
7
7
|
return _jsx(Icon, { svg: _jsx(SVG, {}) });
|
|
8
8
|
}
|
|
9
9
|
function SVG() {
|
|
10
|
-
return (_jsxs("svg", {
|
|
10
|
+
return (_jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("path", { d: "M9.5 14.5L14.5 9.5", strokeWidth: "2" }), _jsx("path", { d: "M4 14.5L14.5 4", strokeWidth: "2" })] }));
|
|
11
11
|
}
|
|
12
12
|
export default memo(ResizeHandleIcon);
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ItemId } from "../../internal/interfaces";
|
|
2
|
-
import { Rect } from "../../internal/interfaces";
|
|
3
|
-
import { Coordinates } from "../utils/coordinates";
|
|
4
|
-
import { Operation } from "./controller";
|
|
5
|
-
/**
|
|
6
|
-
* Produces a rect (in coordinates) to represent the draggable item.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getCollisionRect(operation: Operation, draggableElement: HTMLElement, coordinates: Coordinates): {
|
|
9
|
-
left: number;
|
|
10
|
-
top: number;
|
|
11
|
-
right: number;
|
|
12
|
-
bottom: number;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Returns IDs of droppables hovered by the draggable rect.
|
|
16
|
-
*/
|
|
17
|
-
export declare function getHoveredDroppables(collisionRect: Rect, droppables: readonly [ItemId, HTMLElement][]): string[];
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { getGridPlacement, isInside } from "../utils/rects";
|
|
2
|
-
import { getNormalizedElementRect } from "../utils/screen";
|
|
3
|
-
/**
|
|
4
|
-
* Produces a rect (in coordinates) to represent the draggable item.
|
|
5
|
-
*/
|
|
6
|
-
export function getCollisionRect(operation, draggableElement, coordinates) {
|
|
7
|
-
const activeRect = getNormalizedElementRect(draggableElement);
|
|
8
|
-
let collisionRect = { left: 0, top: 0, right: 0, bottom: 0 };
|
|
9
|
-
if (operation === "reorder") {
|
|
10
|
-
collisionRect = activeRect;
|
|
11
|
-
}
|
|
12
|
-
if (operation === "resize") {
|
|
13
|
-
collisionRect = { left: activeRect.left, top: activeRect.top, right: coordinates.x, bottom: coordinates.y };
|
|
14
|
-
}
|
|
15
|
-
if (operation === "insert") {
|
|
16
|
-
collisionRect = {
|
|
17
|
-
left: coordinates.x,
|
|
18
|
-
top: coordinates.y,
|
|
19
|
-
right: coordinates.x + activeRect.width,
|
|
20
|
-
bottom: coordinates.y + activeRect.height,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return collisionRect;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Returns IDs of droppables hovered by the draggable rect.
|
|
27
|
-
*/
|
|
28
|
-
export function getHoveredDroppables(collisionRect, droppables) {
|
|
29
|
-
const droppableRects = droppables.map(([, element]) => getNormalizedElementRect(element));
|
|
30
|
-
const bounds = getGridPlacement(collisionRect, droppableRects);
|
|
31
|
-
return droppables.filter((_, index) => isInside(droppableRects[index], bounds)).map(([droppableId]) => droppableId);
|
|
32
|
-
}
|