@cloudscape-design/board-components 3.0.28 → 3.0.30
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/utils/events.js +1 -1
- package/internal/dnd-controller/controller.js +3 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/item-container/index.js +31 -29
- package/internal/item-container/styles.css.js +7 -7
- package/internal/item-container/styles.scoped.css +7 -7
- package/internal/item-container/styles.selectors.js +7 -7
- package/internal/manifest.json +1 -1
- package/package.json +1 -1
package/board/utils/events.js
CHANGED
|
@@ -12,7 +12,7 @@ export function createItemsChangeEvent(items, layoutShift) {
|
|
|
12
12
|
return createCustomEvent({
|
|
13
13
|
items: newItems,
|
|
14
14
|
addedItem: newItems.find((it) => it.id === insertTarget),
|
|
15
|
-
removedItem:
|
|
15
|
+
removedItem: items.find((it) => it.id === removeTarget),
|
|
16
16
|
resizedItem: newItems.find((it) => it.id === resizeTarget),
|
|
17
17
|
movedItem: !insertTarget ? newItems.find((it) => it.id === moveTarget) : undefined,
|
|
18
18
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { useEffect } from "react";
|
|
4
4
|
import { Coordinates } from "../utils/coordinates";
|
|
5
|
+
import { useStableEventHandler } from "../utils/use-stable-event-handler";
|
|
5
6
|
import { EventEmitter } from "./event-emitter";
|
|
6
7
|
import { getHoveredDroppables } from "./get-hovered-droppables";
|
|
7
8
|
class DragAndDropController extends EventEmitter {
|
|
@@ -97,7 +98,8 @@ class DragAndDropController extends EventEmitter {
|
|
|
97
98
|
// Controller is a singleton and is shared between all d&d elements.
|
|
98
99
|
const controller = new DragAndDropController();
|
|
99
100
|
export function useDragSubscription(event, handler) {
|
|
100
|
-
|
|
101
|
+
const stableHandler = useStableEventHandler(handler);
|
|
102
|
+
useEffect(() => controller.on(event, stableHandler), [event, stableHandler]);
|
|
101
103
|
}
|
|
102
104
|
export function useDraggable({ draggableItem, getCollisionRect, }) {
|
|
103
105
|
return {
|
package/internal/environment.js
CHANGED
|
@@ -27,6 +27,8 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
27
27
|
const pointerOffsetRef = useRef(new Coordinates({ x: 0, y: 0 }));
|
|
28
28
|
const pointerBoundariesRef = useRef(null);
|
|
29
29
|
const [transition, setTransition] = useState(null);
|
|
30
|
+
const [isHidden, setIsHidden] = useState(false);
|
|
31
|
+
const muteEventsRef = useRef(false);
|
|
30
32
|
const itemRef = useRef(null);
|
|
31
33
|
const draggableApi = useDraggable({
|
|
32
34
|
draggableItem: item,
|
|
@@ -40,7 +42,7 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
40
42
|
const [width, height] = [collisionRect.right - collisionRect.left, collisionRect.bottom - collisionRect.top];
|
|
41
43
|
const pointerOffset = pointerOffsetRef.current;
|
|
42
44
|
if (operation === "resize") {
|
|
43
|
-
setTransition(
|
|
45
|
+
setTransition({
|
|
44
46
|
operation,
|
|
45
47
|
interactionType,
|
|
46
48
|
itemId: draggableItem.id,
|
|
@@ -49,29 +51,30 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
49
51
|
height: Math.max(getItemSize(null).minHeight, height - pointerOffset.y),
|
|
50
52
|
},
|
|
51
53
|
positionTransform: null,
|
|
52
|
-
|
|
53
|
-
}));
|
|
54
|
+
});
|
|
54
55
|
}
|
|
55
56
|
else if (operation === "insert" || operation === "reorder") {
|
|
56
|
-
setTransition(
|
|
57
|
+
setTransition({
|
|
57
58
|
operation,
|
|
58
59
|
interactionType,
|
|
59
60
|
itemId: draggableItem.id,
|
|
60
61
|
sizeTransform: dropTarget ? getItemSize(dropTarget) : originalSizeRef.current,
|
|
61
62
|
positionTransform: { x: coordinates.x - pointerOffset.x, y: coordinates.y - pointerOffset.y },
|
|
62
|
-
|
|
63
|
-
}));
|
|
63
|
+
});
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
useDragSubscription("start", (detail) => updateTransition(detail));
|
|
68
68
|
useDragSubscription("update", (detail) => updateTransition(detail));
|
|
69
|
-
useDragSubscription("submit", () =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
useDragSubscription("submit", () => {
|
|
70
|
+
setTransition(null);
|
|
71
|
+
setIsHidden(false);
|
|
72
|
+
muteEventsRef.current = false;
|
|
73
|
+
});
|
|
74
|
+
useDragSubscription("discard", () => {
|
|
75
|
+
setTransition(null);
|
|
76
|
+
setIsHidden(false);
|
|
77
|
+
muteEventsRef.current = false;
|
|
75
78
|
});
|
|
76
79
|
// During the transition listen to pointer move and pointer up events to update/submit transition.
|
|
77
80
|
const transitionInteractionType = (_a = transition === null || transition === void 0 ? void 0 : transition.interactionType) !== null && _a !== void 0 ? _a : null;
|
|
@@ -152,6 +155,8 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
152
155
|
}
|
|
153
156
|
// Notify the respective droppable of the intention to insert the item in it.
|
|
154
157
|
draggableApi.acquire(nextDroppable, childrenRef.current);
|
|
158
|
+
setIsHidden(true);
|
|
159
|
+
muteEventsRef.current = true;
|
|
155
160
|
}
|
|
156
161
|
function onHandleKeyDown(operation, event) {
|
|
157
162
|
const canInsert = transition && operation === "drag" && !placed;
|
|
@@ -187,10 +192,10 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
187
192
|
}
|
|
188
193
|
}
|
|
189
194
|
function onBlur() {
|
|
190
|
-
// When drag- or resize handle loses focus the transition must be submitted with two exceptions:
|
|
195
|
+
// When drag- or resize handle on palette or board item loses focus the transition must be submitted with two exceptions:
|
|
191
196
|
// 1. If the last interaction is not "keyboard" (the user clicked on another handle issuing a new transition);
|
|
192
|
-
// 2. If the item is
|
|
193
|
-
if (transition && transition.interactionType === "keyboard" && !
|
|
197
|
+
// 2. If the item is acquired by the board (in that case the focus moves to the board item which is expected, palette item is hidden and all events handlers must be muted).
|
|
198
|
+
if (transition && transition.interactionType === "keyboard" && !muteEventsRef.current) {
|
|
194
199
|
draggableApi.submitTransition();
|
|
195
200
|
}
|
|
196
201
|
}
|
|
@@ -227,20 +232,17 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
227
232
|
if (inTransition) {
|
|
228
233
|
itemTransitionClassNames.push(styles.inTransition);
|
|
229
234
|
}
|
|
230
|
-
if (transition) {
|
|
235
|
+
if (transition && transition.interactionType === "pointer") {
|
|
231
236
|
// Adjust the dragged/resized item to the pointer's location.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
else if (transition.isBorrowed) {
|
|
242
|
-
itemTransitionClassNames.push(styles.borrowed);
|
|
243
|
-
}
|
|
237
|
+
itemTransitionClassNames.push(transition.operation === "resize" ? styles.resized : styles.dragged);
|
|
238
|
+
itemTransitionStyle.left = (_c = transition.positionTransform) === null || _c === void 0 ? void 0 : _c.x;
|
|
239
|
+
itemTransitionStyle.top = (_d = transition.positionTransform) === null || _d === void 0 ? void 0 : _d.y;
|
|
240
|
+
itemTransitionStyle.width = (_e = transition.sizeTransform) === null || _e === void 0 ? void 0 : _e.width;
|
|
241
|
+
itemTransitionStyle.height = (_f = transition.sizeTransform) === null || _f === void 0 ? void 0 : _f.height;
|
|
242
|
+
itemTransitionStyle.pointerEvents = "none";
|
|
243
|
+
}
|
|
244
|
+
if (isHidden) {
|
|
245
|
+
itemTransitionClassNames.push(styles.hidden);
|
|
244
246
|
}
|
|
245
247
|
if (placed && transform) {
|
|
246
248
|
// The moved items positions are altered with CSS transform.
|
|
@@ -265,7 +267,7 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
265
267
|
useImperativeHandle(ref, () => ({
|
|
266
268
|
focusDragHandle: () => { var _a; return (_a = dragHandleRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
267
269
|
}));
|
|
268
|
-
const isActive = (!!transition && !
|
|
270
|
+
const isActive = (!!transition && !isHidden) || !!acquired;
|
|
269
271
|
const shouldUsePortal = ((transition === null || transition === void 0 ? void 0 : transition.operation) === "insert" || (transition === null || transition === void 0 ? void 0 : transition.operation) === "reorder") &&
|
|
270
272
|
(transition === null || transition === void 0 ? void 0 : transition.interactionType) === "pointer";
|
|
271
273
|
const childrenRef = useRef(null);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
import './styles.scoped.css';
|
|
3
3
|
export default {
|
|
4
|
-
"root": "
|
|
5
|
-
"inTransition": "
|
|
6
|
-
"transformed": "
|
|
7
|
-
"removed": "
|
|
8
|
-
"dragged": "
|
|
9
|
-
"resized": "
|
|
10
|
-
"
|
|
4
|
+
"root": "awsui_root_lljvd_1jk2l_1",
|
|
5
|
+
"inTransition": "awsui_inTransition_lljvd_1jk2l_7",
|
|
6
|
+
"transformed": "awsui_transformed_lljvd_1jk2l_12",
|
|
7
|
+
"removed": "awsui_removed_lljvd_1jk2l_17",
|
|
8
|
+
"dragged": "awsui_dragged_lljvd_1jk2l_21",
|
|
9
|
+
"resized": "awsui_resized_lljvd_1jk2l_26",
|
|
10
|
+
"hidden": "awsui_hidden_lljvd_1jk2l_31"
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
.
|
|
1
|
+
.awsui_root_lljvd_1jk2l_1:not(#\9) {
|
|
2
2
|
touch-action: none;
|
|
3
3
|
position: relative;
|
|
4
4
|
height: 100%;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
.
|
|
7
|
+
.awsui_inTransition_lljvd_1jk2l_7:not(#\9) {
|
|
8
8
|
transition: transform 200ms;
|
|
9
9
|
transition-timing-function: ease;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
.
|
|
12
|
+
.awsui_transformed_lljvd_1jk2l_12:not(#\9) {
|
|
13
13
|
position: absolute;
|
|
14
14
|
z-index: 1;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
.
|
|
17
|
+
.awsui_removed_lljvd_1jk2l_17:not(#\9) {
|
|
18
18
|
display: none;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
.
|
|
21
|
+
.awsui_dragged_lljvd_1jk2l_21:not(#\9) {
|
|
22
22
|
z-index: 2000;
|
|
23
23
|
position: fixed;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
.
|
|
26
|
+
.awsui_resized_lljvd_1jk2l_26:not(#\9) {
|
|
27
27
|
z-index: 2000;
|
|
28
28
|
position: absolute;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
.
|
|
31
|
+
.awsui_hidden_lljvd_1jk2l_31:not(#\9) {
|
|
32
32
|
display: none;
|
|
33
33
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
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
|
-
"inTransition": "
|
|
7
|
-
"transformed": "
|
|
8
|
-
"removed": "
|
|
9
|
-
"dragged": "
|
|
10
|
-
"resized": "
|
|
11
|
-
"
|
|
5
|
+
"root": "awsui_root_lljvd_1jk2l_1",
|
|
6
|
+
"inTransition": "awsui_inTransition_lljvd_1jk2l_7",
|
|
7
|
+
"transformed": "awsui_transformed_lljvd_1jk2l_12",
|
|
8
|
+
"removed": "awsui_removed_lljvd_1jk2l_17",
|
|
9
|
+
"dragged": "awsui_dragged_lljvd_1jk2l_21",
|
|
10
|
+
"resized": "awsui_resized_lljvd_1jk2l_26",
|
|
11
|
+
"hidden": "awsui_hidden_lljvd_1jk2l_31"
|
|
12
12
|
};
|
|
13
13
|
|
package/internal/manifest.json
CHANGED