@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.
@@ -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: newItems.find((it) => it.id === removeTarget),
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
- useEffect(() => controller.on(event, handler), [event, handler]);
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 {
@@ -1,4 +1,4 @@
1
1
  export var PACKAGE_SOURCE = "board-components";
2
- export var PACKAGE_VERSION = "3.0.0 (49652ff5)";
2
+ export var PACKAGE_VERSION = "3.0.0 (5dff2947)";
3
3
  export var THEME = "open-source-visual-refresh";
4
4
  export var ALWAYS_VISUAL_REFRESH = true;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "PACKAGE_SOURCE": "board-components",
3
- "PACKAGE_VERSION": "3.0.0 (49652ff5)",
3
+ "PACKAGE_VERSION": "3.0.0 (5dff2947)",
4
4
  "THEME": "open-source-visual-refresh",
5
5
  "ALWAYS_VISUAL_REFRESH": true
6
6
  }
@@ -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((transition) => ({
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
- isBorrowed: !!(transition === null || transition === void 0 ? void 0 : transition.isBorrowed),
53
- }));
54
+ });
54
55
  }
55
56
  else if (operation === "insert" || operation === "reorder") {
56
- setTransition((transition) => ({
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
- isBorrowed: !!(transition === null || transition === void 0 ? void 0 : transition.isBorrowed),
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", () => setTransition(null));
70
- useDragSubscription("discard", () => setTransition(null));
71
- useDragSubscription("acquire", (detail) => {
72
- if (detail.draggableItem.id === item.id) {
73
- setTransition((transition) => transition && { ...transition, isBorrowed: true });
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 borrowed (in that case the focus moves to the acquired item which is expected).
193
- if (transition && transition.interactionType === "keyboard" && !transition.isBorrowed) {
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
- if (transition.interactionType === "pointer") {
233
- itemTransitionClassNames.push(transition.operation === "resize" ? styles.resized : styles.dragged);
234
- itemTransitionStyle.left = (_c = transition.positionTransform) === null || _c === void 0 ? void 0 : _c.x;
235
- itemTransitionStyle.top = (_d = transition.positionTransform) === null || _d === void 0 ? void 0 : _d.y;
236
- itemTransitionStyle.width = (_e = transition.sizeTransform) === null || _e === void 0 ? void 0 : _e.width;
237
- itemTransitionStyle.height = (_f = transition.sizeTransform) === null || _f === void 0 ? void 0 : _f.height;
238
- itemTransitionStyle.pointerEvents = "none";
239
- }
240
- // Make the borrowed item dimmed.
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 && !transition.isBorrowed) || !!acquired;
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": "awsui_root_lljvd_1nttw_1",
5
- "inTransition": "awsui_inTransition_lljvd_1nttw_7",
6
- "transformed": "awsui_transformed_lljvd_1nttw_12",
7
- "removed": "awsui_removed_lljvd_1nttw_17",
8
- "dragged": "awsui_dragged_lljvd_1nttw_21",
9
- "resized": "awsui_resized_lljvd_1nttw_26",
10
- "borrowed": "awsui_borrowed_lljvd_1nttw_31"
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
- .awsui_root_lljvd_1nttw_1:not(#\9) {
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
- .awsui_inTransition_lljvd_1nttw_7:not(#\9) {
7
+ .awsui_inTransition_lljvd_1jk2l_7:not(#\9) {
8
8
  transition: transform 200ms;
9
9
  transition-timing-function: ease;
10
10
  }
11
11
 
12
- .awsui_transformed_lljvd_1nttw_12:not(#\9) {
12
+ .awsui_transformed_lljvd_1jk2l_12:not(#\9) {
13
13
  position: absolute;
14
14
  z-index: 1;
15
15
  }
16
16
 
17
- .awsui_removed_lljvd_1nttw_17:not(#\9) {
17
+ .awsui_removed_lljvd_1jk2l_17:not(#\9) {
18
18
  display: none;
19
19
  }
20
20
 
21
- .awsui_dragged_lljvd_1nttw_21:not(#\9) {
21
+ .awsui_dragged_lljvd_1jk2l_21:not(#\9) {
22
22
  z-index: 2000;
23
23
  position: fixed;
24
24
  }
25
25
 
26
- .awsui_resized_lljvd_1nttw_26:not(#\9) {
26
+ .awsui_resized_lljvd_1jk2l_26:not(#\9) {
27
27
  z-index: 2000;
28
28
  position: absolute;
29
29
  }
30
30
 
31
- .awsui_borrowed_lljvd_1nttw_31:not(#\9) {
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": "awsui_root_lljvd_1nttw_1",
6
- "inTransition": "awsui_inTransition_lljvd_1nttw_7",
7
- "transformed": "awsui_transformed_lljvd_1nttw_12",
8
- "removed": "awsui_removed_lljvd_1nttw_17",
9
- "dragged": "awsui_dragged_lljvd_1nttw_21",
10
- "resized": "awsui_resized_lljvd_1nttw_26",
11
- "borrowed": "awsui_borrowed_lljvd_1nttw_31"
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
 
@@ -1,3 +1,3 @@
1
1
  {
2
- "commit": "49652ff586f1bf37480d83de685ced23a5bbf1fc"
2
+ "commit": "5dff29478d324c1d9508bb43b94dcef2e723a177"
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudscape-design/board-components",
3
- "version": "3.0.28",
3
+ "version": "3.0.30",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudscape-design/board-components.git"