@cloudscape-design/board-components 3.0.9 → 3.0.11

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.
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { InternalBaseComponentProps } from "../internal/base-component/use-base-component";
3
3
  import { BoardProps } from "./interfaces";
4
- export declare function InternalBoard<D>({ items, renderItem, onItemsChange, empty, i18nStrings, __internalRootRef, }: BoardProps<D> & InternalBaseComponentProps): JSX.Element;
4
+ export declare function InternalBoard<D>({ items, renderItem, onItemsChange, empty, i18nStrings, __internalRootRef, ...rest }: BoardProps<D> & InternalBaseComponentProps): JSX.Element;
package/board/internal.js CHANGED
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import clsx from "clsx";
5
5
  import { useEffect, useRef } from "react";
6
+ import { getDataAttributes } from "../internal/base-component/get-data-attributes";
6
7
  import { useContainerColumns } from "../internal/breakpoints";
7
8
  import { TRANSITION_DURATION_MS } from "../internal/constants";
8
9
  import { useDragSubscription } from "../internal/dnd-controller/controller";
@@ -21,7 +22,7 @@ import { selectTransitionRows, useTransition } from "./transition";
21
22
  import { announcementToString } from "./utils/announcements";
22
23
  import { createTransforms } from "./utils/create-transforms";
23
24
  import { createItemsChangeEvent } from "./utils/events";
24
- export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStrings, __internalRootRef, }) {
25
+ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStrings, __internalRootRef, ...rest }) {
25
26
  var _a, _b;
26
27
  const containerAccessRef = useRef(null);
27
28
  const [columns, containerQueryRef] = useContainerColumns();
@@ -156,7 +157,7 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
156
157
  const announcement = transitionAnnouncement
157
158
  ? announcementToString(transitionAnnouncement, items, i18nStrings, columns)
158
159
  : "";
159
- return (_jsxs("div", { ref: __internalRootRef, children: [_jsx(ScreenReaderGridNavigation, { items: items, itemsLayout: itemsLayout, ariaLabel: i18nStrings.navigationAriaLabel, ariaDescription: i18nStrings.navigationAriaDescription, itemAriaLabel: i18nStrings.navigationItemAriaLabel, onActivateItem: focusItem }), _jsx("div", { ref: containerRef, className: clsx(styles.root, { [styles.empty]: rows === 0 }), children: rows > 0 ? (_jsx(Grid, { columns: columns, layout: [...placeholdersLayout.items, ...itemsLayout.items], children: (gridContext) => {
160
+ return (_jsxs("div", { ref: __internalRootRef, ...getDataAttributes(rest), children: [_jsx(ScreenReaderGridNavigation, { items: items, itemsLayout: itemsLayout, ariaLabel: i18nStrings.navigationAriaLabel, ariaDescription: i18nStrings.navigationAriaDescription, itemAriaLabel: i18nStrings.navigationItemAriaLabel, onActivateItem: focusItem }), _jsx("div", { ref: containerRef, className: clsx(styles.root, { [styles.empty]: rows === 0 }), children: rows > 0 ? (_jsx(Grid, { columns: columns, layout: [...placeholdersLayout.items, ...itemsLayout.items], children: (gridContext) => {
160
161
  var _a;
161
162
  const layoutShift = (_a = transition === null || transition === void 0 ? void 0 : transition.layoutShift) !== null && _a !== void 0 ? _a : removeTransition === null || removeTransition === void 0 ? void 0 : removeTransition.layoutShift;
162
163
  const transforms = layoutShift ? createTransforms(itemsLayout, layoutShift.moves, gridContext) : {};
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { InternalBaseComponentProps } from "../internal/base-component/use-base-component";
3
3
  import type { BoardItemProps } from "./interfaces";
4
- export declare function InternalBoardItem({ children, header, settings, disableContentPaddings, footer, i18nStrings, __internalRootRef, }: BoardItemProps & InternalBaseComponentProps): JSX.Element;
4
+ export declare function InternalBoardItem({ children, header, settings, disableContentPaddings, footer, i18nStrings, __internalRootRef, ...rest }: BoardItemProps & InternalBaseComponentProps): JSX.Element;
@@ -4,17 +4,18 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  import Container from "@cloudscape-design/components/container";
5
5
  import clsx from "clsx";
6
6
  import { useId } from "react";
7
+ import { getDataAttributes } from "../internal/base-component/get-data-attributes";
7
8
  import DragHandle from "../internal/drag-handle";
8
9
  import { useItemContext } from "../internal/item-container";
9
10
  import ResizeHandle from "../internal/resize-handle";
10
11
  import ScreenreaderOnly from "../internal/screenreader-only";
11
12
  import WidgetContainerHeader from "./header";
12
13
  import styles from "./styles.css.js";
13
- export function InternalBoardItem({ children, header, settings, disableContentPaddings, footer, i18nStrings, __internalRootRef, }) {
14
+ export function InternalBoardItem({ children, header, settings, disableContentPaddings, footer, i18nStrings, __internalRootRef, ...rest }) {
14
15
  const { dragHandle, resizeHandle, isActive } = useItemContext();
15
16
  const dragHandleAriaLabelledBy = useId();
16
17
  const dragHandleAriaDescribedBy = useId();
17
18
  const resizeHandleAriaLabelledBy = useId();
18
19
  const resizeHandleAriaDescribedBy = useId();
19
- return (_jsxs("div", { ref: __internalRootRef, className: styles.root, children: [_jsx(Container, { fitHeight: true, disableHeaderPaddings: true, header: _jsx(WidgetContainerHeader, { handle: _jsx(DragHandle, { ref: dragHandle.ref, ariaLabelledBy: dragHandleAriaLabelledBy, ariaDescribedBy: dragHandleAriaDescribedBy, onPointerDown: dragHandle.onPointerDown, onKeyDown: dragHandle.onKeyDown }), settings: settings, children: header }), footer: footer, disableContentPaddings: disableContentPaddings, className: clsx(styles["container-override"], isActive && styles.active), children: children }), resizeHandle && (_jsx("div", { className: styles.resizer, children: _jsx(ResizeHandle, { ariaLabelledBy: resizeHandleAriaLabelledBy, ariaDescribedBy: resizeHandleAriaDescribedBy, onPointerDown: resizeHandle.onPointerDown, onKeyDown: resizeHandle.onKeyDown }) })), _jsx(ScreenreaderOnly, { id: dragHandleAriaLabelledBy, children: i18nStrings.dragHandleAriaLabel }), _jsx(ScreenreaderOnly, { id: dragHandleAriaDescribedBy, children: i18nStrings.dragHandleAriaDescription }), _jsx(ScreenreaderOnly, { id: resizeHandleAriaLabelledBy, children: i18nStrings.resizeHandleAriaLabel }), _jsx(ScreenreaderOnly, { id: resizeHandleAriaDescribedBy, children: i18nStrings.resizeHandleAriaDescription })] }));
20
+ return (_jsxs("div", { ref: __internalRootRef, className: styles.root, ...getDataAttributes(rest), children: [_jsx(Container, { fitHeight: true, disableHeaderPaddings: true, header: _jsx(WidgetContainerHeader, { handle: _jsx(DragHandle, { ref: dragHandle.ref, ariaLabelledBy: dragHandleAriaLabelledBy, ariaDescribedBy: dragHandleAriaDescribedBy, onPointerDown: dragHandle.onPointerDown, onKeyDown: dragHandle.onKeyDown }), settings: settings, children: header }), footer: footer, disableContentPaddings: disableContentPaddings, className: clsx(styles["container-override"], isActive && styles.active), children: children }), resizeHandle && (_jsx("div", { className: styles.resizer, children: _jsx(ResizeHandle, { ariaLabelledBy: resizeHandleAriaLabelledBy, ariaDescribedBy: resizeHandleAriaDescribedBy, onPointerDown: resizeHandle.onPointerDown, onKeyDown: resizeHandle.onKeyDown }) })), _jsx(ScreenreaderOnly, { id: dragHandleAriaLabelledBy, children: i18nStrings.dragHandleAriaLabel }), _jsx(ScreenreaderOnly, { id: dragHandleAriaDescribedBy, children: i18nStrings.dragHandleAriaDescription }), _jsx(ScreenreaderOnly, { id: resizeHandleAriaLabelledBy, children: i18nStrings.resizeHandleAriaLabel }), _jsx(ScreenreaderOnly, { id: resizeHandleAriaDescribedBy, children: i18nStrings.resizeHandleAriaDescription })] }));
20
21
  }
@@ -1,15 +1,15 @@
1
1
 
2
2
  import './styles.scoped.css';
3
3
  export default {
4
- "root": "awsui_root_9ckv7_7y7kt_1",
5
- "container-override": "awsui_container-override_9ckv7_7y7kt_6",
6
- "active": "awsui_active_9ckv7_7y7kt_6",
7
- "header": "awsui_header_9ckv7_7y7kt_10",
8
- "flexible": "awsui_flexible_9ckv7_7y7kt_16",
9
- "handle": "awsui_handle_9ckv7_7y7kt_20",
10
- "header-content": "awsui_header-content_9ckv7_7y7kt_24",
11
- "settings": "awsui_settings_9ckv7_7y7kt_28",
12
- "fixed": "awsui_fixed_9ckv7_7y7kt_33",
13
- "resizer": "awsui_resizer_9ckv7_7y7kt_37"
4
+ "root": "awsui_root_9ckv7_o6rfp_1",
5
+ "container-override": "awsui_container-override_9ckv7_o6rfp_6",
6
+ "active": "awsui_active_9ckv7_o6rfp_6",
7
+ "header": "awsui_header_9ckv7_o6rfp_10",
8
+ "flexible": "awsui_flexible_9ckv7_o6rfp_16",
9
+ "handle": "awsui_handle_9ckv7_o6rfp_20",
10
+ "header-content": "awsui_header-content_9ckv7_o6rfp_24",
11
+ "settings": "awsui_settings_9ckv7_o6rfp_28",
12
+ "fixed": "awsui_fixed_9ckv7_o6rfp_33",
13
+ "resizer": "awsui_resizer_9ckv7_o6rfp_37"
14
14
  };
15
15
 
@@ -1,40 +1,40 @@
1
- .awsui_root_9ckv7_7y7kt_1:not(#\9) {
1
+ .awsui_root_9ckv7_o6rfp_1:not(#\9) {
2
2
  display: contents;
3
3
  }
4
4
 
5
5
  /* TODO: use container API instead of styles override */
6
- .awsui_container-override_9ckv7_7y7kt_6.awsui_active_9ckv7_7y7kt_6:not(#\9) {
6
+ .awsui_container-override_9ckv7_o6rfp_6.awsui_active_9ckv7_o6rfp_6:not(#\9) {
7
7
  box-shadow: var(--shadow-container-active-l4kuxc, 0px 1px 1px 1px #e9ebed, 0px 6px 36px rgba(0, 7, 22, 0.1019607843));
8
8
  }
9
9
 
10
- .awsui_header_9ckv7_7y7kt_10:not(#\9) {
10
+ .awsui_header_9ckv7_o6rfp_10:not(#\9) {
11
11
  display: flex;
12
12
  justify-items: center;
13
13
  padding: var(--space-scaled-s-cu1hzn, 12px) calc(var(--space-container-horizontal-tlw03i, 20px) - var(--space-scaled-xs-6859qs, 8px));
14
14
  }
15
15
 
16
- .awsui_flexible_9ckv7_7y7kt_16:not(#\9) {
16
+ .awsui_flexible_9ckv7_o6rfp_16:not(#\9) {
17
17
  flex: 1 1 min-content;
18
18
  }
19
19
 
20
- .awsui_handle_9ckv7_7y7kt_20:not(#\9) {
20
+ .awsui_handle_9ckv7_o6rfp_20:not(#\9) {
21
21
  margin-top: calc(var(--space-scaled-xxs-95dhkm, 4px) + 1px);
22
22
  }
23
23
 
24
- .awsui_header-content_9ckv7_7y7kt_24:not(#\9) {
24
+ .awsui_header-content_9ckv7_o6rfp_24:not(#\9) {
25
25
  margin-left: var(--space-scaled-xxs-95dhkm, 4px);
26
26
  }
27
27
 
28
- .awsui_settings_9ckv7_7y7kt_28:not(#\9) {
29
- margin-top: calc(var(--space-scaled-xxxs-b6dm8t, 2px) + 1px);
28
+ .awsui_settings_9ckv7_o6rfp_28:not(#\9) {
29
+ margin-top: calc(var(--space-scaled-xxxs-lo883m, 2px) + 1px);
30
30
  margin-left: var(--space-static-xs-9adq92, 8px);
31
31
  }
32
32
 
33
- .awsui_fixed_9ckv7_7y7kt_33:not(#\9) {
33
+ .awsui_fixed_9ckv7_o6rfp_33:not(#\9) {
34
34
  flex: 0 0 auto;
35
35
  }
36
36
 
37
- .awsui_resizer_9ckv7_7y7kt_37:not(#\9) {
37
+ .awsui_resizer_9ckv7_o6rfp_37:not(#\9) {
38
38
  position: absolute;
39
39
  bottom: calc(var(--space-static-xs-9adq92, 8px) - var(--space-static-xxxs-k3qmdh, 2px));
40
40
  right: calc(var(--space-static-xs-9adq92, 8px) - var(--space-static-xxxs-k3qmdh, 2px));
@@ -2,15 +2,15 @@
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_9ckv7_7y7kt_1",
6
- "container-override": "awsui_container-override_9ckv7_7y7kt_6",
7
- "active": "awsui_active_9ckv7_7y7kt_6",
8
- "header": "awsui_header_9ckv7_7y7kt_10",
9
- "flexible": "awsui_flexible_9ckv7_7y7kt_16",
10
- "handle": "awsui_handle_9ckv7_7y7kt_20",
11
- "header-content": "awsui_header-content_9ckv7_7y7kt_24",
12
- "settings": "awsui_settings_9ckv7_7y7kt_28",
13
- "fixed": "awsui_fixed_9ckv7_7y7kt_33",
14
- "resizer": "awsui_resizer_9ckv7_7y7kt_37"
5
+ "root": "awsui_root_9ckv7_o6rfp_1",
6
+ "container-override": "awsui_container-override_9ckv7_o6rfp_6",
7
+ "active": "awsui_active_9ckv7_o6rfp_6",
8
+ "header": "awsui_header_9ckv7_o6rfp_10",
9
+ "flexible": "awsui_flexible_9ckv7_o6rfp_16",
10
+ "handle": "awsui_handle_9ckv7_o6rfp_20",
11
+ "header-content": "awsui_header-content_9ckv7_o6rfp_24",
12
+ "settings": "awsui_settings_9ckv7_o6rfp_28",
13
+ "fixed": "awsui_fixed_9ckv7_o6rfp_33",
14
+ "resizer": "awsui_resizer_9ckv7_o6rfp_37"
15
15
  };
16
16
 
@@ -0,0 +1 @@
1
+ export declare function getDataAttributes(props: Record<string, string>): Record<string, any>;
@@ -0,0 +1,11 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export function getDataAttributes(props) {
4
+ const result = {};
5
+ Object.keys(props).forEach((prop) => {
6
+ if (prop.startsWith("data-")) {
7
+ result[prop] = props[prop];
8
+ }
9
+ });
10
+ return result;
11
+ }
@@ -1,4 +1,4 @@
1
1
  export var PACKAGE_SOURCE = "board-components";
2
- export var PACKAGE_VERSION = "3.0.0 (d7b7a1cf)";
2
+ export var PACKAGE_VERSION = "3.0.0 (80489570)";
3
3
  export var THEME = "open-source-visual-refresh";
4
4
  export var ALWAYS_VISUAL_REFRESH = true;
@@ -4,7 +4,7 @@ import { BoardItemDefinitionBase, Direction, Transform } from "../interfaces";
4
4
  export interface ItemContainerRef {
5
5
  focusDragHandle(): void;
6
6
  }
7
- export interface ItemContext {
7
+ interface ItemContextType {
8
8
  isActive: boolean;
9
9
  dragHandle: {
10
10
  ref: RefObject<HTMLButtonElement>;
@@ -16,7 +16,8 @@ export interface ItemContext {
16
16
  onKeyDown(event: KeyboardEvent): void;
17
17
  };
18
18
  }
19
- export declare function useItemContext(): ItemContext;
19
+ export declare const ItemContext: import("react").Context<ItemContextType | null>;
20
+ export declare function useItemContext(): ItemContextType;
20
21
  /**
21
22
  * Defines item's parameters and its relation with the layout.
22
23
  *
@@ -46,3 +47,4 @@ export interface ItemContainerProps {
46
47
  children: ReactNode;
47
48
  }
48
49
  export declare const ItemContainer: import("react").ForwardRefExoticComponent<ItemContainerProps & import("react").RefAttributes<ItemContainerRef>>;
50
+ export {};
@@ -7,14 +7,13 @@ import { createContext, forwardRef, useContext, useEffect, useImperativeHandle,
7
7
  import { useDragSubscription, useDraggable, } from "../dnd-controller/controller";
8
8
  import { Coordinates } from "../utils/coordinates";
9
9
  import { getNormalizedElementRect } from "../utils/screen";
10
- import { useStableEventHandler } from "../utils/use-stable-event-handler";
11
- import { useThrottledEventHandler } from "../utils/use-throttled-event-handler";
10
+ import { throttle } from "../utils/throttle";
12
11
  import { getCollisionRect } from "./get-collision-rect";
13
12
  import { getNextDroppable } from "./get-next-droppable";
14
13
  import styles from "./styles.css.js";
15
- const Context = createContext(null);
14
+ export const ItemContext = createContext(null);
16
15
  export function useItemContext() {
17
- const ctx = useContext(Context);
16
+ const ctx = useContext(ItemContext);
18
17
  if (!ctx) {
19
18
  throw new Error("Unable to find BoardItem context.");
20
19
  }
@@ -35,18 +34,6 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
35
34
  return getCollisionRect(operation, itemRef.current, coordinates, sizeOverride);
36
35
  },
37
36
  });
38
- const onPointerMove = useThrottledEventHandler((event) => {
39
- var _a, _b, _c, _d;
40
- const coordinates = Coordinates.fromEvent(event);
41
- draggableApi.updateTransition(new Coordinates({
42
- x: Math.max(coordinates.x, (_b = (_a = pointerBoundariesRef.current) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : Number.NEGATIVE_INFINITY),
43
- y: Math.max(coordinates.y, (_d = (_c = pointerBoundariesRef.current) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : Number.NEGATIVE_INFINITY),
44
- }));
45
- }, 10);
46
- const onPointerUp = useStableEventHandler(() => {
47
- onPointerMove.cancel();
48
- draggableApi.submitTransition();
49
- });
50
37
  function updateTransition({ operation, interactionType, draggableItem, collisionRect, coordinates, dropTarget, }) {
51
38
  if (item.id === draggableItem.id) {
52
39
  const [width, height] = [collisionRect.right - collisionRect.left, collisionRect.bottom - collisionRect.top];
@@ -89,6 +76,18 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
89
76
  const transitionInteractionType = (_a = transition === null || transition === void 0 ? void 0 : transition.interactionType) !== null && _a !== void 0 ? _a : null;
90
77
  const transitionItemId = (_b = transition === null || transition === void 0 ? void 0 : transition.itemId) !== null && _b !== void 0 ? _b : null;
91
78
  useEffect(() => {
79
+ const onPointerMove = throttle((event) => {
80
+ var _a, _b, _c, _d;
81
+ const coordinates = Coordinates.fromEvent(event);
82
+ draggableApi.updateTransition(new Coordinates({
83
+ x: Math.max(coordinates.x, (_b = (_a = pointerBoundariesRef.current) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : Number.NEGATIVE_INFINITY),
84
+ y: Math.max(coordinates.y, (_d = (_c = pointerBoundariesRef.current) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : Number.NEGATIVE_INFINITY),
85
+ }));
86
+ }, 10);
87
+ const onPointerUp = () => {
88
+ onPointerMove.cancel();
89
+ draggableApi.submitTransition();
90
+ };
92
91
  if (transitionInteractionType === "pointer" && transitionItemId === item.id) {
93
92
  window.addEventListener("pointermove", onPointerMove);
94
93
  window.addEventListener("pointerup", onPointerUp);
@@ -97,7 +96,9 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
97
96
  window.removeEventListener("pointermove", onPointerMove);
98
97
  window.removeEventListener("pointerup", onPointerUp);
99
98
  };
100
- }, [item.id, transitionInteractionType, transitionItemId, onPointerMove, onPointerUp]);
99
+ // draggableApi is not expected to change
100
+ // eslint-disable-next-line react-hooks/exhaustive-deps
101
+ }, [item.id, transitionInteractionType, transitionItemId]);
101
102
  function onKeyboardTransitionToggle(operation) {
102
103
  // The acquired item is a copy and does not have the transition state.
103
104
  // However, pressing "Space" or "Enter" on the acquired item must submit the active transition.
@@ -252,7 +253,7 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
252
253
  useImperativeHandle(ref, () => ({
253
254
  focusDragHandle: () => { var _a; return (_a = dragHandleRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
254
255
  }));
255
- return (_jsx("div", { ref: itemRef, className: clsx(styles.root, ...itemTransitionClassNames), style: itemTransitionStyle, "data-item-id": item.id, onBlur: onBlur, children: _jsx(Context.Provider, { value: {
256
+ return (_jsx("div", { ref: itemRef, className: clsx(styles.root, ...itemTransitionClassNames), style: itemTransitionStyle, "data-item-id": item.id, onBlur: onBlur, children: _jsx(ItemContext.Provider, { value: {
256
257
  isActive: (!!transition && !transition.isBorrowed) || !!acquired,
257
258
  dragHandle: {
258
259
  ref: dragHandleRef,
@@ -1,3 +1,3 @@
1
1
  {
2
- "commit": "d7b7a1cf21b47243ecc9d552fc84f09cf70bf951"
2
+ "commit": "80489570231464cdf039fe26f27deedddecb1858"
3
3
  }
@@ -78,19 +78,13 @@ export function transformItems(sourceItems, gridLayout, resizeTarget) {
78
78
  const items = [];
79
79
  let changeFromIndex = sortedLayout.findIndex(({ id }, index) => id !== sourceItems[index].id || id === resizeTarget);
80
80
  changeFromIndex = changeFromIndex !== -1 ? changeFromIndex : sortedLayout.length;
81
- function setColumnOffset(item, layout, value) {
82
- if (!item.columnOffset) {
83
- item.columnOffset = {};
84
- }
85
- item.columnOffset[layout] = value;
86
- }
87
81
  for (let index = 0; index < sortedLayout.length; index++) {
88
82
  const { id, x, width, height } = sortedLayout[index];
89
83
  const item = { ...getItem(id) };
90
84
  if (index >= changeFromIndex) {
91
85
  item.columnOffset = undefined;
92
86
  }
93
- setColumnOffset(item, gridLayout.columns, x);
87
+ item.columnOffset = { ...item.columnOffset, [gridLayout.columns]: x };
94
88
  if (item.id === resizeTarget) {
95
89
  item.columnSpan = width;
96
90
  item.rowSpan = height;
@@ -1,12 +1,13 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  export function throttle(func, delay) {
4
+ let cancelled = false;
4
5
  let pending = null;
5
6
  let lastInvokeTime = null;
6
7
  let timerId = null;
7
8
  // Runs on every animation frame until timer stopped.
8
9
  function pendingFunc() {
9
- if (pending === null || lastInvokeTime === null) {
10
+ if (cancelled === true || pending === null || lastInvokeTime === null) {
10
11
  return;
11
12
  }
12
13
  const invokeTime = Date.now();
@@ -46,6 +47,7 @@ export function throttle(func, delay) {
46
47
  pending = null;
47
48
  lastInvokeTime = null;
48
49
  timerId = null;
50
+ cancelled = true;
49
51
  };
50
52
  return throttled;
51
53
  }
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { InternalBaseComponentProps } from "../internal/base-component/use-base-component";
3
3
  import { ItemsPaletteProps } from "./interfaces";
4
- export declare function InternalItemsPalette<D>({ items, renderItem, i18nStrings, __internalRootRef, }: ItemsPaletteProps<D> & InternalBaseComponentProps): JSX.Element;
4
+ export declare function InternalItemsPalette<D>({ items, renderItem, i18nStrings, __internalRootRef, ...rest }: ItemsPaletteProps<D> & InternalBaseComponentProps): JSX.Element;
@@ -3,12 +3,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import SpaceBetween from "@cloudscape-design/components/space-between";
5
5
  import { useRef, useState } from "react";
6
+ import { getDataAttributes } from "../internal/base-component/get-data-attributes";
6
7
  import { useDragSubscription } from "../internal/dnd-controller/controller";
7
8
  import { ItemContainer } from "../internal/item-container";
8
9
  import LiveRegion from "../internal/live-region";
9
10
  import { ScreenReaderGridNavigation } from "../internal/screenreader-grid-navigation";
10
11
  import styles from "./styles.css.js";
11
- export function InternalItemsPalette({ items, renderItem, i18nStrings, __internalRootRef, }) {
12
+ export function InternalItemsPalette({ items, renderItem, i18nStrings, __internalRootRef, ...rest }) {
12
13
  const paletteRef = useRef(null);
13
14
  const itemContainerRef = useRef({});
14
15
  const [dropState, setDropState] = useState();
@@ -54,7 +55,7 @@ export function InternalItemsPalette({ items, renderItem, i18nStrings, __interna
54
55
  columns: 1,
55
56
  rows: items.length,
56
57
  };
57
- return (_jsxs("div", { ref: __internalRootRef, children: [_jsx(ScreenReaderGridNavigation, { items: items, itemsLayout: itemsLayout, ariaLabel: i18nStrings.navigationAriaLabel, ariaDescription: i18nStrings.navigationAriaDescription, itemAriaLabel: (item) => i18nStrings.navigationItemAriaLabel(item), onActivateItem: focusItem }), _jsx("div", { ref: paletteRef, className: styles.root, children: _jsx(SpaceBetween, { size: "l", children: items.map((item) => (_jsx(ItemContainer, { ref: (elem) => {
58
+ return (_jsxs("div", { ref: __internalRootRef, ...getDataAttributes(rest), children: [_jsx(ScreenReaderGridNavigation, { items: items, itemsLayout: itemsLayout, ariaLabel: i18nStrings.navigationAriaLabel, ariaDescription: i18nStrings.navigationAriaDescription, itemAriaLabel: (item) => i18nStrings.navigationItemAriaLabel(item), onActivateItem: focusItem }), _jsx("div", { ref: paletteRef, className: styles.root, children: _jsx(SpaceBetween, { size: "l", children: items.map((item) => (_jsx(ItemContainer, { ref: (elem) => {
58
59
  if (elem) {
59
60
  itemContainerRef.current[item.id] = elem;
60
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudscape-design/board-components",
3
- "version": "3.0.9",
3
+ "version": "3.0.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudscape-design/board-components.git"
@@ -1 +0,0 @@
1
- export declare function useThrottledEventHandler<T extends (...args: any[]) => void>(callback: T, delay: number): import("./throttle").ThrottledFunction<T>;
@@ -1,11 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { useCallback } from "react";
4
- import { throttle } from "./throttle";
5
- import { useStableEventHandler } from "./use-stable-event-handler";
6
- export function useThrottledEventHandler(callback, delay) {
7
- const stableCallback = useStableEventHandler(callback);
8
- // ESLint rule requires an inline function which we cannot provide here
9
- // eslint-disable-next-line react-hooks/exhaustive-deps
10
- return useCallback(throttle(((...args) => stableCallback(...args)), delay), []);
11
- }