@dxos/react-ui-stack 0.8.4-main.c1de068 → 0.8.4-main.c351d160a8

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.
Files changed (107) hide show
  1. package/dist/lib/browser/index.mjs +743 -57
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/playwright/index.mjs +4 -0
  5. package/dist/lib/browser/playwright/index.mjs.map +2 -2
  6. package/dist/lib/node-esm/index.mjs +744 -57
  7. package/dist/lib/node-esm/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/meta.json +1 -1
  9. package/dist/lib/node-esm/playwright/index.mjs +4 -0
  10. package/dist/lib/node-esm/playwright/index.mjs.map +2 -2
  11. package/dist/types/src/components/Stack/Stack.d.ts +17 -9
  12. package/dist/types/src/components/Stack/Stack.d.ts.map +1 -1
  13. package/dist/types/src/components/Stack/Stack.stories.d.ts +12 -3
  14. package/dist/types/src/components/Stack/Stack.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/StackContext.d.ts +2 -1
  16. package/dist/types/src/components/StackContext.d.ts.map +1 -1
  17. package/dist/types/src/components/StackItem/MenuSignifier.d.ts.map +1 -1
  18. package/dist/types/src/components/StackItem/StackItem.d.ts +11 -14
  19. package/dist/types/src/components/StackItem/StackItem.d.ts.map +1 -1
  20. package/dist/types/src/components/StackItem/StackItem.stories.d.ts +13 -5
  21. package/dist/types/src/components/StackItem/StackItem.stories.d.ts.map +1 -1
  22. package/dist/types/src/components/StackItem/StackItemContent.d.ts +4 -37
  23. package/dist/types/src/components/StackItem/StackItemContent.d.ts.map +1 -1
  24. package/dist/types/src/components/StackItem/StackItemDragHandle.d.ts.map +1 -1
  25. package/dist/types/src/components/StackItem/StackItemHeading.d.ts +2 -2
  26. package/dist/types/src/components/StackItem/StackItemHeading.d.ts.map +1 -1
  27. package/dist/types/src/components/StackItem/StackItemResizeHandle.d.ts +1 -1
  28. package/dist/types/src/components/StackItem/StackItemResizeHandle.d.ts.map +1 -1
  29. package/dist/types/src/components/StackItem/StackItemSigil.d.ts +2 -2
  30. package/dist/types/src/components/StackItem/StackItemSigil.d.ts.map +1 -1
  31. package/dist/types/src/components/index.d.ts +1 -1
  32. package/dist/types/src/components/index.d.ts.map +1 -1
  33. package/dist/types/src/components/{defs.d.ts → types.d.ts} +1 -1
  34. package/dist/types/src/components/types.d.ts.map +1 -0
  35. package/dist/types/src/hooks/useStackDropForElements.d.ts +9 -7
  36. package/dist/types/src/hooks/useStackDropForElements.d.ts.map +1 -1
  37. package/dist/types/src/index.d.ts +0 -1
  38. package/dist/types/src/index.d.ts.map +1 -1
  39. package/dist/types/src/translations.d.ts +2 -2
  40. package/dist/types/src/translations.d.ts.map +1 -1
  41. package/dist/types/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +41 -38
  43. package/src/components/Stack/Stack.stories.tsx +8 -9
  44. package/src/components/Stack/Stack.tsx +230 -31
  45. package/src/components/StackContext.tsx +2 -1
  46. package/src/components/StackItem/MenuSignifier.tsx +2 -9
  47. package/src/components/StackItem/StackItem.stories.tsx +21 -17
  48. package/src/components/StackItem/StackItem.tsx +50 -30
  49. package/src/components/StackItem/StackItemContent.tsx +25 -44
  50. package/src/components/StackItem/StackItemDragHandle.tsx +4 -3
  51. package/src/components/StackItem/StackItemHeading.tsx +17 -20
  52. package/src/components/StackItem/StackItemResizeHandle.tsx +3 -2
  53. package/src/components/StackItem/StackItemSigil.tsx +10 -6
  54. package/src/components/index.ts +2 -1
  55. package/src/hooks/useStackDropForElements.ts +59 -45
  56. package/src/index.ts +0 -3
  57. package/src/playwright/playwright.config.ts +1 -1
  58. package/src/translations.ts +1 -1
  59. package/dist/lib/browser/chunk-P3TQV4BA.mjs +0 -1198
  60. package/dist/lib/browser/chunk-P3TQV4BA.mjs.map +0 -7
  61. package/dist/lib/browser/testing/index.mjs +0 -31
  62. package/dist/lib/browser/testing/index.mjs.map +0 -7
  63. package/dist/lib/node-esm/chunk-3WVEPAJ4.mjs +0 -1200
  64. package/dist/lib/node-esm/chunk-3WVEPAJ4.mjs.map +0 -7
  65. package/dist/lib/node-esm/testing/index.mjs +0 -32
  66. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  67. package/dist/types/src/components/defs.d.ts.map +0 -1
  68. package/dist/types/src/components/deprecated/LayoutControls.d.ts +0 -19
  69. package/dist/types/src/components/deprecated/LayoutControls.d.ts.map +0 -1
  70. package/dist/types/src/exemplars/Card/Card.d.ts +0 -58
  71. package/dist/types/src/exemplars/Card/Card.d.ts.map +0 -1
  72. package/dist/types/src/exemplars/Card/Card.stories.d.ts +0 -13
  73. package/dist/types/src/exemplars/Card/Card.stories.d.ts.map +0 -1
  74. package/dist/types/src/exemplars/Card/CardDragPreview.d.ts +0 -6
  75. package/dist/types/src/exemplars/Card/CardDragPreview.d.ts.map +0 -1
  76. package/dist/types/src/exemplars/Card/fragments.d.ts +0 -12
  77. package/dist/types/src/exemplars/Card/fragments.d.ts.map +0 -1
  78. package/dist/types/src/exemplars/Card/index.d.ts +0 -4
  79. package/dist/types/src/exemplars/Card/index.d.ts.map +0 -1
  80. package/dist/types/src/exemplars/CardStack/CardStack.d.ts +0 -40
  81. package/dist/types/src/exemplars/CardStack/CardStack.d.ts.map +0 -1
  82. package/dist/types/src/exemplars/CardStack/CardStack.stories.d.ts +0 -9
  83. package/dist/types/src/exemplars/CardStack/CardStack.stories.d.ts.map +0 -1
  84. package/dist/types/src/exemplars/CardStack/CardStackDragPreview.d.ts +0 -9
  85. package/dist/types/src/exemplars/CardStack/CardStackDragPreview.d.ts.map +0 -1
  86. package/dist/types/src/exemplars/CardStack/index.d.ts +0 -3
  87. package/dist/types/src/exemplars/CardStack/index.d.ts.map +0 -1
  88. package/dist/types/src/exemplars/index.d.ts +0 -3
  89. package/dist/types/src/exemplars/index.d.ts.map +0 -1
  90. package/dist/types/src/testing/CardContainer.d.ts +0 -6
  91. package/dist/types/src/testing/CardContainer.d.ts.map +0 -1
  92. package/dist/types/src/testing/index.d.ts +0 -2
  93. package/dist/types/src/testing/index.d.ts.map +0 -1
  94. package/src/components/deprecated/LayoutControls.tsx +0 -109
  95. package/src/exemplars/Card/Card.stories.tsx +0 -78
  96. package/src/exemplars/Card/Card.tsx +0 -186
  97. package/src/exemplars/Card/CardDragPreview.tsx +0 -22
  98. package/src/exemplars/Card/fragments.ts +0 -23
  99. package/src/exemplars/Card/index.ts +0 -7
  100. package/src/exemplars/CardStack/CardStack.stories.tsx +0 -172
  101. package/src/exemplars/CardStack/CardStack.tsx +0 -136
  102. package/src/exemplars/CardStack/CardStackDragPreview.tsx +0 -61
  103. package/src/exemplars/CardStack/index.ts +0 -6
  104. package/src/exemplars/index.ts +0 -6
  105. package/src/testing/CardContainer.tsx +0 -34
  106. package/src/testing/index.ts +0 -5
  107. /package/src/components/{defs.ts → types.ts} +0 -0
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-stack",
3
- "version": "0.8.4-main.c1de068",
3
+ "version": "0.8.4-main.c351d160a8",
4
4
  "description": "A stack component.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
- "sideEffects": true,
13
+ "sideEffects": false,
10
14
  "type": "module",
11
15
  "exports": {
12
16
  ".": {
@@ -18,11 +22,6 @@
18
22
  "types": "./dist/types/src/playwright/index.d.ts",
19
23
  "browser": "./dist/lib/browser/playwright/index.mjs",
20
24
  "node": "./dist/lib/node-esm/playwright/index.mjs"
21
- },
22
- "./testing": {
23
- "types": "./dist/types/src/testing/index.d.ts",
24
- "browser": "./dist/lib/browser/testing/index.mjs",
25
- "node": "./dist/lib/node-esm/testing/index.mjs"
26
25
  }
27
26
  },
28
27
  "types": "dist/types/src/index.d.ts",
@@ -41,11 +40,11 @@
41
40
  "src"
42
41
  ],
43
42
  "dependencies": {
44
- "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
45
- "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.0",
46
- "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.3",
47
- "@fluentui/react-tabster": "^9.24.2",
48
- "@preact-signals/safe-react": "^0.9.0",
43
+ "@atlaskit/pragmatic-drag-and-drop": "1.7.7",
44
+ "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.2",
45
+ "@atlaskit/pragmatic-drag-and-drop-hitbox": "1.1.0",
46
+ "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "3.2.10",
47
+ "@fluentui/react-tabster": "9.26.11",
49
48
  "@radix-ui/primitive": "1.1.1",
50
49
  "@radix-ui/react-compose-refs": "1.1.1",
51
50
  "@radix-ui/react-context": "1.1.1",
@@ -54,36 +53,40 @@
54
53
  "@radix-ui/react-slot": "1.1.2",
55
54
  "@radix-ui/react-use-controllable-state": "1.1.0",
56
55
  "react-resize-detector": "^11.0.1",
57
- "@dxos/echo-schema": "0.8.4-main.c1de068",
58
- "@dxos/keyboard": "0.8.4-main.c1de068",
59
- "@dxos/live-object": "0.8.4-main.c1de068",
60
- "@dxos/react-ui-attention": "0.8.4-main.c1de068",
61
- "@dxos/react-ui-dnd": "0.8.4-main.c1de068",
62
- "@dxos/storybook-utils": "0.8.4-main.c1de068",
63
- "@dxos/util": "0.8.4-main.c1de068"
56
+ "@dxos/keyboard": "0.8.4-main.c351d160a8",
57
+ "@dxos/echo": "0.8.4-main.c351d160a8",
58
+ "@dxos/react-ui-attention": "0.8.4-main.c351d160a8",
59
+ "@dxos/react-ui-dnd": "0.8.4-main.c351d160a8",
60
+ "@dxos/react-ui-mosaic": "0.8.4-main.c351d160a8",
61
+ "@dxos/util": "0.8.4-main.c351d160a8"
64
62
  },
65
63
  "devDependencies": {
66
- "@types/react": "~18.2.0",
67
- "@types/react-dom": "~18.2.0",
68
- "react": "~18.2.0",
69
- "react-dom": "~18.2.0",
70
- "vite": "5.4.7",
71
- "@dxos/app-graph": "0.8.4-main.c1de068",
72
- "@dxos/echo-schema": "0.8.4-main.c1de068",
73
- "@dxos/client": "0.8.4-main.c1de068",
74
- "@dxos/random": "0.8.4-main.c1de068",
75
- "@dxos/react-ui": "0.8.4-main.c1de068",
76
- "@dxos/react-ui-theme": "0.8.4-main.c1de068",
77
- "@dxos/test-utils": "0.8.4-main.c1de068",
78
- "@dxos/storybook-utils": "0.8.4-main.c1de068"
64
+ "@types/react": "~19.2.7",
65
+ "@types/react-dom": "~19.2.3",
66
+ "react": "~19.2.3",
67
+ "react-dom": "~19.2.3",
68
+ "vite": "^7.1.11",
69
+ "@dxos/app-graph": "0.8.4-main.c351d160a8",
70
+ "@dxos/app-framework": "0.8.4-main.c351d160a8",
71
+ "@dxos/client": "0.8.4-main.c351d160a8",
72
+ "@dxos/echo-db": "0.8.4-main.c351d160a8",
73
+ "@dxos/echo": "0.8.4-main.c351d160a8",
74
+ "@dxos/random": "0.8.4-main.c351d160a8",
75
+ "@dxos/react-client": "0.8.4-main.c351d160a8",
76
+ "@dxos/react-ui": "0.8.4-main.c351d160a8",
77
+ "@dxos/schema": "0.8.4-main.c351d160a8",
78
+ "@dxos/storybook-utils": "0.8.4-main.c351d160a8",
79
+ "@dxos/test-utils": "0.8.4-main.c351d160a8",
80
+ "@dxos/types": "0.8.4-main.c351d160a8",
81
+ "@dxos/ui-theme": "0.8.4-main.c351d160a8"
79
82
  },
80
83
  "peerDependencies": {
81
- "react": "~18.2.0",
82
- "react-dom": "~18.2.0",
83
- "@dxos/client": "0.8.4-main.c1de068",
84
- "@dxos/react-ui": "0.8.4-main.c1de068",
85
- "@dxos/random": "0.8.4-main.c1de068",
86
- "@dxos/react-ui-theme": "0.8.4-main.c1de068"
84
+ "react": "~19.2.3",
85
+ "react-dom": "~19.2.3",
86
+ "@dxos/client": "0.8.4-main.c351d160a8",
87
+ "@dxos/ui-theme": "0.8.4-main.c351d160a8",
88
+ "@dxos/react-ui": "0.8.4-main.c351d160a8",
89
+ "@dxos/random": "0.8.4-main.c351d160a8"
87
90
  },
88
91
  "publishConfig": {
89
92
  "access": "public"
@@ -2,18 +2,17 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
8
6
  import { type Meta, type StoryObj } from '@storybook/react-vite';
9
- import React, { useState, useCallback } from 'react';
7
+ import React, { useCallback, useState } from 'react';
10
8
 
11
9
  import { faker } from '@dxos/random';
12
- import { withTheme } from '@dxos/storybook-utils';
10
+ import { withTheme } from '@dxos/react-ui/testing';
13
11
 
14
- import { Stack } from './Stack';
15
12
  import { StackItem } from '../StackItem';
16
- import { type StackItemData } from '../defs';
13
+ import { type StackItemData } from '../types';
14
+
15
+ import { Stack } from './Stack';
17
16
 
18
17
  type StoryStackItem = {
19
18
  id: string;
@@ -129,12 +128,12 @@ const DefaultStory = () => {
129
128
  );
130
129
  };
131
130
 
132
- const meta: Meta<typeof DefaultStory> = {
131
+ const meta = {
133
132
  title: 'ui/react-ui-stack/Stack',
134
133
  component: DefaultStory,
135
- decorators: [withTheme],
136
134
  argTypes: { orientation: { control: 'radio', options: ['horizontal', 'vertical'] } },
137
- };
135
+ decorators: [withTheme()],
136
+ } satisfies Meta<typeof DefaultStory>;
138
137
 
139
138
  export default meta;
140
139
 
@@ -2,47 +2,67 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { useArrowNavigationGroup } from '@fluentui/react-tabster';
6
5
  import { composeRefs } from '@radix-ui/react-compose-refs';
7
6
  import React, {
8
- Children,
9
7
  type CSSProperties,
8
+ Children,
10
9
  type ComponentPropsWithRef,
10
+ type FocusEvent,
11
+ type KeyboardEvent,
11
12
  forwardRef,
12
- useState,
13
- useMemo,
14
13
  useCallback,
15
14
  useEffect,
15
+ useMemo,
16
+ useState,
16
17
  } from 'react';
17
18
 
18
- import { type ThemedClassName, ListItem } from '@dxos/react-ui';
19
- import { mx } from '@dxos/react-ui-theme';
19
+ import { ListItem, type ThemedClassName, useId } from '@dxos/react-ui';
20
+ import { mx } from '@dxos/ui-theme';
20
21
 
21
22
  import { useStackDropForElements } from '../../hooks';
22
23
  import { StackContext } from '../StackContext';
23
- import { type StackContextValue } from '../defs';
24
+ import { type StackContextValue } from '../types';
24
25
 
25
26
  export type Orientation = 'horizontal' | 'vertical';
26
- export type Size = 'intrinsic' | 'contain' | 'contain-fit-content';
27
27
 
28
- export type StackProps = Omit<ThemedClassName<ComponentPropsWithRef<'div'>>, 'aria-orientation'> &
29
- Partial<StackContextValue> & {
30
- itemsCount?: number;
31
- getDropElement?: (stackElement: HTMLDivElement) => HTMLDivElement;
32
- separatorOnScroll?: number;
33
- };
28
+ /**
29
+ * Size is how Stack and its StackItems coordinate the dimensions of the items with the available space.
30
+ * - `intrinsic` signals to Stack and its StackItems to occupy their intrinsic size
31
+ * - Any other size will extrinsically fill the available space along the axis of its orientation and handle overflow:
32
+ * - `contain` causes StackItems to occupy their intrinsic size
33
+ * - `split` divides the Stack’s available space among the StackItems
34
+ */
35
+ export type Size = 'intrinsic' | 'contain' | 'split';
34
36
 
35
- export const railGridHorizontal = 'grid-rows-[[rail-start]_var(--rail-size)_[content-start]_1fr_[content-end]]';
36
- export const railGridVertical = 'grid-cols-[[rail-start]_var(--rail-size)_[content-start]_1fr_[content-end]]';
37
+ export const railGridHorizontal = 'grid-rows-[[rail-start]_var(--dx-rail-size)_[content-start]_1fr_[content-end]]';
38
+ export const railGridVertical = 'grid-cols-[[rail-start]_var(--dx-rail-size)_[content-start]_1fr_[content-end]]';
37
39
 
38
- // TODO(ZaymonFC): Magic 2px to stop overflow (tabster dummies... ask @thure).
40
+ // TODO(ZaymonFC): Magic 2px to stop overflow.
39
41
  export const railGridHorizontalContainFitContent =
40
- 'grid-rows-[[rail-start]_var(--rail-size)_[content-start]_fit-content(calc(100%-var(--rail-size)*2+2px))_[content-end]]';
42
+ 'grid-rows-[[rail-start]_var(--dx-rail-size)_[content-start]_fit-content(calc(100%-var(--dx-rail-size)*2+2px))_[content-end]]';
41
43
  export const railGridVerticalContainFitContent =
42
- 'grid-cols-[[rail-start]_var(--rail-size)_[content-start]_fit-content(calc(100%-var(--rail-size)*2+2px))_[content-end]]';
44
+ 'grid-cols-[[rail-start]_var(--dx-rail-size)_[content-start]_fit-content(calc(100%-var(--dx-rail-size)*2+2px))_[content-end]]';
43
45
 
44
46
  export const autoScrollRootAttributes = { 'data-drag-autoscroll': 'idle' };
45
47
 
48
+ const PERPENDICULAR_FOCUS_THRESHHOLD = 128;
49
+
50
+ const scrollIntoViewAndFocus = (el: HTMLElement, orientation: StackProps['orientation']) => {
51
+ el.scrollIntoView({
52
+ behavior: 'instant',
53
+ [orientation === 'vertical' ? 'block' : 'inline']: 'center',
54
+ });
55
+ return el.focus();
56
+ };
57
+
58
+ export type StackProps = Omit<ThemedClassName<ComponentPropsWithRef<'div'>>, 'aria-orientation'> &
59
+ Partial<StackContextValue> & {
60
+ itemsCount?: number;
61
+ getDropElement?: (stackElement: HTMLDivElement) => HTMLDivElement;
62
+ separatorOnScroll?: number;
63
+ circularFocus?: boolean;
64
+ };
65
+
46
66
  export const Stack = forwardRef<HTMLDivElement, StackProps>(
47
67
  (
48
68
  {
@@ -50,23 +70,25 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
50
70
  classNames,
51
71
  style,
52
72
  orientation = 'vertical',
53
- rail = true,
73
+ rail = true, // TODO(burdon): Change default to false.
54
74
  size = 'intrinsic',
55
75
  onRearrange,
56
76
  itemsCount = Children.count(children),
57
77
  getDropElement,
58
78
  separatorOnScroll,
79
+ circularFocus,
59
80
  ...props
60
81
  },
61
82
  forwardedRef,
62
83
  ) => {
84
+ const stackId = useId('stack', props.id);
63
85
  const [stackElement, stackRef] = useState<HTMLDivElement | null>(null);
86
+ const [lastFocusedItem, setLastFocusedItem] = useState<string>();
64
87
  const composedItemRef = composeRefs<HTMLDivElement>(stackRef, forwardedRef);
65
- const arrowNavigationAttrs = useArrowNavigationGroup({ axis: orientation });
66
88
 
67
89
  const styles: CSSProperties = {
68
90
  [orientation === 'horizontal' ? 'gridTemplateColumns' : 'gridTemplateRows']:
69
- `repeat(${itemsCount}, min-content) [tabster-dummies] 0`,
91
+ size === 'split' ? `repeat(${itemsCount}, 1fr)` : `repeat(${itemsCount}, min-content) [tabster-dummies] 0`,
70
92
  ...style,
71
93
  };
72
94
 
@@ -97,14 +119,187 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
97
119
  }
98
120
  }, [stackElement, separatorOnScroll, orientation]);
99
121
 
122
+ /**
123
+ * Handles blur events to track the last focused item within this stack.
124
+ */
125
+ const handleBlur = useCallback(
126
+ (event: FocusEvent<HTMLDivElement>) => {
127
+ if (event.target) {
128
+ const target = event.target as HTMLElement;
129
+ const closestStackItem = target.closest(`[data-dx-item-id]`) as HTMLElement | null;
130
+ if (closestStackItem?.closest(`[data-dx-stack="${stackId}"]`)) {
131
+ setLastFocusedItem(closestStackItem?.getAttribute('data-dx-item-id') ?? undefined);
132
+ }
133
+ }
134
+ props.onBlur?.(event);
135
+ },
136
+ [stackId, props.onBlur],
137
+ );
138
+
139
+ /**
140
+ * Handles moving focus using the arrow keys. Focus is only handled by the nearest stack;
141
+ * if the arrow key matches the orientation, focus cycles between items, otherwise focus is passed to an adjacent stack item;
142
+ * or, if there is no such stack item, focus is passed to the adjacent empty stack if one can be found.
143
+ */
144
+ const handleKeyDown = useCallback(
145
+ (event: KeyboardEvent<HTMLDivElement>) => {
146
+ const target = event.target as HTMLElement;
147
+ if (
148
+ event.key.startsWith('Arrow') &&
149
+ !target.closest(
150
+ `input, textarea, [role="textbox"], [data-tabster*="mover"], [data-arrow-keys="all"], [data-arrow-keys~="${event.key.toLowerCase().slice(5)}"]`,
151
+ )
152
+ ) {
153
+ const closestOwnedItem = target.closest(`[data-dx-stack-item="${stackId}"]`);
154
+ const closestStack = target.closest('[data-dx-stack]') as HTMLElement | null;
155
+ const closestStackItems = Array.from(
156
+ closestStack?.querySelectorAll(`[data-dx-stack-item="${stackId}"]`) ?? [],
157
+ );
158
+ const closestStackOrientation = closestStack?.getAttribute('aria-orientation') as Orientation;
159
+ const ancestorStack = closestStack?.parentElement?.closest('[data-dx-stack]') as HTMLElement | null;
160
+ if (closestOwnedItem && closestStack) {
161
+ const ancestorOrientation = ancestorStack?.getAttribute('aria-orientation') as Orientation | undefined;
162
+ const parallelDelta = (
163
+ closestStackOrientation === 'vertical' ? event.key === 'ArrowUp' : event.key === 'ArrowLeft'
164
+ )
165
+ ? -1
166
+ : (closestStackOrientation === 'vertical' ? event.key === 'ArrowDown' : event.key === 'ArrowRight')
167
+ ? 1
168
+ : 0;
169
+ const perpendicularDelta = (
170
+ closestStackOrientation === 'vertical' ? event.key === 'ArrowLeft' : event.key === 'ArrowUp'
171
+ )
172
+ ? -1
173
+ : (closestStackOrientation === 'vertical' ? event.key === 'ArrowRight' : event.key === 'ArrowDown')
174
+ ? 1
175
+ : 0;
176
+ if (parallelDelta !== 0) {
177
+ const currentIndex = closestStackItems.indexOf(closestOwnedItem);
178
+ const nextIndex = currentIndex + parallelDelta;
179
+ let adjacentItem: HTMLElement | undefined;
180
+
181
+ if (circularFocus) {
182
+ // Circular navigation: wrap around using modulo.
183
+ adjacentItem = closestStackItems[(nextIndex + closestStackItems.length) % closestStackItems.length] as
184
+ | HTMLElement
185
+ | undefined;
186
+ } else {
187
+ // Non-circular navigation: only move if within bounds.
188
+ if (nextIndex >= 0 && nextIndex < closestStackItems.length) {
189
+ adjacentItem = closestStackItems[nextIndex] as HTMLElement | undefined;
190
+ }
191
+ }
192
+
193
+ if (adjacentItem) {
194
+ event.preventDefault();
195
+ scrollIntoViewAndFocus(adjacentItem, closestStackOrientation);
196
+ }
197
+ }
198
+
199
+ if (perpendicularDelta !== 0) {
200
+ if (ancestorStack && ancestorOrientation !== closestStackOrientation) {
201
+ const siblingStacks = Array.from(
202
+ ancestorStack.querySelectorAll(
203
+ `[data-dx-stack-item="${ancestorStack.getAttribute('data-dx-stack')}"] [data-dx-stack]`,
204
+ ),
205
+ ) as HTMLElement[];
206
+ const currentStackIndex = siblingStacks.indexOf(closestStack);
207
+ const nextStackIndex = currentStackIndex + perpendicularDelta;
208
+ let adjacentStack: HTMLElement | undefined;
209
+
210
+ if (ancestorStack.getAttribute('data-dx-stack-circular-focus') === 'true') {
211
+ // Circular navigation: wrap around using modulo.
212
+ adjacentStack = siblingStacks[(nextStackIndex + siblingStacks.length) % siblingStacks.length] as
213
+ | HTMLElement
214
+ | undefined;
215
+ } else {
216
+ // Non-circular navigation: only move if within bounds.
217
+ if (nextStackIndex >= 0 && nextStackIndex < siblingStacks.length) {
218
+ adjacentStack = siblingStacks[nextStackIndex] as HTMLElement | undefined;
219
+ }
220
+ }
221
+ const adjacentStackSelfItem = adjacentStack?.closest(
222
+ `[data-dx-stack-item=${ancestorStack.getAttribute('data-dx-stack')}]`,
223
+ ) as HTMLElement | undefined;
224
+ const adjacentStackItems = adjacentStack
225
+ ? (Array.from(
226
+ adjacentStack.querySelectorAll(
227
+ `[data-dx-stack-item="${adjacentStack.getAttribute('data-dx-stack')}"]`,
228
+ ),
229
+ ) as HTMLElement[])
230
+ : [];
231
+ if (adjacentStack && adjacentStackItems.length > 0) {
232
+ // Check if the adjacent stack has a last focused item recorded, otherwise find the closest item by position.
233
+ let closestItem = adjacentStackItems[0];
234
+ // Try to find an item with matching data-dx-stack-item value.
235
+ const lastFocusedItem = adjacentStack.querySelector(
236
+ `[data-dx-item-id="${adjacentStack.getAttribute('data-dx-last-focused-item') ?? 'never'}"]`,
237
+ );
238
+ if (lastFocusedItem) {
239
+ closestItem = lastFocusedItem as HTMLElement;
240
+ } else {
241
+ // Fall back to positional calculation
242
+ const ownedItemRect = closestOwnedItem.getBoundingClientRect();
243
+ const targetPosition =
244
+ closestStackOrientation === 'vertical' ? ownedItemRect.top : ownedItemRect.left;
245
+
246
+ let closestDistance = Infinity;
247
+ for (const item of adjacentStackItems) {
248
+ const itemRect = item.getBoundingClientRect();
249
+ const itemPosition = closestStackOrientation === 'vertical' ? itemRect.top : itemRect.left;
250
+ const distance = Math.abs(itemPosition - targetPosition);
251
+ if (distance < closestDistance) {
252
+ closestDistance = distance;
253
+ closestItem = item;
254
+ }
255
+ if (closestDistance <= PERPENDICULAR_FOCUS_THRESHHOLD) {
256
+ break;
257
+ }
258
+ }
259
+ }
260
+
261
+ event.preventDefault();
262
+ scrollIntoViewAndFocus(closestItem, closestStackOrientation);
263
+ } else if (adjacentStackSelfItem) {
264
+ event.preventDefault();
265
+ scrollIntoViewAndFocus(adjacentStackSelfItem, ancestorOrientation);
266
+ }
267
+ } else if (closestOwnedItem) {
268
+ const closestOwnedItemStack = closestOwnedItem.querySelector('[data-dx-stack]');
269
+ const closestOwnedItemStackItems = closestOwnedItemStack
270
+ ? (Array.from(
271
+ closestOwnedItemStack.querySelectorAll(
272
+ `[data-dx-stack-item="${closestOwnedItemStack.getAttribute('data-dx-stack')}"]`,
273
+ ),
274
+ ) as HTMLElement[])
275
+ : [];
276
+ if (closestOwnedItemStackItems.length > 0) {
277
+ event.preventDefault();
278
+ scrollIntoViewAndFocus(
279
+ closestOwnedItemStackItems[
280
+ ['ArrowUp', 'ArrowLeft'].includes(event.key) ? closestOwnedItemStackItems.length - 1 : 0
281
+ ],
282
+ closestOwnedItemStack?.getAttribute('aria-orientation') as Orientation,
283
+ );
284
+ }
285
+ }
286
+ }
287
+ }
288
+ }
289
+ props.onKeyDown?.(event);
290
+ },
291
+ [props.onKeyDown, stackId, circularFocus],
292
+ );
293
+
100
294
  const gridClasses = useMemo(() => {
101
295
  if (!rail) {
102
- return orientation === 'horizontal' ? 'grid-rows-1 pli-1' : 'grid-cols-1 plb-1';
296
+ return orientation === 'horizontal' ? 'grid-rows-1 px-(--stack-gap)' : 'grid-cols-1 py-(--stack-gap)';
103
297
  }
298
+
104
299
  if (orientation === 'horizontal') {
105
- return size === 'contain-fit-content' ? railGridHorizontalContainFitContent : railGridHorizontal;
300
+ return railGridHorizontal;
106
301
  } else {
107
- return size === 'contain-fit-content' ? railGridVerticalContainFitContent : railGridVertical;
302
+ return railGridVertical;
108
303
  }
109
304
  }, [rail, orientation, size]);
110
305
 
@@ -125,19 +320,23 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
125
320
  }, [stackElement, handleScroll]);
126
321
 
127
322
  return (
128
- <StackContext.Provider value={{ orientation, rail, size, onRearrange }}>
323
+ <StackContext.Provider value={{ orientation, rail, size, onRearrange, stackId }}>
129
324
  <div
130
325
  {...props}
131
- {...arrowNavigationAttrs}
132
326
  className={mx(
133
- 'grid relative',
327
+ 'grid relative [--stack-gap:var(--spacing-trim-xs)]',
134
328
  gridClasses,
135
- (size === 'contain' || size === 'contain-fit-content') &&
329
+ size === 'contain' &&
136
330
  (orientation === 'horizontal'
137
- ? 'overflow-x-auto min-bs-0 max-bs-full bs-full'
138
- : 'overflow-y-auto min-is-0 max-is-full is-full'),
331
+ ? 'overflow-x-auto overscroll-x-contain min-h-0 max-h-full h-full'
332
+ : 'overflow-y-auto min-w-0 max-w-full w-full'),
139
333
  classNames,
140
334
  )}
335
+ onKeyDown={handleKeyDown}
336
+ onBlur={handleBlur}
337
+ data-dx-stack={stackId}
338
+ data-dx-stack-circular-focus={circularFocus}
339
+ data-dx-last-focused-item={lastFocusedItem}
141
340
  data-rail={rail}
142
341
  aria-orientation={orientation}
143
342
  style={styles}
@@ -5,13 +5,14 @@
5
5
  import { createContext, useContext } from 'react';
6
6
 
7
7
  import { type Orientation, type Size } from './Stack';
8
- import { type StackItemSize, type StackItemRearrangeHandler } from './defs';
8
+ import { type StackItemRearrangeHandler, type StackItemSize } from './types';
9
9
 
10
10
  export type StackContextValue = {
11
11
  orientation: Orientation;
12
12
  rail: boolean;
13
13
  size: Size;
14
14
  onRearrange?: StackItemRearrangeHandler;
15
+ stackId?: string;
15
16
  };
16
17
 
17
18
  export const StackContext = createContext<StackContextValue>({
@@ -5,14 +5,7 @@
5
5
  import React from 'react';
6
6
 
7
7
  export const MenuSignifierHorizontal = () => (
8
- <svg
9
- className='absolute block-end-[7px]'
10
- width={20}
11
- height={2}
12
- viewBox='0 0 20 2'
13
- stroke='currentColor'
14
- opacity={0.5}
15
- >
8
+ <svg className='absolute bottom-[7px]' width={20} height={2} viewBox='0 0 20 2' stroke='currentColor' opacity={0.5}>
16
9
  <line
17
10
  x1={0.5}
18
11
  y1={0.75}
@@ -27,7 +20,7 @@ export const MenuSignifierHorizontal = () => (
27
20
  );
28
21
 
29
22
  export const MenuSignifierVertical = () => (
30
- <svg className='absolute inline-start-1' width={2} height={18} viewBox='0 0 2 18' stroke='currentColor'>
23
+ <svg className='absolute left-1' width={2} height={18} viewBox='0 0 2 18' stroke='currentColor'>
31
24
  <line x1={1} y1={3} x2={1} y2={18} strokeWidth={1.5} strokeLinecap='round' strokeDasharray='0 6' />
32
25
  </svg>
33
26
  );
@@ -2,24 +2,20 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
6
  import React from 'react';
9
7
 
10
- import { Icon, DropdownMenu } from '@dxos/react-ui';
11
- import { withTheme } from '@dxos/storybook-utils';
8
+ import { DropdownMenu, Icon } from '@dxos/react-ui';
9
+ import { withTheme } from '@dxos/react-ui/testing';
12
10
 
13
- import { StackItem } from './StackItem';
11
+ import { StackItem, type StackItemRootProps } from './StackItem';
14
12
 
15
- const meta: Meta<typeof StackItem.Root> = {
16
- title: 'ui/react-ui-stack/StackItem',
17
- component: StackItem.Root,
18
- render: (args) => (
19
- <StackItem.Root role='section' {...args} classNames='w-[20rem] border border-separator'>
20
- <StackItem.Heading>
13
+ const DefaultStory = (props: StackItemRootProps) => {
14
+ return (
15
+ <StackItem.Root role='section' {...props} classNames='w-[20rem] border border-separator'>
16
+ <StackItem.Heading classNames='w-full border-b border-separator'>
21
17
  <span className='sr-only'>Title</span>
22
- <div role='none' className='sticky -block-start-px bg-[--sticky-bg] p-1 is-full'>
18
+ <div role='none' className='sticky -top-px bg-(--sticky-bg) p-1 w-full'>
23
19
  <DropdownMenu.Root>
24
20
  <DropdownMenu.Trigger asChild>
25
21
  <StackItem.SigilButton>
@@ -29,18 +25,26 @@ const meta: Meta<typeof StackItem.Root> = {
29
25
  </DropdownMenu.Root>
30
26
  </div>
31
27
  </StackItem.Heading>
32
- <StackItem.Content classNames='p-2'>Content</StackItem.Content>
28
+ <StackItem.Content>
29
+ <div className='p-4 text-center'>Content</div>
30
+ </StackItem.Content>
33
31
  </StackItem.Root>
34
- ),
35
- decorators: [withTheme],
32
+ );
33
+ };
34
+
35
+ const meta = {
36
+ title: 'ui/react-ui-stack/StackItem',
37
+ component: StackItem.Root as any,
38
+ render: DefaultStory,
39
+ decorators: [withTheme()],
36
40
  parameters: {
37
41
  layout: 'centered',
38
42
  },
39
- };
43
+ } satisfies Meta<typeof DefaultStory>;
40
44
 
41
45
  export default meta;
42
46
 
43
- type Story = StoryObj<typeof StackItem.Root>;
47
+ type Story = StoryObj<typeof meta>;
44
48
 
45
49
  export const Default: Story = {
46
50
  args: {