@cloudscape-design/board-components 3.0.21 → 3.0.23

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.
@@ -47,12 +47,15 @@ export interface BoardProps<D = DataFallbackType> {
47
47
  */
48
48
  i18nStrings: BoardProps.I18nStrings<D>;
49
49
  /**
50
- * Fired when a user interaction changes size or position of board items.
50
+ * Called when a user modifies the size or position of board items.
51
51
  *
52
52
  * The change detail has the following properties:
53
+ *
53
54
  * * `items`: (readonly Item<D>[]) - the updated items array.
54
- * * `addedItem`: (Item<D>, optional) - the item that was added as part of the update, if available.
55
- * * `removedItem`: (Item<D>, optional) - the item that was removed as part of the update, if available.
55
+ * * `addedItem`: (Item<D>, optional) - the item that was added as part of the update, if applicable.
56
+ * * `removedItem`: (Item<D>, optional) - the item that was removed as part of the update, if applicable.
57
+ * * `resizedItem`: (Item<D>, optional) - the item that was resized as part of the update, if applicable.
58
+ * * `movedItem`: (Item<D>, optional) - the item that was moved as part of the update, if applicable.
56
59
  */
57
60
  onItemsChange: NonCancelableEventHandler<BoardProps.ItemsChangeDetail<D>>;
58
61
  /**
@@ -69,6 +72,8 @@ export declare namespace BoardProps {
69
72
  }
70
73
  interface ItemsChangeDetail<D = DataFallbackType> {
71
74
  items: ReadonlyArray<Item<D>>;
75
+ movedItem?: Item<D>;
76
+ resizedItem?: Item<D>;
72
77
  addedItem?: Item<D>;
73
78
  removedItem?: Item<D>;
74
79
  }
@@ -129,6 +134,7 @@ export interface Transition<D> {
129
134
  collisionIds: Set<ItemId>;
130
135
  layoutShift: null | LayoutShift;
131
136
  path: readonly Position[];
137
+ acquiredItemElement?: ReactNode;
132
138
  }
133
139
  export interface RemoveTransition<D> {
134
140
  items: readonly BoardProps.Item<D>[];
package/board/internal.js CHANGED
@@ -34,6 +34,7 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
34
34
  const removeTransition = transitionState.removeTransition;
35
35
  const transitionAnnouncement = transitionState.announcement;
36
36
  const acquiredItem = (_a = transition === null || transition === void 0 ? void 0 : transition.acquiredItem) !== null && _a !== void 0 ? _a : null;
37
+ const acquiredItemElement = transition === null || transition === void 0 ? void 0 : transition.acquiredItemElement;
37
38
  // Using cached columns from transition to ensure no unexpected changes in the process.
38
39
  const columns = transition ? transition.itemsLayout.columns : currentColumns;
39
40
  // Use previous items while remove transition is in progress.
@@ -132,7 +133,7 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
132
133
  document.body.classList.remove(styles["current-operation-reorder"], styles["current-operation-resize"]);
133
134
  autoScrollHandlers.removePointerEventHandlers();
134
135
  });
135
- useDragSubscription("acquire", ({ droppableId, draggableItem }) => {
136
+ useDragSubscription("acquire", ({ droppableId, draggableItem, acquiredItemElement }) => {
136
137
  const placeholder = placeholdersLayout.items.find((it) => it.id === droppableId);
137
138
  // If missing then it does not belong to this board.
138
139
  if (!placeholder) {
@@ -142,6 +143,7 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
142
143
  type: "acquire-item",
143
144
  position: new Position({ x: placeholder.x, y: placeholder.y }),
144
145
  layoutElement: containerAccessRef.current,
146
+ acquiredItemElement: acquiredItemElement,
145
147
  });
146
148
  focusNextRenderIdRef.current = draggableItem.id;
147
149
  });
@@ -198,7 +200,9 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
198
200
  height: gridContext.getHeight(itemSize.height),
199
201
  minHeight: gridContext.getHeight(getMinRowSpan(item)),
200
202
  maxHeight: gridContext.getHeight(itemMaxSize.height),
201
- }), onKeyMove: onItemMove, children: () => renderItem(item, { removeItem: () => removeItemAction(item) }) }, item.id));
203
+ }), onKeyMove: onItemMove, children: item.id === (acquiredItem === null || acquiredItem === void 0 ? void 0 : acquiredItem.id) && acquiredItemElement
204
+ ? () => acquiredItemElement
205
+ : () => renderItem(item, { removeItem: () => removeItemAction(item) }) }, item.id));
202
206
  });
203
207
  return children;
204
208
  } })) : (empty) }), _jsx(LiveRegion, { children: announcement })] }));
@@ -1,4 +1,4 @@
1
- import { Dispatch } from "react";
1
+ import { Dispatch, ReactNode } from "react";
2
2
  import { InteractionType, Operation } from "../internal/dnd-controller/controller";
3
3
  import { BoardItemDefinitionBase, Direction, GridLayout, ItemId, Rect } from "../internal/interfaces";
4
4
  import { Coordinates } from "../internal/utils/coordinates";
@@ -45,6 +45,7 @@ interface AcquireItemAction {
45
45
  type: "acquire-item";
46
46
  position: Position;
47
47
  layoutElement: HTMLElement;
48
+ acquiredItemElement?: ReactNode;
48
49
  }
49
50
  export declare function useTransition<D>(): [TransitionState<D>, Dispatch<Action<D>>];
50
51
  export declare function selectTransitionRows<D>(state: TransitionState<D>): number;
@@ -207,7 +207,7 @@ function updateTransitionWithKeyboardEvent(state, { direction }) {
207
207
  return updateManualItemTransition(transition, "down");
208
208
  }
209
209
  }
210
- function acquireTransitionItem(state, { position, layoutElement }) {
210
+ function acquireTransitionItem(state, { position, layoutElement, acquiredItemElement }) {
211
211
  const { transition } = state;
212
212
  if (!transition) {
213
213
  throw new Error("Invariant violation: no transition.");
@@ -224,7 +224,14 @@ function acquireTransitionItem(state, { position, layoutElement }) {
224
224
  const layoutShift = getLayoutShift(transition, path, insertionDirection);
225
225
  // The columnOffset, columnSpan and rowSpan are of no use as of being overridden by the layout shift.
226
226
  const acquiredItem = { ...transition.draggableItem, columnOffset: 0, columnSpan: 1, rowSpan: 1 };
227
- const nextTransition = { ...transition, collisionIds: new Set(), layoutShift, path, acquiredItem };
227
+ const nextTransition = {
228
+ ...transition,
229
+ collisionIds: new Set(),
230
+ layoutShift,
231
+ path,
232
+ acquiredItem,
233
+ acquiredItemElement,
234
+ };
228
235
  return {
229
236
  transition: nextTransition,
230
237
  removeTransition: null,
@@ -3,12 +3,17 @@
3
3
  import { createCustomEvent } from "../../internal/utils/events";
4
4
  import { transformItems } from "../../internal/utils/layout";
5
5
  export function createItemsChangeEvent(items, layoutShift) {
6
- var _a, _b, _c, _d, _e, _f;
6
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7
7
  const insertTarget = (_b = (_a = layoutShift.moves.find((move) => move.type === "INSERT")) === null || _a === void 0 ? void 0 : _a.itemId) !== null && _b !== void 0 ? _b : null;
8
- const removeTarget = (_d = (_c = layoutShift.moves.find((move) => move.type === "REMOVE")) === null || _c === void 0 ? void 0 : _c.itemId) !== null && _d !== void 0 ? _d : null;
9
- const resizeTarget = (_f = (_e = layoutShift.moves.find((move) => move.type === "RESIZE")) === null || _e === void 0 ? void 0 : _e.itemId) !== null && _f !== void 0 ? _f : null;
8
+ const moveTarget = (_d = (_c = layoutShift.moves.find((move) => move.type === "MOVE")) === null || _c === void 0 ? void 0 : _c.itemId) !== null && _d !== void 0 ? _d : null;
9
+ const removeTarget = (_f = (_e = layoutShift.moves.find((move) => move.type === "REMOVE")) === null || _e === void 0 ? void 0 : _e.itemId) !== null && _f !== void 0 ? _f : null;
10
+ const resizeTarget = (_h = (_g = layoutShift.moves.find((move) => move.type === "RESIZE")) === null || _g === void 0 ? void 0 : _g.itemId) !== null && _h !== void 0 ? _h : null;
10
11
  const newItems = transformItems(items, layoutShift.next, resizeTarget !== null && resizeTarget !== void 0 ? resizeTarget : insertTarget);
11
- const addedItem = newItems.find((it) => it.id === insertTarget);
12
- const removedItem = newItems.find((it) => it.id === removeTarget);
13
- return createCustomEvent({ items: newItems, addedItem, removedItem });
12
+ return createCustomEvent({
13
+ items: newItems,
14
+ addedItem: newItems.find((it) => it.id === insertTarget),
15
+ removedItem: newItems.find((it) => it.id === removeTarget),
16
+ resizedItem: newItems.find((it) => it.id === resizeTarget),
17
+ movedItem: !insertTarget ? newItems.find((it) => it.id === moveTarget) : undefined,
18
+ });
14
19
  }
@@ -88,7 +88,7 @@ module.exports = {
88
88
  "events": [
89
89
  {
90
90
  "name": "onItemsChange",
91
- "description": "Fired when a user interaction changes size or position of board items.\nThe change detail has the following properties:\n* `items`: (readonly Item<D>[]) - the updated items array.\n* `addedItem`: (Item<D>, optional) - the item that was added as part of the update, if available.\n* `removedItem`: (Item<D>, optional) - the item that was removed as part of the update, if available.\n",
91
+ "description": "Called when a user modifies the size or position of board items.\nThe change detail has the following properties:\n\n* `items`: (readonly Item<D>[]) - the updated items array.\n* `addedItem`: (Item<D>, optional) - the item that was added as part of the update, if applicable.\n* `removedItem`: (Item<D>, optional) - the item that was removed as part of the update, if applicable.\n* `resizedItem`: (Item<D>, optional) - the item that was resized as part of the update, if applicable.\n* `movedItem`: (Item<D>, optional) - the item that was moved as part of the update, if applicable.\n",
92
92
  "cancelable": false,
93
93
  "detailType": "BoardProps.ItemsChangeDetail<D>",
94
94
  "detailInlineType": {
@@ -105,10 +105,20 @@ module.exports = {
105
105
  "type": "ReadonlyArray<BoardProps.Item<D>>",
106
106
  "optional": false
107
107
  },
108
+ {
109
+ "name": "movedItem",
110
+ "type": "BoardProps.Item<D>",
111
+ "optional": true
112
+ },
108
113
  {
109
114
  "name": "removedItem",
110
115
  "type": "BoardProps.Item<D>",
111
116
  "optional": true
117
+ },
118
+ {
119
+ "name": "resizedItem",
120
+ "type": "BoardProps.Item<D>",
121
+ "optional": true
112
122
  }
113
123
  ]
114
124
  }
@@ -1,3 +1,4 @@
1
+ import { ReactNode } from "react";
1
2
  import { BoardItemDefinitionBase, ItemId, Rect } from "../interfaces";
2
3
  import { Coordinates } from "../utils/coordinates";
3
4
  type Item = BoardItemDefinitionBase<unknown>;
@@ -35,6 +36,7 @@ export interface Droppable {
35
36
  interface AcquireData {
36
37
  droppableId: ItemId;
37
38
  draggableItem: Item;
39
+ acquiredItemElement?: ReactNode;
38
40
  }
39
41
  export interface DragAndDropEvents {
40
42
  start: (data: DragAndDropData) => void;
@@ -52,7 +54,7 @@ export declare function useDraggable({ draggableItem, getCollisionRect, }: {
52
54
  updateTransition(coordinates: Coordinates): void;
53
55
  submitTransition(): void;
54
56
  discardTransition(): void;
55
- acquire(droppableId: ItemId): void;
57
+ acquire(droppableId: ItemId, acquiredItemElement?: ReactNode): void;
56
58
  getDroppables(): [string, Droppable][];
57
59
  };
58
60
  export declare function useDroppable({ itemId, context, getElement, }: {
@@ -42,11 +42,11 @@ class DragAndDropController extends EventEmitter {
42
42
  /**
43
43
  * Issues an "acquire" event to notify the current transition draggable is acquired by the given droppable.
44
44
  */
45
- acquire(droppableId) {
45
+ acquire(droppableId, acquiredItemElement) {
46
46
  if (!this.transition) {
47
47
  throw new Error("Invariant violation: no transition present for acquire.");
48
48
  }
49
- this.emit("acquire", { droppableId, draggableItem: this.transition.draggableItem });
49
+ this.emit("acquire", { droppableId, draggableItem: this.transition.draggableItem, acquiredItemElement });
50
50
  }
51
51
  /**
52
52
  * Registers a droppable used for collisions check, acquire, and dropTarget provision.
@@ -113,8 +113,8 @@ export function useDraggable({ draggableItem, getCollisionRect, }) {
113
113
  discardTransition() {
114
114
  controller.discard();
115
115
  },
116
- acquire(droppableId) {
117
- controller.acquire(droppableId);
116
+ acquire(droppableId, acquiredItemElement) {
117
+ controller.acquire(droppableId, acquiredItemElement);
118
118
  },
119
119
  getDroppables() {
120
120
  return controller.getDroppables();
@@ -1,4 +1,4 @@
1
1
  export var PACKAGE_SOURCE = "board-components";
2
- export var PACKAGE_VERSION = "3.0.0 (a3a50d67)";
2
+ export var PACKAGE_VERSION = "3.0.0 (1e40ad14)";
3
3
  export var THEME = "open-source-visual-refresh";
4
4
  export var ALWAYS_VISUAL_REFRESH = true;
@@ -139,7 +139,7 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
139
139
  return;
140
140
  }
141
141
  // Notify the respective droppable of the intention to insert the item in it.
142
- draggableApi.acquire(nextDroppable);
142
+ draggableApi.acquire(nextDroppable, childrenRef.current);
143
143
  }
144
144
  function onHandleKeyDown(operation, event) {
145
145
  const canInsert = transition && operation === "drag" && !placed;
@@ -1,3 +1,3 @@
1
1
  {
2
- "commit": "a3a50d67b43c8088811533ff77574fca0f0135ce"
2
+ "commit": "1e40ad14e04fda613654941bcee13153a5724069"
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudscape-design/board-components",
3
- "version": "3.0.21",
3
+ "version": "3.0.23",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudscape-design/board-components.git"