@dxos/react-ui-stack 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5
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 +545 -1003
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{testing → playwright}/index.mjs +5 -1
- package/dist/lib/browser/{testing → playwright}/index.mjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +545 -1003
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{testing → playwright}/index.mjs +5 -1
- package/dist/lib/node-esm/{testing → playwright}/index.mjs.map +3 -3
- 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 +14 -17
- 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/playwright/index.d.ts.map +1 -0
- package/dist/types/src/playwright/stack-manager.d.ts.map +1 -0
- 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 +48 -39
- package/src/components/Stack/Stack.stories.tsx +15 -18
- 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 +61 -43
- 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 +2 -2
- package/src/components/StackItem/StackItemSigil.tsx +10 -7
- package/src/components/index.ts +2 -1
- package/src/hooks/useStackDropForElements.ts +61 -47
- package/src/index.ts +0 -3
- package/src/{testing → playwright}/index.ts +1 -1
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +1 -1
- package/src/translations.ts +9 -9
- 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 -57
- 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/index.d.ts.map +0 -1
- package/dist/types/src/testing/stack-manager.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 -167
- 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/dist/types/src/{testing → playwright}/index.d.ts +0 -0
- /package/dist/types/src/{testing → playwright}/stack-manager.d.ts +0 -0
- /package/src/components/{defs.ts → types.ts} +0 -0
- /package/src/{testing → playwright}/stack-manager.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.fcfe5033a5",
|
|
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
|
".": {
|
|
@@ -14,18 +18,18 @@
|
|
|
14
18
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
19
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
20
|
},
|
|
17
|
-
"./
|
|
18
|
-
"types": "./dist/types/src/
|
|
19
|
-
"browser": "./dist/lib/browser/
|
|
20
|
-
"node":
|
|
21
|
-
"require": "./dist/lib/node/testing/index.cjs",
|
|
22
|
-
"default": "./dist/lib/node-esm/testing/index.mjs"
|
|
23
|
-
}
|
|
21
|
+
"./playwright": {
|
|
22
|
+
"types": "./dist/types/src/playwright/index.d.ts",
|
|
23
|
+
"browser": "./dist/lib/browser/playwright/index.mjs",
|
|
24
|
+
"node": "./dist/lib/node-esm/playwright/index.mjs"
|
|
24
25
|
}
|
|
25
26
|
},
|
|
26
27
|
"types": "dist/types/src/index.d.ts",
|
|
27
28
|
"typesVersions": {
|
|
28
29
|
"*": {
|
|
30
|
+
"playwright": [
|
|
31
|
+
"dist/types/src/playwright/index.d.ts"
|
|
32
|
+
],
|
|
29
33
|
"testing": [
|
|
30
34
|
"dist/types/src/testing/index.d.ts"
|
|
31
35
|
]
|
|
@@ -36,11 +40,11 @@
|
|
|
36
40
|
"src"
|
|
37
41
|
],
|
|
38
42
|
"dependencies": {
|
|
39
|
-
"@atlaskit/pragmatic-drag-and-drop": "
|
|
40
|
-
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.
|
|
41
|
-
"@atlaskit/pragmatic-drag-and-drop-hitbox": "
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
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",
|
|
44
48
|
"@radix-ui/primitive": "1.1.1",
|
|
45
49
|
"@radix-ui/react-compose-refs": "1.1.1",
|
|
46
50
|
"@radix-ui/react-context": "1.1.1",
|
|
@@ -49,35 +53,40 @@
|
|
|
49
53
|
"@radix-ui/react-slot": "1.1.2",
|
|
50
54
|
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
51
55
|
"react-resize-detector": "^11.0.1",
|
|
52
|
-
"@dxos/echo
|
|
53
|
-
"@dxos/keyboard": "0.8.4-main.
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/react-ui-attention": "0.8.4-main.
|
|
56
|
-
"@dxos/util": "0.8.4-main.
|
|
57
|
-
"@dxos/react-ui-
|
|
56
|
+
"@dxos/echo": "0.8.4-main.fcfe5033a5",
|
|
57
|
+
"@dxos/keyboard": "0.8.4-main.fcfe5033a5",
|
|
58
|
+
"@dxos/react-ui-dnd": "0.8.4-main.fcfe5033a5",
|
|
59
|
+
"@dxos/react-ui-attention": "0.8.4-main.fcfe5033a5",
|
|
60
|
+
"@dxos/util": "0.8.4-main.fcfe5033a5",
|
|
61
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.fcfe5033a5"
|
|
58
62
|
},
|
|
59
63
|
"devDependencies": {
|
|
60
|
-
"@types/react": "~
|
|
61
|
-
"@types/react-dom": "~
|
|
62
|
-
"react": "~
|
|
63
|
-
"react-dom": "~
|
|
64
|
-
"vite": "
|
|
65
|
-
"@dxos/app-
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@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.fcfe5033a5",
|
|
70
|
+
"@dxos/client": "0.8.4-main.fcfe5033a5",
|
|
71
|
+
"@dxos/echo": "0.8.4-main.fcfe5033a5",
|
|
72
|
+
"@dxos/random": "0.8.4-main.fcfe5033a5",
|
|
73
|
+
"@dxos/echo-db": "0.8.4-main.fcfe5033a5",
|
|
74
|
+
"@dxos/app-graph": "0.8.4-main.fcfe5033a5",
|
|
75
|
+
"@dxos/react-client": "0.8.4-main.fcfe5033a5",
|
|
76
|
+
"@dxos/react-ui": "0.8.4-main.fcfe5033a5",
|
|
77
|
+
"@dxos/schema": "0.8.4-main.fcfe5033a5",
|
|
78
|
+
"@dxos/storybook-utils": "0.8.4-main.fcfe5033a5",
|
|
79
|
+
"@dxos/test-utils": "0.8.4-main.fcfe5033a5",
|
|
80
|
+
"@dxos/types": "0.8.4-main.fcfe5033a5",
|
|
81
|
+
"@dxos/ui-theme": "0.8.4-main.fcfe5033a5"
|
|
73
82
|
},
|
|
74
83
|
"peerDependencies": {
|
|
75
|
-
"react": "~
|
|
76
|
-
"react-dom": "~
|
|
77
|
-
"@dxos/
|
|
78
|
-
"@dxos/
|
|
79
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
80
|
-
"@dxos/
|
|
84
|
+
"react": "~19.2.3",
|
|
85
|
+
"react-dom": "~19.2.3",
|
|
86
|
+
"@dxos/random": "0.8.4-main.fcfe5033a5",
|
|
87
|
+
"@dxos/client": "0.8.4-main.fcfe5033a5",
|
|
88
|
+
"@dxos/react-ui": "0.8.4-main.fcfe5033a5",
|
|
89
|
+
"@dxos/ui-theme": "0.8.4-main.fcfe5033a5"
|
|
81
90
|
},
|
|
82
91
|
"publishConfig": {
|
|
83
92
|
"access": "public"
|
|
@@ -2,18 +2,16 @@
|
|
|
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
|
-
import {
|
|
12
|
-
import { withTheme } from '@dxos/
|
|
9
|
+
import { random } from '@dxos/random';
|
|
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
|
+
import { Stack } from './Stack';
|
|
17
15
|
|
|
18
16
|
type StoryStackItem = {
|
|
19
17
|
id: string;
|
|
@@ -23,7 +21,7 @@ type StoryStackItem = {
|
|
|
23
21
|
|
|
24
22
|
const KanbanBlock = ({ item }: { item: StoryStackItem }) => {
|
|
25
23
|
return (
|
|
26
|
-
<div className='overflow-hidden'>
|
|
24
|
+
<div role='none' className='overflow-hidden'>
|
|
27
25
|
<p className='place-content-center p-4'>{item.title}</p>
|
|
28
26
|
</div>
|
|
29
27
|
);
|
|
@@ -31,16 +29,16 @@ const KanbanBlock = ({ item }: { item: StoryStackItem }) => {
|
|
|
31
29
|
|
|
32
30
|
const DefaultStory = () => {
|
|
33
31
|
const [columns, setColumns] = useState<StoryStackItem[]>(
|
|
34
|
-
|
|
32
|
+
random.helpers.multiple(
|
|
35
33
|
() =>
|
|
36
34
|
({
|
|
37
|
-
id:
|
|
38
|
-
title:
|
|
39
|
-
items:
|
|
35
|
+
id: random.string.uuid(),
|
|
36
|
+
title: random.lorem.paragraph(),
|
|
37
|
+
items: random.helpers.multiple(
|
|
40
38
|
() =>
|
|
41
39
|
({
|
|
42
|
-
id:
|
|
43
|
-
title:
|
|
40
|
+
id: random.string.uuid(),
|
|
41
|
+
title: random.lorem.paragraph(),
|
|
44
42
|
}) satisfies StoryStackItem,
|
|
45
43
|
{ count: { min: 32, max: 64 } },
|
|
46
44
|
),
|
|
@@ -78,7 +76,6 @@ const DefaultStory = () => {
|
|
|
78
76
|
targetColumn.items
|
|
79
77
|
) {
|
|
80
78
|
const [movedCard] = sourceColumn.items.splice(sourceCardIndex, 1);
|
|
81
|
-
|
|
82
79
|
let insertIndex;
|
|
83
80
|
if (sourceColumn === targetColumn && sourceCardIndex < targetCardIndex) {
|
|
84
81
|
insertIndex = closestEdge === 'bottom' ? targetCardIndex : targetCardIndex - 1;
|
|
@@ -129,12 +126,12 @@ const DefaultStory = () => {
|
|
|
129
126
|
);
|
|
130
127
|
};
|
|
131
128
|
|
|
132
|
-
const meta
|
|
129
|
+
const meta = {
|
|
133
130
|
title: 'ui/react-ui-stack/Stack',
|
|
134
131
|
component: DefaultStory,
|
|
135
|
-
decorators: [withTheme],
|
|
136
132
|
argTypes: { orientation: { control: 'radio', options: ['horizontal', 'vertical'] } },
|
|
137
|
-
|
|
133
|
+
decorators: [withTheme()],
|
|
134
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
138
135
|
|
|
139
136
|
export default meta;
|
|
140
137
|
|
|
@@ -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
|
);
|