@cloudscape-design/board-components 3.0.10 → 3.0.12

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) : {};
@@ -185,14 +186,14 @@ export function InternalBoard({ items, renderItem, onItemsChange, empty, i18nStr
185
186
  else {
186
187
  delete itemContainerRef.current[item.id];
187
188
  }
188
- }, item: item, transform: transforms[item.id], inTransition: !!layoutShift, placed: true, acquired: item.id === (acquiredItem === null || acquiredItem === void 0 ? void 0 : acquiredItem.id), getItemSize: () => ({
189
+ }, item: item, transform: transforms[item.id], inTransition: !!transition || !!removeTransition, placed: true, acquired: item.id === (acquiredItem === null || acquiredItem === void 0 ? void 0 : acquiredItem.id), getItemSize: () => ({
189
190
  width: gridContext.getWidth(itemSize.width),
190
191
  minWidth: gridContext.getWidth(getMinColumnSpan(item, columns)),
191
192
  maxWidth: gridContext.getWidth(itemMaxSize.width),
192
193
  height: gridContext.getHeight(itemSize.height),
193
194
  minHeight: gridContext.getHeight(getMinRowSpan(item)),
194
195
  maxHeight: gridContext.getHeight(itemMaxSize.height),
195
- }), onKeyMove: onItemMove, children: renderItem(item, { removeItem: () => removeItemAction(item) }) }, item.id));
196
+ }), onKeyMove: onItemMove, children: () => renderItem(item, { removeItem: () => removeItemAction(item) }) }, item.id));
196
197
  });
197
198
  return children;
198
199
  } })) : (empty) }), _jsx(LiveRegion, { children: announcement })] }));
@@ -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
  }
@@ -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 (15818dea)";
2
+ export var PACKAGE_VERSION = "3.0.0 (e54f625f)";
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
  *
@@ -43,6 +44,7 @@ export interface ItemContainerProps {
43
44
  maxHeight: number;
44
45
  };
45
46
  onKeyMove?(direction: Direction): void;
46
- children: ReactNode;
47
+ children: () => ReactNode;
47
48
  }
48
49
  export declare const ItemContainer: import("react").ForwardRefExoticComponent<ItemContainerProps & import("react").RefAttributes<ItemContainerRef>>;
50
+ export {};
@@ -11,9 +11,9 @@ import { throttle } from "../utils/throttle";
11
11
  import { getCollisionRect } from "./get-collision-rect";
12
12
  import { getNextDroppable } from "./get-next-droppable";
13
13
  import styles from "./styles.css.js";
14
- const Context = createContext(null);
14
+ export const ItemContext = createContext(null);
15
15
  export function useItemContext() {
16
- const ctx = useContext(Context);
16
+ const ctx = useContext(ItemContext);
17
17
  if (!ctx) {
18
18
  throw new Error("Unable to find BoardItem context.");
19
19
  }
@@ -253,8 +253,13 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
253
253
  useImperativeHandle(ref, () => ({
254
254
  focusDragHandle: () => { var _a; return (_a = dragHandleRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
255
255
  }));
256
- return (_jsx("div", { ref: itemRef, className: clsx(styles.root, ...itemTransitionClassNames), style: itemTransitionStyle, "data-item-id": item.id, onBlur: onBlur, children: _jsx(Context.Provider, { value: {
257
- isActive: (!!transition && !transition.isBorrowed) || !!acquired,
256
+ const isActive = (!!transition && !transition.isBorrowed) || !!acquired;
257
+ const childrenRef = useRef(null);
258
+ if (!inTransition || isActive) {
259
+ childrenRef.current = children();
260
+ }
261
+ return (_jsx("div", { ref: itemRef, className: clsx(styles.root, ...itemTransitionClassNames), style: itemTransitionStyle, "data-item-id": item.id, onBlur: onBlur, children: _jsx(ItemContext.Provider, { value: {
262
+ isActive,
258
263
  dragHandle: {
259
264
  ref: dragHandleRef,
260
265
  onPointerDown: onDragHandlePointerDown,
@@ -266,5 +271,5 @@ function ItemContainerComponent({ item, placed, acquired, inTransition, transfor
266
271
  onKeyDown: onResizeHandleKeyDown,
267
272
  }
268
273
  : null,
269
- }, children: children }) }));
274
+ }, children: childrenRef.current }) }));
270
275
  }
@@ -1,3 +1,3 @@
1
1
  {
2
- "commit": "15818dea059d8aaa61ad7c3a37cfeb228d48fa53"
2
+ "commit": "e54f625f9918c8ec22794da2af6fc13af4b62c12"
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,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
  }
@@ -67,7 +68,7 @@ export function InternalItemsPalette({ items, renderItem, i18nStrings, __interna
67
68
  }
68
69
  const { width, height } = dropContext.scale(item);
69
70
  return { width, minWidth: width, maxWidth: width, height, minHeight: height, maxHeight: height };
70
- }, children: renderItem(item, {
71
+ }, children: () => renderItem(item, {
71
72
  showPreview: (dropState === null || dropState === void 0 ? void 0 : dropState.id) === item.id && dropState.isExpanded,
72
73
  }) }, item.id))) }) }), _jsx(LiveRegion, { children: announcement })] }));
73
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudscape-design/board-components",
3
- "version": "3.0.10",
3
+ "version": "3.0.12",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudscape-design/board-components.git"