@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 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, acquiredItemElement }) => {
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: 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: true, acquired: item.id === (acquiredItem === null || acquiredItem === void 0 ? void 0 : acquiredItem.id), getItemSize: () => ({
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),
@@ -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
  });
@@ -36,7 +36,7 @@ export interface Droppable {
36
36
  interface AcquireData {
37
37
  droppableId: ItemId;
38
38
  draggableItem: Item;
39
- acquiredItemElement?: ReactNode;
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, acquiredItemElement?: ReactNode): void;
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, acquiredItemElement) {
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, acquiredItemElement });
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
- 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 {
@@ -113,8 +115,8 @@ export function useDraggable({ draggableItem, getCollisionRect, }) {
113
115
  discardTransition() {
114
116
  controller.discard();
115
117
  },
116
- acquire(droppableId, acquiredItemElement) {
117
- controller.acquire(droppableId, acquiredItemElement);
118
+ acquire(droppableId, renderAcquiredItem) {
119
+ controller.acquire(droppableId, renderAcquiredItem);
118
120
  },
119
121
  getDroppables() {
120
122
  return controller.getDroppables();
@@ -1,4 +1,4 @@
1
1
  export var PACKAGE_SOURCE = "board-components";
2
- export var PACKAGE_VERSION = "3.0.0 (b4c8f266)";
2
+ export var PACKAGE_VERSION = "3.0.0 (222f89e3)";
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 (b4c8f266)",
3
+ "PACKAGE_VERSION": "3.0.0 (222f89e3)",
4
4
  "THEME": "open-source-visual-refresh",
5
5
  "ALWAYS_VISUAL_REFRESH": true
6
6
  }
@@ -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((transition) => ({
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
- 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
+ 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", () => 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
- }
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, childrenRef.current);
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 borrowed (in that case the focus moves to the acquired item which is expected).
193
- if (transition && transition.interactionType === "keyboard" && !transition.isBorrowed) {
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
- 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
- }
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 (placed && transform) {
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 && !transition.isBorrowed) || !!acquired;
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": "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": "b4c8f266f6f1ed79280c9224722081597f6f8aed"
2
+ "commit": "222f89e36dd7458e8541be32c1e9dc059173a886"
3
3
  }
@@ -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, isExpanded: false });
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 }, dropTarget }) => {
31
- setDropState({ id, isExpanded: !!dropTarget });
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudscape-design/board-components",
3
- "version": "3.0.29",
3
+ "version": "3.0.31",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudscape-design/board-components.git"