@dxos/react-ui-stack 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6
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/dist/lib/browser/index.mjs +723 -60
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/playwright/index.mjs +4 -0
- package/dist/lib/browser/playwright/index.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +724 -60
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/playwright/index.mjs +4 -0
- package/dist/lib/node-esm/playwright/index.mjs.map +2 -2
- package/dist/types/src/components/Stack/Stack.d.ts +13 -10
- package/dist/types/src/components/Stack/Stack.d.ts.map +1 -1
- package/dist/types/src/components/Stack/Stack.stories.d.ts +12 -3
- package/dist/types/src/components/Stack/Stack.stories.d.ts.map +1 -1
- package/dist/types/src/components/StackContext.d.ts +2 -1
- package/dist/types/src/components/StackContext.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/MenuSignifier.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItem.d.ts +11 -14
- package/dist/types/src/components/StackItem/StackItem.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItem.stories.d.ts +13 -5
- package/dist/types/src/components/StackItem/StackItem.stories.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemContent.d.ts +4 -37
- package/dist/types/src/components/StackItem/StackItemContent.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemDragHandle.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemHeading.d.ts +2 -2
- package/dist/types/src/components/StackItem/StackItemHeading.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemResizeHandle.d.ts +1 -1
- package/dist/types/src/components/StackItem/StackItemResizeHandle.d.ts.map +1 -1
- package/dist/types/src/components/StackItem/StackItemSigil.d.ts +2 -2
- package/dist/types/src/components/StackItem/StackItemSigil.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/{defs.d.ts → types.d.ts} +1 -1
- package/dist/types/src/components/types.d.ts.map +1 -0
- package/dist/types/src/hooks/useStackDropForElements.d.ts +9 -7
- package/dist/types/src/hooks/useStackDropForElements.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +10 -10
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +41 -38
- package/src/components/Stack/Stack.stories.tsx +9 -11
- package/src/components/Stack/Stack.tsx +239 -53
- package/src/components/StackContext.tsx +2 -1
- package/src/components/StackItem/MenuSignifier.tsx +2 -9
- package/src/components/StackItem/StackItem.stories.tsx +22 -18
- package/src/components/StackItem/StackItem.tsx +50 -30
- package/src/components/StackItem/StackItemContent.tsx +25 -44
- package/src/components/StackItem/StackItemDragHandle.tsx +4 -3
- package/src/components/StackItem/StackItemHeading.tsx +17 -20
- package/src/components/StackItem/StackItemResizeHandle.tsx +3 -2
- package/src/components/StackItem/StackItemSigil.tsx +11 -7
- package/src/components/index.ts +2 -1
- package/src/hooks/useStackDropForElements.ts +59 -45
- package/src/index.ts +0 -3
- package/src/playwright/playwright.config.ts +1 -1
- package/src/translations.ts +9 -9
- package/dist/lib/browser/chunk-P3TQV4BA.mjs +0 -1198
- package/dist/lib/browser/chunk-P3TQV4BA.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -31
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3WVEPAJ4.mjs +0 -1200
- package/dist/lib/node-esm/chunk-3WVEPAJ4.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -32
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/components/defs.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/LayoutControls.d.ts +0 -19
- package/dist/types/src/components/deprecated/LayoutControls.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/Card.d.ts +0 -58
- package/dist/types/src/exemplars/Card/Card.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/Card.stories.d.ts +0 -13
- package/dist/types/src/exemplars/Card/Card.stories.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/CardDragPreview.d.ts +0 -6
- package/dist/types/src/exemplars/Card/CardDragPreview.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/fragments.d.ts +0 -12
- package/dist/types/src/exemplars/Card/fragments.d.ts.map +0 -1
- package/dist/types/src/exemplars/Card/index.d.ts +0 -4
- package/dist/types/src/exemplars/Card/index.d.ts.map +0 -1
- package/dist/types/src/exemplars/CardStack/CardStack.d.ts +0 -40
- package/dist/types/src/exemplars/CardStack/CardStack.d.ts.map +0 -1
- package/dist/types/src/exemplars/CardStack/CardStack.stories.d.ts +0 -9
- package/dist/types/src/exemplars/CardStack/CardStack.stories.d.ts.map +0 -1
- package/dist/types/src/exemplars/CardStack/CardStackDragPreview.d.ts +0 -9
- package/dist/types/src/exemplars/CardStack/CardStackDragPreview.d.ts.map +0 -1
- package/dist/types/src/exemplars/CardStack/index.d.ts +0 -3
- package/dist/types/src/exemplars/CardStack/index.d.ts.map +0 -1
- package/dist/types/src/exemplars/index.d.ts +0 -3
- package/dist/types/src/exemplars/index.d.ts.map +0 -1
- package/dist/types/src/testing/CardContainer.d.ts +0 -6
- package/dist/types/src/testing/CardContainer.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/src/components/deprecated/LayoutControls.tsx +0 -109
- package/src/exemplars/Card/Card.stories.tsx +0 -78
- package/src/exemplars/Card/Card.tsx +0 -186
- package/src/exemplars/Card/CardDragPreview.tsx +0 -22
- package/src/exemplars/Card/fragments.ts +0 -23
- package/src/exemplars/Card/index.ts +0 -7
- package/src/exemplars/CardStack/CardStack.stories.tsx +0 -172
- package/src/exemplars/CardStack/CardStack.tsx +0 -136
- package/src/exemplars/CardStack/CardStackDragPreview.tsx +0 -61
- package/src/exemplars/CardStack/index.ts +0 -6
- package/src/exemplars/index.ts +0 -6
- package/src/testing/CardContainer.tsx +0 -34
- package/src/testing/index.ts +0 -5
- /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.
|
|
3
|
+
"version": "0.8.4-main.bcb3aa67d6",
|
|
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":
|
|
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": "
|
|
45
|
-
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.
|
|
46
|
-
"@atlaskit/pragmatic-drag-and-drop-hitbox": "
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
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
|
|
58
|
-
"@dxos/keyboard": "0.8.4-main.
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/react-ui-attention": "0.8.4-main.b97322e"
|
|
56
|
+
"@dxos/echo": "0.8.4-main.bcb3aa67d6",
|
|
57
|
+
"@dxos/keyboard": "0.8.4-main.bcb3aa67d6",
|
|
58
|
+
"@dxos/react-ui-dnd": "0.8.4-main.bcb3aa67d6",
|
|
59
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.bcb3aa67d6",
|
|
60
|
+
"@dxos/util": "0.8.4-main.bcb3aa67d6",
|
|
61
|
+
"@dxos/react-ui-attention": "0.8.4-main.bcb3aa67d6"
|
|
64
62
|
},
|
|
65
63
|
"devDependencies": {
|
|
66
|
-
"@types/react": "~
|
|
67
|
-
"@types/react-dom": "~
|
|
68
|
-
"react": "~
|
|
69
|
-
"react-dom": "~
|
|
70
|
-
"vite": "
|
|
71
|
-
"@dxos/app-
|
|
72
|
-
"@dxos/client": "0.8.4-main.
|
|
73
|
-
"@dxos/echo
|
|
74
|
-
"@dxos/
|
|
75
|
-
"@dxos/
|
|
76
|
-
"@dxos/
|
|
77
|
-
"@dxos/react-ui
|
|
78
|
-
"@dxos/
|
|
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-framework": "0.8.4-main.bcb3aa67d6",
|
|
70
|
+
"@dxos/client": "0.8.4-main.bcb3aa67d6",
|
|
71
|
+
"@dxos/echo": "0.8.4-main.bcb3aa67d6",
|
|
72
|
+
"@dxos/app-graph": "0.8.4-main.bcb3aa67d6",
|
|
73
|
+
"@dxos/echo-db": "0.8.4-main.bcb3aa67d6",
|
|
74
|
+
"@dxos/random": "0.8.4-main.bcb3aa67d6",
|
|
75
|
+
"@dxos/react-ui": "0.8.4-main.bcb3aa67d6",
|
|
76
|
+
"@dxos/react-client": "0.8.4-main.bcb3aa67d6",
|
|
77
|
+
"@dxos/schema": "0.8.4-main.bcb3aa67d6",
|
|
78
|
+
"@dxos/storybook-utils": "0.8.4-main.bcb3aa67d6",
|
|
79
|
+
"@dxos/test-utils": "0.8.4-main.bcb3aa67d6",
|
|
80
|
+
"@dxos/types": "0.8.4-main.bcb3aa67d6",
|
|
81
|
+
"@dxos/ui-theme": "0.8.4-main.bcb3aa67d6"
|
|
79
82
|
},
|
|
80
83
|
"peerDependencies": {
|
|
81
|
-
"react": "~
|
|
82
|
-
"react-dom": "~
|
|
83
|
-
"@dxos/
|
|
84
|
-
"@dxos/
|
|
85
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
86
|
-
"@dxos/
|
|
84
|
+
"react": "~19.2.3",
|
|
85
|
+
"react-dom": "~19.2.3",
|
|
86
|
+
"@dxos/random": "0.8.4-main.bcb3aa67d6",
|
|
87
|
+
"@dxos/client": "0.8.4-main.bcb3aa67d6",
|
|
88
|
+
"@dxos/react-ui": "0.8.4-main.bcb3aa67d6",
|
|
89
|
+
"@dxos/ui-theme": "0.8.4-main.bcb3aa67d6"
|
|
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, {
|
|
7
|
+
import React, { useCallback, useState } from 'react';
|
|
10
8
|
|
|
11
9
|
import { faker } from '@dxos/random';
|
|
12
|
-
import { withTheme } from '@dxos/
|
|
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 '../
|
|
13
|
+
import { type StackItemData } from '../types';
|
|
14
|
+
|
|
15
|
+
import { Stack } from './Stack';
|
|
17
16
|
|
|
18
17
|
type StoryStackItem = {
|
|
19
18
|
id: string;
|
|
@@ -23,7 +22,7 @@ type StoryStackItem = {
|
|
|
23
22
|
|
|
24
23
|
const KanbanBlock = ({ item }: { item: StoryStackItem }) => {
|
|
25
24
|
return (
|
|
26
|
-
<div className='overflow-hidden'>
|
|
25
|
+
<div role='none' className='overflow-hidden'>
|
|
27
26
|
<p className='place-content-center p-4'>{item.title}</p>
|
|
28
27
|
</div>
|
|
29
28
|
);
|
|
@@ -78,7 +77,6 @@ const DefaultStory = () => {
|
|
|
78
77
|
targetColumn.items
|
|
79
78
|
) {
|
|
80
79
|
const [movedCard] = sourceColumn.items.splice(sourceCardIndex, 1);
|
|
81
|
-
|
|
82
80
|
let insertIndex;
|
|
83
81
|
if (sourceColumn === targetColumn && sourceCardIndex < targetCardIndex) {
|
|
84
82
|
insertIndex = closestEdge === 'bottom' ? targetCardIndex : targetCardIndex - 1;
|
|
@@ -129,12 +127,12 @@ const DefaultStory = () => {
|
|
|
129
127
|
);
|
|
130
128
|
};
|
|
131
129
|
|
|
132
|
-
const meta
|
|
130
|
+
const meta = {
|
|
133
131
|
title: 'ui/react-ui-stack/Stack',
|
|
134
132
|
component: DefaultStory,
|
|
135
|
-
decorators: [withTheme],
|
|
136
133
|
argTypes: { orientation: { control: 'radio', options: ['horizontal', 'vertical'] } },
|
|
137
|
-
|
|
134
|
+
decorators: [withTheme()],
|
|
135
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
138
136
|
|
|
139
137
|
export default meta;
|
|
140
138
|
|
|
@@ -2,78 +2,86 @@
|
|
|
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
7
|
Children,
|
|
9
|
-
type CSSProperties,
|
|
10
8
|
type ComponentPropsWithRef,
|
|
9
|
+
type FocusEvent,
|
|
10
|
+
type KeyboardEvent,
|
|
11
11
|
forwardRef,
|
|
12
|
-
useState,
|
|
13
|
-
useMemo,
|
|
14
12
|
useCallback,
|
|
15
13
|
useEffect,
|
|
14
|
+
useState,
|
|
16
15
|
} from 'react';
|
|
17
16
|
|
|
18
|
-
import { type ThemedClassName,
|
|
19
|
-
import { mx } from '@dxos/
|
|
17
|
+
import { ListItem, type ThemedClassName, useId } from '@dxos/react-ui';
|
|
18
|
+
import { mx } from '@dxos/ui-theme';
|
|
20
19
|
|
|
21
20
|
import { useStackDropForElements } from '../../hooks';
|
|
22
21
|
import { StackContext } from '../StackContext';
|
|
23
|
-
import { type StackContextValue } from '../
|
|
22
|
+
import { type StackContextValue } from '../types';
|
|
24
23
|
|
|
25
24
|
export type Orientation = 'horizontal' | 'vertical';
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Size is how Stack and its StackItems coordinate the dimensions of the items with the available space.
|
|
28
|
+
* - `intrinsic` signals to Stack and its StackItems to occupy their intrinsic size
|
|
29
|
+
* - Any other size will extrinsically fill the available space along the axis of its orientation and handle overflow:
|
|
30
|
+
* - `contain` causes StackItems to occupy their intrinsic size
|
|
31
|
+
* - `split` divides the Stack’s available space among the StackItems
|
|
32
|
+
*/
|
|
33
|
+
export type Size = 'intrinsic' | 'contain' | 'split';
|
|
34
|
+
|
|
35
|
+
export const railGridHorizontal = 'grid-rows-[[rail-start]_var(--dx-rail-size)_[content-start]_1fr_[content-end]]';
|
|
36
|
+
export const railGridVertical = 'grid-cols-[[rail-start]_var(--dx-rail-size)_[content-start]_1fr_[content-end]]';
|
|
37
|
+
|
|
38
|
+
const PERPENDICULAR_FOCUS_THRESHHOLD = 128;
|
|
39
|
+
|
|
40
|
+
const scrollIntoViewAndFocus = (el: HTMLElement, orientation: StackProps['orientation']) => {
|
|
41
|
+
el.scrollIntoView({
|
|
42
|
+
behavior: 'instant',
|
|
43
|
+
[orientation === 'vertical' ? 'block' : 'inline']: 'center',
|
|
44
|
+
});
|
|
45
|
+
return el.focus();
|
|
46
|
+
};
|
|
27
47
|
|
|
28
48
|
export type StackProps = Omit<ThemedClassName<ComponentPropsWithRef<'div'>>, 'aria-orientation'> &
|
|
29
49
|
Partial<StackContextValue> & {
|
|
30
50
|
itemsCount?: number;
|
|
31
|
-
|
|
51
|
+
circularFocus?: boolean;
|
|
32
52
|
separatorOnScroll?: number;
|
|
53
|
+
getDropElement?: (stackElement: HTMLDivElement) => HTMLDivElement;
|
|
33
54
|
};
|
|
34
55
|
|
|
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
|
-
|
|
38
|
-
// TODO(ZaymonFC): Magic 2px to stop overflow (tabster dummies... ask @thure).
|
|
39
|
-
export const railGridHorizontalContainFitContent =
|
|
40
|
-
'grid-rows-[[rail-start]_var(--rail-size)_[content-start]_fit-content(calc(100%-var(--rail-size)*2+2px))_[content-end]]';
|
|
41
|
-
export const railGridVerticalContainFitContent =
|
|
42
|
-
'grid-cols-[[rail-start]_var(--rail-size)_[content-start]_fit-content(calc(100%-var(--rail-size)*2+2px))_[content-end]]';
|
|
43
|
-
|
|
44
|
-
export const autoScrollRootAttributes = { 'data-drag-autoscroll': 'idle' };
|
|
45
|
-
|
|
46
56
|
export const Stack = forwardRef<HTMLDivElement, StackProps>(
|
|
47
57
|
(
|
|
48
58
|
{
|
|
49
59
|
children,
|
|
50
60
|
classNames,
|
|
61
|
+
id,
|
|
51
62
|
style,
|
|
52
63
|
orientation = 'vertical',
|
|
53
64
|
rail = true,
|
|
54
65
|
size = 'intrinsic',
|
|
55
|
-
onRearrange,
|
|
56
66
|
itemsCount = Children.count(children),
|
|
57
|
-
|
|
67
|
+
circularFocus,
|
|
58
68
|
separatorOnScroll,
|
|
69
|
+
getDropElement,
|
|
70
|
+
onBlur,
|
|
71
|
+
onKeyDown,
|
|
72
|
+
onRearrange,
|
|
59
73
|
...props
|
|
60
74
|
},
|
|
61
75
|
forwardedRef,
|
|
62
76
|
) => {
|
|
77
|
+
const stackId = useId('stack', id);
|
|
63
78
|
const [stackElement, stackRef] = useState<HTMLDivElement | null>(null);
|
|
79
|
+
const [lastFocusedItem, setLastFocusedItem] = useState<string>();
|
|
64
80
|
const composedItemRef = composeRefs<HTMLDivElement>(stackRef, forwardedRef);
|
|
65
|
-
const arrowNavigationAttrs = useArrowNavigationGroup({ axis: orientation });
|
|
66
|
-
|
|
67
|
-
const styles: CSSProperties = {
|
|
68
|
-
[orientation === 'horizontal' ? 'gridTemplateColumns' : 'gridTemplateRows']:
|
|
69
|
-
`repeat(${itemsCount}, min-content) [tabster-dummies] 0`,
|
|
70
|
-
...style,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const selfDroppable = !!(itemsCount < 1 && onRearrange && props.id);
|
|
74
81
|
|
|
82
|
+
const selfDroppable = !!(itemsCount < 1 && onRearrange && id);
|
|
75
83
|
const { dropping } = useStackDropForElements({
|
|
76
|
-
id
|
|
84
|
+
id,
|
|
77
85
|
element: getDropElement && stackElement ? getDropElement(stackElement) : stackElement,
|
|
78
86
|
scrollElement: stackElement,
|
|
79
87
|
selfDroppable,
|
|
@@ -81,6 +89,7 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
|
|
|
81
89
|
onRearrange,
|
|
82
90
|
});
|
|
83
91
|
|
|
92
|
+
/** Updates scroll separator data attributes based on current scroll position. */
|
|
84
93
|
const handleScroll = useCallback(() => {
|
|
85
94
|
if (stackElement && Number.isFinite(separatorOnScroll)) {
|
|
86
95
|
const scrollPosition = orientation === 'horizontal' ? stackElement.scrollLeft : stackElement.scrollTop;
|
|
@@ -97,17 +106,25 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
|
|
|
97
106
|
}
|
|
98
107
|
}, [stackElement, separatorOnScroll, orientation]);
|
|
99
108
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
/** Handles blur events to track the last focused item within this stack. */
|
|
110
|
+
const handleBlur = useCallback(
|
|
111
|
+
(event: FocusEvent<HTMLDivElement>) => {
|
|
112
|
+
if (event.target) {
|
|
113
|
+
const target = event.target as HTMLElement;
|
|
114
|
+
const closestStackItem = target.closest(`[data-dx-item-id]`) as HTMLElement | null;
|
|
115
|
+
if (closestStackItem?.closest(`[data-dx-stack="${stackId}"]`)) {
|
|
116
|
+
setLastFocusedItem(closestStackItem?.getAttribute('data-dx-item-id') ?? undefined);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
onBlur?.(event);
|
|
120
|
+
},
|
|
121
|
+
[stackId, onBlur],
|
|
122
|
+
);
|
|
110
123
|
|
|
124
|
+
/** Handles keyboard navigation within the stack. */
|
|
125
|
+
const handleKeyDown = useKeyDown(stackId, circularFocus, onKeyDown);
|
|
126
|
+
|
|
127
|
+
/** Observes DOM mutations to keep scroll separator state in sync. */
|
|
111
128
|
useEffect(() => {
|
|
112
129
|
if (!(stackElement && Number.isFinite(separatorOnScroll))) {
|
|
113
130
|
return;
|
|
@@ -118,31 +135,46 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
|
|
|
118
135
|
});
|
|
119
136
|
|
|
120
137
|
observer.observe(stackElement, { childList: true, subtree: true });
|
|
121
|
-
|
|
122
138
|
return () => {
|
|
123
139
|
observer.disconnect();
|
|
124
140
|
};
|
|
125
141
|
}, [stackElement, handleScroll]);
|
|
126
142
|
|
|
127
143
|
return (
|
|
128
|
-
<StackContext.Provider value={{ orientation, rail, size, onRearrange }}>
|
|
144
|
+
<StackContext.Provider value={{ stackId, orientation, rail, size, onRearrange }}>
|
|
129
145
|
<div
|
|
130
146
|
{...props}
|
|
131
|
-
{...
|
|
147
|
+
{...(Number.isFinite(separatorOnScroll) && { onScroll: handleScroll })}
|
|
132
148
|
className={mx(
|
|
133
|
-
'grid
|
|
134
|
-
|
|
135
|
-
(size === 'contain' || size === 'contain-fit-content') &&
|
|
149
|
+
'relative grid [--stack-gap:var(--spacing-trim-xs)]',
|
|
150
|
+
size === 'contain' &&
|
|
136
151
|
(orientation === 'horizontal'
|
|
137
|
-
? 'overflow-x-auto min-
|
|
138
|
-
: 'overflow-y-auto min-
|
|
152
|
+
? 'overflow-x-auto overscroll-x-contain min-h-0 max-h-full h-full'
|
|
153
|
+
: 'overflow-y-auto min-w-0 max-w-full w-full'),
|
|
154
|
+
rail
|
|
155
|
+
? orientation === 'horizontal'
|
|
156
|
+
? railGridHorizontal
|
|
157
|
+
: railGridVertical
|
|
158
|
+
: orientation === 'horizontal'
|
|
159
|
+
? 'grid-rows-1 px-(--stack-gap)'
|
|
160
|
+
: 'grid-cols-1 py-(--stack-gap)',
|
|
139
161
|
classNames,
|
|
140
162
|
)}
|
|
141
|
-
|
|
163
|
+
style={{
|
|
164
|
+
[orientation === 'horizontal' ? 'gridTemplateColumns' : 'gridTemplateRows']:
|
|
165
|
+
size === 'split'
|
|
166
|
+
? `repeat(${itemsCount}, 1fr)`
|
|
167
|
+
: `repeat(${itemsCount}, min-content) [tabster-dummies] 0`,
|
|
168
|
+
...style,
|
|
169
|
+
}}
|
|
142
170
|
aria-orientation={orientation}
|
|
143
|
-
|
|
171
|
+
data-dx-stack={stackId}
|
|
172
|
+
data-dx-stack-circular-focus={circularFocus}
|
|
173
|
+
data-dx-last-focused-item={lastFocusedItem}
|
|
174
|
+
data-rail={rail}
|
|
175
|
+
onBlur={handleBlur}
|
|
176
|
+
onKeyDown={handleKeyDown}
|
|
144
177
|
ref={composedItemRef}
|
|
145
|
-
{...(Number.isFinite(separatorOnScroll) && { onScroll: handleScroll })}
|
|
146
178
|
>
|
|
147
179
|
{children}
|
|
148
180
|
{selfDroppable && dropping && (
|
|
@@ -162,3 +194,157 @@ export const Stack = forwardRef<HTMLDivElement, StackProps>(
|
|
|
162
194
|
export { StackContext };
|
|
163
195
|
|
|
164
196
|
export type { StackContextValue };
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Handles moving focus using the arrow keys. Focus is only handled by the nearest stack.
|
|
200
|
+
* If the arrow key matches the orientation, focus cycles between items, otherwise focus is passed to an adjacent stack item;
|
|
201
|
+
* Or if there is no such stack item, focus is passed to the adjacent empty stack if one can be found.
|
|
202
|
+
*/
|
|
203
|
+
// TODO(burdon): Replace with Mosaic.Stack which handles this automatically.
|
|
204
|
+
const useKeyDown = (stackId: string, circularFocus?: boolean, onKeyDown?: StackProps['onKeyDown']) =>
|
|
205
|
+
useCallback(
|
|
206
|
+
(event: KeyboardEvent<HTMLDivElement>) => {
|
|
207
|
+
const target = event.target as HTMLElement;
|
|
208
|
+
if (
|
|
209
|
+
event.key.startsWith('Arrow') &&
|
|
210
|
+
!target.closest(
|
|
211
|
+
`input, textarea, [role="textbox"], [data-tabster*="mover"], [data-arrow-keys="all"], [data-arrow-keys~="${event.key.toLowerCase().slice(5)}"]`,
|
|
212
|
+
)
|
|
213
|
+
) {
|
|
214
|
+
const closestOwnedItem = target.closest(`[data-dx-stack-item="${stackId}"]`);
|
|
215
|
+
const closestStack = target.closest('[data-dx-stack]') as HTMLElement | null;
|
|
216
|
+
const closestStackItems = Array.from(closestStack?.querySelectorAll(`[data-dx-stack-item="${stackId}"]`) ?? []);
|
|
217
|
+
const closestStackOrientation = closestStack?.getAttribute('aria-orientation') as Orientation;
|
|
218
|
+
const ancestorStack = closestStack?.parentElement?.closest('[data-dx-stack]') as HTMLElement | null;
|
|
219
|
+
if (closestOwnedItem && closestStack) {
|
|
220
|
+
const ancestorOrientation = ancestorStack?.getAttribute('aria-orientation') as Orientation | undefined;
|
|
221
|
+
const parallelDelta = (
|
|
222
|
+
closestStackOrientation === 'vertical' ? event.key === 'ArrowUp' : event.key === 'ArrowLeft'
|
|
223
|
+
)
|
|
224
|
+
? -1
|
|
225
|
+
: (closestStackOrientation === 'vertical' ? event.key === 'ArrowDown' : event.key === 'ArrowRight')
|
|
226
|
+
? 1
|
|
227
|
+
: 0;
|
|
228
|
+
const perpendicularDelta = (
|
|
229
|
+
closestStackOrientation === 'vertical' ? event.key === 'ArrowLeft' : event.key === 'ArrowUp'
|
|
230
|
+
)
|
|
231
|
+
? -1
|
|
232
|
+
: (closestStackOrientation === 'vertical' ? event.key === 'ArrowRight' : event.key === 'ArrowDown')
|
|
233
|
+
? 1
|
|
234
|
+
: 0;
|
|
235
|
+
if (parallelDelta !== 0) {
|
|
236
|
+
const currentIndex = closestStackItems.indexOf(closestOwnedItem);
|
|
237
|
+
const nextIndex = currentIndex + parallelDelta;
|
|
238
|
+
let adjacentItem: HTMLElement | undefined;
|
|
239
|
+
if (circularFocus) {
|
|
240
|
+
// Circular navigation: wrap around using modulo.
|
|
241
|
+
adjacentItem = closestStackItems[(nextIndex + closestStackItems.length) % closestStackItems.length] as
|
|
242
|
+
| HTMLElement
|
|
243
|
+
| undefined;
|
|
244
|
+
} else {
|
|
245
|
+
// Non-circular navigation: only move if within bounds.
|
|
246
|
+
if (nextIndex >= 0 && nextIndex < closestStackItems.length) {
|
|
247
|
+
adjacentItem = closestStackItems[nextIndex] as HTMLElement | undefined;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (adjacentItem) {
|
|
252
|
+
event.preventDefault();
|
|
253
|
+
scrollIntoViewAndFocus(adjacentItem, closestStackOrientation);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (perpendicularDelta !== 0) {
|
|
258
|
+
if (ancestorStack && ancestorOrientation !== closestStackOrientation) {
|
|
259
|
+
const siblingStacks = Array.from(
|
|
260
|
+
ancestorStack.querySelectorAll(
|
|
261
|
+
`[data-dx-stack-item="${ancestorStack.getAttribute('data-dx-stack')}"] [data-dx-stack]`,
|
|
262
|
+
),
|
|
263
|
+
) as HTMLElement[];
|
|
264
|
+
const currentStackIndex = siblingStacks.indexOf(closestStack);
|
|
265
|
+
const nextStackIndex = currentStackIndex + perpendicularDelta;
|
|
266
|
+
let adjacentStack: HTMLElement | undefined;
|
|
267
|
+
|
|
268
|
+
if (ancestorStack.getAttribute('data-dx-stack-circular-focus') === 'true') {
|
|
269
|
+
// Circular navigation: wrap around using modulo.
|
|
270
|
+
adjacentStack = siblingStacks[(nextStackIndex + siblingStacks.length) % siblingStacks.length] as
|
|
271
|
+
| HTMLElement
|
|
272
|
+
| undefined;
|
|
273
|
+
} else {
|
|
274
|
+
// Non-circular navigation: only move if within bounds.
|
|
275
|
+
if (nextStackIndex >= 0 && nextStackIndex < siblingStacks.length) {
|
|
276
|
+
adjacentStack = siblingStacks[nextStackIndex] as HTMLElement | undefined;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const adjacentStackSelfItem = adjacentStack?.closest(
|
|
280
|
+
`[data-dx-stack-item=${ancestorStack.getAttribute('data-dx-stack')}]`,
|
|
281
|
+
) as HTMLElement | undefined;
|
|
282
|
+
const adjacentStackItems = adjacentStack
|
|
283
|
+
? (Array.from(
|
|
284
|
+
adjacentStack.querySelectorAll(
|
|
285
|
+
`[data-dx-stack-item="${adjacentStack.getAttribute('data-dx-stack')}"]`,
|
|
286
|
+
),
|
|
287
|
+
) as HTMLElement[])
|
|
288
|
+
: [];
|
|
289
|
+
if (adjacentStack && adjacentStackItems.length > 0) {
|
|
290
|
+
// Check if the adjacent stack has a last focused item recorded, otherwise find the closest item by position.
|
|
291
|
+
let closestItem = adjacentStackItems[0];
|
|
292
|
+
// Try to find an item with matching data-dx-stack-item value.
|
|
293
|
+
const lastFocusedItem = adjacentStack.querySelector(
|
|
294
|
+
`[data-dx-item-id="${adjacentStack.getAttribute('data-dx-last-focused-item') ?? 'never'}"]`,
|
|
295
|
+
);
|
|
296
|
+
if (lastFocusedItem) {
|
|
297
|
+
closestItem = lastFocusedItem as HTMLElement;
|
|
298
|
+
} else {
|
|
299
|
+
// Fall back to positional calculation
|
|
300
|
+
const ownedItemRect = closestOwnedItem.getBoundingClientRect();
|
|
301
|
+
const targetPosition =
|
|
302
|
+
closestStackOrientation === 'vertical' ? ownedItemRect.top : ownedItemRect.left;
|
|
303
|
+
|
|
304
|
+
let closestDistance = Infinity;
|
|
305
|
+
for (const item of adjacentStackItems) {
|
|
306
|
+
const itemRect = item.getBoundingClientRect();
|
|
307
|
+
const itemPosition = closestStackOrientation === 'vertical' ? itemRect.top : itemRect.left;
|
|
308
|
+
const distance = Math.abs(itemPosition - targetPosition);
|
|
309
|
+
if (distance < closestDistance) {
|
|
310
|
+
closestDistance = distance;
|
|
311
|
+
closestItem = item;
|
|
312
|
+
}
|
|
313
|
+
if (closestDistance <= PERPENDICULAR_FOCUS_THRESHHOLD) {
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
event.preventDefault();
|
|
320
|
+
scrollIntoViewAndFocus(closestItem, closestStackOrientation);
|
|
321
|
+
} else if (adjacentStackSelfItem) {
|
|
322
|
+
event.preventDefault();
|
|
323
|
+
scrollIntoViewAndFocus(adjacentStackSelfItem, ancestorOrientation);
|
|
324
|
+
}
|
|
325
|
+
} else if (closestOwnedItem) {
|
|
326
|
+
const closestOwnedItemStack = closestOwnedItem.querySelector('[data-dx-stack]');
|
|
327
|
+
const closestOwnedItemStackItems = closestOwnedItemStack
|
|
328
|
+
? (Array.from(
|
|
329
|
+
closestOwnedItemStack.querySelectorAll(
|
|
330
|
+
`[data-dx-stack-item="${closestOwnedItemStack.getAttribute('data-dx-stack')}"]`,
|
|
331
|
+
),
|
|
332
|
+
) as HTMLElement[])
|
|
333
|
+
: [];
|
|
334
|
+
if (closestOwnedItemStackItems.length > 0) {
|
|
335
|
+
event.preventDefault();
|
|
336
|
+
scrollIntoViewAndFocus(
|
|
337
|
+
closestOwnedItemStackItems[
|
|
338
|
+
['ArrowUp', 'ArrowLeft'].includes(event.key) ? closestOwnedItemStackItems.length - 1 : 0
|
|
339
|
+
],
|
|
340
|
+
closestOwnedItemStack?.getAttribute('aria-orientation') as Orientation,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
onKeyDown?.(event);
|
|
348
|
+
},
|
|
349
|
+
[onKeyDown, stackId, circularFocus],
|
|
350
|
+
);
|
|
@@ -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
|
|
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
|
|
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,45 +2,49 @@
|
|
|
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 {
|
|
11
|
-
import { withTheme } from '@dxos/
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 -
|
|
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>
|
|
26
|
-
<Icon icon='ph--dots-three--regular'
|
|
22
|
+
<Icon icon='ph--dots-three--regular' />
|
|
27
23
|
</StackItem.SigilButton>
|
|
28
24
|
</DropdownMenu.Trigger>
|
|
29
25
|
</DropdownMenu.Root>
|
|
30
26
|
</div>
|
|
31
27
|
</StackItem.Heading>
|
|
32
|
-
<StackItem.Content
|
|
28
|
+
<StackItem.Content>
|
|
29
|
+
<div className='p-4 text-center'>Content</div>
|
|
30
|
+
</StackItem.Content>
|
|
33
31
|
</StackItem.Root>
|
|
34
|
-
)
|
|
35
|
-
|
|
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
|
|
47
|
+
type Story = StoryObj<typeof meta>;
|
|
44
48
|
|
|
45
49
|
export const Default: Story = {
|
|
46
50
|
args: {
|