@cloudscape-design/board-components 3.0.29 → 3.0.31
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/internal.js +3 -3
- package/board/utils/events.js +1 -1
- package/internal/dnd-controller/controller.d.ts +2 -2
- package/internal/dnd-controller/controller.js +7 -5
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/item-container/index.d.ts +1 -1
- package/internal/item-container/index.js +35 -32
- 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/items-palette/internal.js +4 -6
- package/package.json +1 -1
package/board/internal.js
CHANGED
|
@@ -132,7 +132,7 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
|
|
|
132
132
|
dispatch({ type: "discard" });
|
|
133
133
|
autoScrollHandlers.removePointerEventHandlers();
|
|
134
134
|
});
|
|
135
|
-
useDragSubscription("acquire", ({ droppableId, draggableItem,
|
|
135
|
+
useDragSubscription("acquire", ({ droppableId, draggableItem, renderAcquiredItem }) => {
|
|
136
136
|
const placeholder = placeholdersLayout.items.find((it) => it.id === droppableId);
|
|
137
137
|
// If missing then it does not belong to this board.
|
|
138
138
|
if (!placeholder) {
|
|
@@ -142,7 +142,7 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
|
|
|
142
142
|
type: "acquire-item",
|
|
143
143
|
position: new Position({ x: placeholder.x, y: placeholder.y }),
|
|
144
144
|
layoutElement: containerAccessRef.current,
|
|
145
|
-
acquiredItemElement:
|
|
145
|
+
acquiredItemElement: renderAcquiredItem(),
|
|
146
146
|
});
|
|
147
147
|
focusNextRenderIdRef.current = draggableItem.id;
|
|
148
148
|
});
|
|
@@ -192,7 +192,7 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
|
|
|
192
192
|
else {
|
|
193
193
|
delete itemContainerRef.current[item.id];
|
|
194
194
|
}
|
|
195
|
-
}, item: item, transform: transforms[item.id], inTransition: !!transition || !!removeTransition, placed:
|
|
195
|
+
}, item: item, transform: transforms[item.id], inTransition: !!transition || !!removeTransition, placed: item.id !== (acquiredItem === null || acquiredItem === void 0 ? void 0 : acquiredItem.id), acquired: item.id === (acquiredItem === null || acquiredItem === void 0 ? void 0 : acquiredItem.id), getItemSize: () => ({
|
|
196
196
|
width: gridContext.getWidth(itemSize.width),
|
|
197
197
|
minWidth: gridContext.getWidth(getMinColumnSpan(item, itemsLayout.columns)),
|
|
198
198
|
maxWidth: gridContext.getWidth(itemMaxSize.width),
|
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
|
});
|
|
@@ -36,7 +36,7 @@ export interface Droppable {
|
|
|
36
36
|
interface AcquireData {
|
|
37
37
|
droppableId: ItemId;
|
|
38
38
|
draggableItem: Item;
|
|
39
|
-
|
|
39
|
+
renderAcquiredItem: () => ReactNode;
|
|
40
40
|
}
|
|
41
41
|
export interface DragAndDropEvents {
|
|
42
42
|
start: (data: DragAndDropData) => void;
|
|
@@ -54,7 +54,7 @@ export declare function useDraggable({ draggableItem, getCollisionRect, }: {
|
|
|
54
54
|
updateTransition(coordinates: Coordinates): void;
|
|
55
55
|
submitTransition(): void;
|
|
56
56
|
discardTransition(): void;
|
|
57
|
-
acquire(droppableId: ItemId,
|
|
57
|
+
acquire(droppableId: ItemId, renderAcquiredItem: () => ReactNode): void;
|
|
58
58
|
getDroppables(): [string, Droppable][];
|
|
59
59
|
};
|
|
60
60
|
export declare function useDroppable({ itemId, context, getElement, }: {
|
|
@@ -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 {
|
|
@@ -42,11 +43,11 @@ class DragAndDropController extends EventEmitter {
|
|
|
42
43
|
/**
|
|
43
44
|
* Issues an "acquire" event to notify the current transition draggable is acquired by the given droppable.
|
|
44
45
|
*/
|
|
45
|
-
acquire(droppableId,
|
|
46
|
+
acquire(droppableId, renderAcquiredItem) {
|
|
46
47
|
if (!this.transition) {
|
|
47
48
|
throw new Error("Invariant violation: no transition present for acquire.");
|
|
48
49
|
}
|
|
49
|
-
this.emit("acquire", { droppableId, draggableItem: this.transition.draggableItem,
|
|
50
|
+
this.emit("acquire", { droppableId, draggableItem: this.transition.draggableItem, renderAcquiredItem });
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
52
53
|
* Registers a droppable used for collisions check, acquire, and dropTarget provision.
|
|
@@ -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 {
|
|
@@ -113,8 +115,8 @@ export function useDraggable({ draggableItem, getCollisionRect, }) {
|
|
|
113
115
|
discardTransition() {
|
|
114
116
|
controller.discard();
|
|
115
117
|
},
|
|
116
|
-
acquire(droppableId,
|
|
117
|
-
controller.acquire(droppableId,
|
|
118
|
+
acquire(droppableId, renderAcquiredItem) {
|
|
119
|
+
controller.acquire(droppableId, renderAcquiredItem);
|
|
118
120
|
},
|
|
119
121
|
getDroppables() {
|
|
120
122
|
return controller.getDroppables();
|
package/internal/environment.js
CHANGED
|
@@ -46,7 +46,7 @@ export interface ItemContainerProps {
|
|
|
46
46
|
maxHeight: number;
|
|
47
47
|
};
|
|
48
48
|
onKeyMove?(direction: Direction): void;
|
|
49
|
-
children: () => ReactNode;
|
|
49
|
+
children: (hasDropTarget: boolean) => ReactNode;
|
|
50
50
|
}
|
|
51
51
|
export declare const ItemContainer: import("react").ForwardRefExoticComponent<ItemContainerProps & import("react").RefAttributes<ItemContainerRef>>;
|
|
52
52
|
export {};
|
|
@@ -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,31 @@ 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
|
+
hasDropTarget: !!dropTarget,
|
|
64
|
+
});
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
useDragSubscription("start", (detail) => updateTransition(detail));
|
|
68
69
|
useDragSubscription("update", (detail) => updateTransition(detail));
|
|
69
|
-
useDragSubscription("submit", () =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
useDragSubscription("submit", () => {
|
|
71
|
+
setTransition(null);
|
|
72
|
+
setIsHidden(false);
|
|
73
|
+
muteEventsRef.current = false;
|
|
74
|
+
});
|
|
75
|
+
useDragSubscription("discard", () => {
|
|
76
|
+
setTransition(null);
|
|
77
|
+
setIsHidden(false);
|
|
78
|
+
muteEventsRef.current = false;
|
|
75
79
|
});
|
|
76
80
|
// During the transition listen to pointer move and pointer up events to update/submit transition.
|
|
77
81
|
const transitionInteractionType = (_a = transition === null || transition === void 0 ? void 0 : transition.interactionType) !== null && _a !== void 0 ? _a : null;
|
|
@@ -151,7 +155,9 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
151
155
|
return;
|
|
152
156
|
}
|
|
153
157
|
// Notify the respective droppable of the intention to insert the item in it.
|
|
154
|
-
draggableApi.acquire(nextDroppable,
|
|
158
|
+
draggableApi.acquire(nextDroppable, () => children(true));
|
|
159
|
+
setIsHidden(true);
|
|
160
|
+
muteEventsRef.current = true;
|
|
155
161
|
}
|
|
156
162
|
function onHandleKeyDown(operation, event) {
|
|
157
163
|
const canInsert = transition && operation === "drag" && !placed;
|
|
@@ -187,10 +193,10 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
187
193
|
}
|
|
188
194
|
}
|
|
189
195
|
function onBlur() {
|
|
190
|
-
// When drag- or resize handle loses focus the transition must be submitted with two exceptions:
|
|
196
|
+
// When drag- or resize handle on palette or board item loses focus the transition must be submitted with two exceptions:
|
|
191
197
|
// 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" && !
|
|
198
|
+
// 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).
|
|
199
|
+
if (transition && transition.interactionType === "keyboard" && !muteEventsRef.current) {
|
|
194
200
|
draggableApi.submitTransition();
|
|
195
201
|
}
|
|
196
202
|
}
|
|
@@ -227,22 +233,19 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
227
233
|
if (inTransition) {
|
|
228
234
|
itemTransitionClassNames.push(styles.inTransition);
|
|
229
235
|
}
|
|
230
|
-
if (transition) {
|
|
236
|
+
if (transition && transition.interactionType === "pointer") {
|
|
231
237
|
// 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
|
-
}
|
|
238
|
+
itemTransitionClassNames.push(transition.operation === "resize" ? styles.resized : styles.dragged);
|
|
239
|
+
itemTransitionStyle.left = (_c = transition.positionTransform) === null || _c === void 0 ? void 0 : _c.x;
|
|
240
|
+
itemTransitionStyle.top = (_d = transition.positionTransform) === null || _d === void 0 ? void 0 : _d.y;
|
|
241
|
+
itemTransitionStyle.width = (_e = transition.sizeTransform) === null || _e === void 0 ? void 0 : _e.width;
|
|
242
|
+
itemTransitionStyle.height = (_f = transition.sizeTransform) === null || _f === void 0 ? void 0 : _f.height;
|
|
243
|
+
itemTransitionStyle.pointerEvents = "none";
|
|
244
|
+
}
|
|
245
|
+
if (isHidden) {
|
|
246
|
+
itemTransitionClassNames.push(styles.hidden);
|
|
244
247
|
}
|
|
245
|
-
if (
|
|
248
|
+
if (transform) {
|
|
246
249
|
// The moved items positions are altered with CSS transform.
|
|
247
250
|
if (transform.type === "move") {
|
|
248
251
|
itemTransitionClassNames.push(styles.transformed);
|
|
@@ -265,12 +268,12 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
|
|
|
265
268
|
useImperativeHandle(ref, () => ({
|
|
266
269
|
focusDragHandle: () => { var _a; return (_a = dragHandleRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
267
270
|
}));
|
|
268
|
-
const isActive = (!!transition && !
|
|
271
|
+
const isActive = (!!transition && !isHidden) || !!acquired;
|
|
269
272
|
const shouldUsePortal = ((transition === null || transition === void 0 ? void 0 : transition.operation) === "insert" || (transition === null || transition === void 0 ? void 0 : transition.operation) === "reorder") &&
|
|
270
273
|
(transition === null || transition === void 0 ? void 0 : transition.interactionType) === "pointer";
|
|
271
274
|
const childrenRef = useRef(null);
|
|
272
275
|
if (!inTransition || isActive) {
|
|
273
|
-
childrenRef.current = children();
|
|
276
|
+
childrenRef.current = children(!!(transition === null || transition === void 0 ? void 0 : transition.hasDropTarget));
|
|
274
277
|
}
|
|
275
278
|
const content = (_jsx("div", { ref: itemRef, className: clsx(styles.root, ...itemTransitionClassNames), style: itemTransitionStyle, "data-item-id": item.id, onBlur: onBlur, children: _jsx(ItemContext.Provider, { value: {
|
|
276
279
|
isActive,
|
|
@@ -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
|
@@ -18,7 +18,7 @@ export function InternalItemsPalette({ items, renderItem, i18nStrings, __interna
|
|
|
18
18
|
itemContainerRef.current[itemId].focusDragHandle();
|
|
19
19
|
}
|
|
20
20
|
useDragSubscription("start", ({ draggableItem: { id } }) => {
|
|
21
|
-
setDropState({ id
|
|
21
|
+
setDropState({ id });
|
|
22
22
|
// Announce only if the target item belongs to the palette.
|
|
23
23
|
if (items.some((it) => it.id === id)) {
|
|
24
24
|
setAnnouncement(i18nStrings.liveAnnouncementDndStarted);
|
|
@@ -27,8 +27,8 @@ export function InternalItemsPalette({ items, renderItem, i18nStrings, __interna
|
|
|
27
27
|
setAnnouncement("");
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
useDragSubscription("update", ({ draggableItem: { id }
|
|
31
|
-
setDropState({ id
|
|
30
|
+
useDragSubscription("update", ({ draggableItem: { id } }) => {
|
|
31
|
+
setDropState({ id });
|
|
32
32
|
});
|
|
33
33
|
useDragSubscription("submit", () => {
|
|
34
34
|
setDropState(undefined);
|
|
@@ -68,7 +68,5 @@ export function InternalItemsPalette({ items, renderItem, i18nStrings, __interna
|
|
|
68
68
|
}
|
|
69
69
|
const { width, height } = dropContext.scale(item);
|
|
70
70
|
return { width, minWidth: width, maxWidth: width, height, minHeight: height, maxHeight: height };
|
|
71
|
-
}, children: () => renderItem(item, {
|
|
72
|
-
showPreview: (dropState === null || dropState === void 0 ? void 0 : dropState.id) === item.id && dropState.isExpanded,
|
|
73
|
-
}) }, item.id))) }) }), _jsx(LiveRegion, { children: announcement })] }));
|
|
71
|
+
}, children: (hasDropTarget) => renderItem(item, { showPreview: hasDropTarget }) }, item.id))) }) }), _jsx(LiveRegion, { children: announcement })] }));
|
|
74
72
|
}
|