@dxos/react-ui-masonry 0.8.4-main.fcfe5033a5 → 0.8.4-staging.60fe92afc8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-masonry",
3
- "version": "0.8.4-main.fcfe5033a5",
3
+ "version": "0.8.4-staging.60fe92afc8",
4
4
  "description": "A masonry component.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -8,7 +8,7 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/dxos/dxos"
10
10
  },
11
- "license": "MIT",
11
+ "license": "FSL-1.1-Apache-2.0",
12
12
  "author": "DXOS.org",
13
13
  "sideEffects": false,
14
14
  "type": "module",
@@ -26,41 +26,42 @@
26
26
  "src"
27
27
  ],
28
28
  "dependencies": {
29
+ "@fluentui/react-tabster": "9.26.11",
29
30
  "@radix-ui/react-compose-refs": "1.1.1",
30
31
  "@radix-ui/react-context": "1.1.1",
31
32
  "@virtuoso.dev/masonry": "^1.4.2",
32
33
  "react-resize-detector": "^11.0.1",
33
- "@dxos/react-hooks": "0.8.4-main.fcfe5033a5",
34
- "@dxos/types": "0.8.4-main.fcfe5033a5",
35
- "@dxos/react-ui-mosaic": "0.8.4-main.fcfe5033a5",
36
- "@dxos/ui-types": "0.8.4-main.fcfe5033a5"
34
+ "@dxos/react-hooks": "0.8.4-staging.60fe92afc8",
35
+ "@dxos/types": "0.8.4-staging.60fe92afc8",
36
+ "@dxos/react-ui-mosaic": "0.8.4-staging.60fe92afc8",
37
+ "@dxos/ui-types": "0.8.4-staging.60fe92afc8"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@types/react": "~19.2.7",
40
41
  "@types/react-dom": "~19.2.3",
41
- "effect": "3.20.0",
42
+ "effect": "3.21.3",
42
43
  "react": "~19.2.3",
43
44
  "react-dom": "~19.2.3",
44
- "vite": "^7.1.11",
45
- "@dxos/echo": "0.8.4-main.fcfe5033a5",
46
- "@dxos/client": "0.8.4-main.fcfe5033a5",
47
- "@dxos/random": "0.8.4-main.fcfe5033a5",
48
- "@dxos/react-ui-form": "0.8.4-main.fcfe5033a5",
49
- "@dxos/react-client": "0.8.4-main.fcfe5033a5",
50
- "@dxos/react-ui": "0.8.4-main.fcfe5033a5",
51
- "@dxos/storybook-utils": "0.8.4-main.fcfe5033a5",
52
- "@dxos/schema": "0.8.4-main.fcfe5033a5",
53
- "@dxos/ui-theme": "0.8.4-main.fcfe5033a5",
54
- "@dxos/react-ui-stack": "0.8.4-main.fcfe5033a5",
55
- "@dxos/test-utils": "0.8.4-main.fcfe5033a5"
45
+ "vite": "^8.0.16",
46
+ "@dxos/client": "0.8.4-staging.60fe92afc8",
47
+ "@dxos/echo": "0.8.4-staging.60fe92afc8",
48
+ "@dxos/react-client": "0.8.4-staging.60fe92afc8",
49
+ "@dxos/react-ui": "0.8.4-staging.60fe92afc8",
50
+ "@dxos/react-ui-stack": "0.8.4-staging.60fe92afc8",
51
+ "@dxos/schema": "0.8.4-staging.60fe92afc8",
52
+ "@dxos/storybook-utils": "0.8.4-staging.60fe92afc8",
53
+ "@dxos/random": "0.8.4-staging.60fe92afc8",
54
+ "@dxos/test-utils": "0.8.4-staging.60fe92afc8",
55
+ "@dxos/ui-theme": "0.8.4-staging.60fe92afc8",
56
+ "@dxos/react-ui-form": "0.8.4-staging.60fe92afc8"
56
57
  },
57
58
  "peerDependencies": {
58
- "effect": "3.20.0",
59
+ "effect": "3.21.3",
59
60
  "react": "~19.2.3",
60
61
  "react-dom": "~19.2.3",
61
- "@dxos/react-ui": "0.8.4-main.fcfe5033a5",
62
- "@dxos/random": "0.8.4-main.fcfe5033a5",
63
- "@dxos/ui-theme": "0.8.4-main.fcfe5033a5"
62
+ "@dxos/random": "0.8.4-staging.60fe92afc8",
63
+ "@dxos/ui-theme": "0.8.4-staging.60fe92afc8",
64
+ "@dxos/react-ui": "0.8.4-staging.60fe92afc8"
64
65
  },
65
66
  "publishConfig": {
66
67
  "access": "public"
@@ -5,7 +5,7 @@
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
6
  import React from 'react';
7
7
 
8
- import { Filter } from '@dxos/client/echo';
8
+ import { Filter } from '@dxos/echo';
9
9
  import { random } from '@dxos/random';
10
10
  import { useQuery } from '@dxos/react-client/echo';
11
11
  import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
@@ -19,15 +19,15 @@ import { Masonry, MasonryRootProps } from './Masonry';
19
19
  const StoryItem = ({ data: { image, name, description } }: { data: Organization.Organization }) => {
20
20
  return (
21
21
  <Card.Root>
22
- <Card.Toolbar>
22
+ <Card.Header>
23
23
  <Card.Icon icon='ph--building-office--regular' />
24
24
  <Card.Title>{name}</Card.Title>
25
- </Card.Toolbar>
25
+ </Card.Header>
26
26
  <Card.Poster alt={name!} {...(image ? { image } : { icon: 'ph--building-office--regular' })} />
27
27
  {description && (
28
- <Card.Section classNames='px-2 pb-2'>
28
+ <Card.Row fullWidth classNames='px-2 pb-2'>
29
29
  <Card.Text variant='description'>{description}</Card.Text>
30
- </Card.Section>
30
+ </Card.Row>
31
31
  )}
32
32
  </Card.Root>
33
33
  );
@@ -39,7 +39,9 @@ const DefaultStory = (props: MasonryRootProps) => {
39
39
 
40
40
  return (
41
41
  <Masonry.Root {...props} Tile={StoryItem}>
42
- <Masonry.Content items={organizations} />
42
+ <Masonry.Content>
43
+ <Masonry.Viewport items={organizations} />
44
+ </Masonry.Content>
43
45
  </Masonry.Root>
44
46
  );
45
47
  };
package/src/Masonry.tsx CHANGED
@@ -2,6 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import { useArrowNavigationGroup } from '@fluentui/react-tabster';
5
6
  import { useComposedRefs } from '@radix-ui/react-compose-refs';
6
7
  import { createContext } from '@radix-ui/react-context';
7
8
  import { VirtuosoMasonry, type VirtuosoMasonryProps } from '@virtuoso.dev/masonry';
@@ -9,7 +10,8 @@ import React, { type ComponentType, type JSX, type PropsWithChildren, type Ref,
9
10
  import { useResizeDetector } from 'react-resize-detector';
10
11
 
11
12
  import { ScrollArea, ScrollAreaRootProps, ThemedClassName, usePx } from '@dxos/react-ui';
12
- import { cardMaxInlineSize, cardMinInlineSize, composable, composableProps, scrollbar } from '@dxos/ui-theme';
13
+ import { composable, composableProps, scrollbar } from '@dxos/react-ui';
14
+ import { cardMaxInlineSize, cardMinInlineSize } from '@dxos/ui-theme';
13
15
 
14
16
  //
15
17
  // Context
@@ -34,6 +36,13 @@ const MASONRY_NAME = 'Masonry';
34
36
 
35
37
  const [MasonryProvider, useMasonryContext] = createContext<MasonryContextValue>(MASONRY_NAME);
36
38
 
39
+ /** Content-scoped context: measured width of the ScrollArea.Root, shared with Viewport. */
40
+ type MasonryContentContextValue = {
41
+ width: number;
42
+ };
43
+
44
+ const [MasonryContentProvider, useMasonryContentContext] = createContext<MasonryContentContextValue>('Masonry.Content');
45
+
37
46
  //
38
47
  // Root
39
48
  //
@@ -66,25 +75,60 @@ MasonryRoot.displayName = 'Masonry.Root';
66
75
  //
67
76
  // Content
68
77
  //
78
+ // The outer wrapper: renders the ScrollArea.Root, measures available width,
79
+ // and publishes that width via context for Masonry.Viewport to consume.
80
+ // Style this layer (centered/thin/padding) to control the scroll container.
81
+ //
69
82
 
70
- type MasonryContentProps<Item> = ThemedClassName<
71
- {
72
- /** Items to render in the masonry grid. */
73
- items: Item[];
74
- /** Extract a stable key from an item, aligned with react-ui-mosaic's getId. */
75
- getId?: (data: Item) => string;
76
- } & Pick<ScrollAreaRootProps, 'centered' | 'thin' | 'padding'>
83
+ type MasonryContentProps = ThemedClassName<
84
+ PropsWithChildren<Pick<ScrollAreaRootProps, 'centered' | 'thin' | 'padding'>>
77
85
  >;
78
86
 
79
- const MasonryContentInner = composable<HTMLDivElement, MasonryContentProps<any>>(
80
- ({ items, getId, centered, thin = true, padding = true, ...props }, forwardedRef) => {
87
+ const MasonryContentInner = composable<HTMLDivElement, MasonryContentProps>(
88
+ ({ children, centered, thin = true, padding = true, ...props }, forwardedRef) => {
81
89
  const rootRef = useRef<HTMLDivElement | null>(null);
82
90
  const composedRef = useComposedRefs(rootRef, forwardedRef);
83
91
  const { width = 0 } = useResizeDetector({ targetRef: rootRef });
84
92
 
85
- const { Tile, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter } = useMasonryContext('Masonry.Content');
93
+ // NOTE: Masonry currently doesn't support an external scroller.
94
+ // https://github.com/petyosi/react-virtuoso/issues/1305
95
+ return (
96
+ <ScrollArea.Root {...composableProps(props)} centered={centered} thin={thin} padding={padding} ref={composedRef}>
97
+ <MasonryContentProvider width={width}>{children}</MasonryContentProvider>
98
+ </ScrollArea.Root>
99
+ );
100
+ },
101
+ );
102
+
103
+ MasonryContentInner.displayName = 'Masonry.Content';
104
+
105
+ const MasonryContent = MasonryContentInner as (
106
+ props: MasonryContentProps & {
107
+ ref?: Ref<HTMLDivElement | null>;
108
+ },
109
+ ) => JSX.Element;
110
+
111
+ //
112
+ // Viewport
113
+ //
114
+ // The inner render layer: renders the ScrollArea.Viewport wrapped around
115
+ // VirtuosoMasonry. Style this layer separately from Content to control
116
+ // the tile grid (e.g. inner padding, alignment).
117
+ //
118
+
119
+ type MasonryViewportProps<Item> = ThemedClassName<{
120
+ /** Items to render in the masonry grid. */
121
+ items: readonly Item[];
122
+ /** Extract a stable key from an item, aligned with react-ui-mosaic's getId. */
123
+ getId?: (data: Item) => string;
124
+ }>;
125
+
126
+ const MasonryViewportInner = composable<HTMLDivElement, MasonryViewportProps<any>>(
127
+ ({ items, getId, ...props }, forwardedRef) => {
128
+ const { Tile, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter } = useMasonryContext('Masonry.Viewport');
129
+ const { width } = useMasonryContentContext('Masonry.Viewport');
86
130
  const columnCount = useColumnCount(
87
- width - (scrollbar.thin.size + scrollbar.thin.padding),
131
+ width - (scrollbar.md.size + scrollbar.md.padding),
88
132
  columns,
89
133
  maxColumns,
90
134
  minColumnWidth,
@@ -92,33 +136,46 @@ const MasonryContentInner = composable<HTMLDivElement, MasonryContentProps<any>>
92
136
  gutter,
93
137
  );
94
138
 
139
+ // Arrow-key navigation across tiles. Uses Tabster's `both` axis so all
140
+ // four arrows move focus through the items. True 2D (grid) axis doesn't
141
+ // work inside a masonry because VirtuosoMasonry lays items out column-
142
+ // first in the DOM — tabster's Grid direction requires the next DOM
143
+ // element to be to the right of the current for ArrowRight, which is
144
+ // never the case between columns here. `both` treats the keys as flat
145
+ // next/previous-focusable, which gives predictable wrap-around in DOM
146
+ // order for all four directions.
147
+ const arrowNavigationAttrs = useArrowNavigationGroup({
148
+ axis: 'both',
149
+ memorizeCurrent: true,
150
+ tabbable: true,
151
+ });
152
+
95
153
  const TileAdapter = useMemo(() => {
96
- const Adapter = ({ data, index }: { data: any; index: number }) => {
97
- return (
98
- <div role='listitem' style={{ paddingBottom: `${gutter}rem` }}>
99
- <Tile index={index} data={data} />
100
- </div>
101
- );
102
- };
154
+ const Adapter = ({ data, index }: { data: any; index: number }) => (
155
+ <div role='listitem' style={{ paddingBottom: `${gutter}rem` }}>
156
+ <Tile index={index} data={data} />
157
+ </div>
158
+ );
103
159
  Adapter.displayName = 'Masonry.TileAdapter';
104
160
  return Adapter;
105
161
  }, [Tile, gutter]);
106
162
 
107
- // NOTE: Masonry currently doesn't support an external scroller.
108
- // https://github.com/petyosi/react-virtuoso/issues/1305
163
+ if (width <= 0) {
164
+ return null;
165
+ }
166
+
109
167
  return (
110
- <ScrollArea.Root {...composableProps(props)} centered={centered} thin={thin} padding={padding} ref={composedRef}>
111
- {width > 0 && (
112
- <ScrollArea.Viewport asChild>
113
- <ComposableVirtuosoMasonry
114
- style={{ gap: `${gutter}rem` }}
115
- data={items}
116
- columnCount={columnCount}
117
- ItemContent={TileAdapter}
118
- />
119
- </ScrollArea.Viewport>
120
- )}
121
- </ScrollArea.Root>
168
+ <ScrollArea.Viewport asChild>
169
+ <ComposableVirtuosoMasonry
170
+ {...arrowNavigationAttrs}
171
+ {...composableProps(props)}
172
+ ref={forwardedRef}
173
+ style={{ gap: `${gutter}rem` }}
174
+ data={items as any[]}
175
+ columnCount={columnCount}
176
+ ItemContent={TileAdapter}
177
+ />
178
+ </ScrollArea.Viewport>
122
179
  );
123
180
  },
124
181
  );
@@ -129,10 +186,10 @@ const ComposableVirtuosoMasonry = composable<HTMLDivElement, VirtuosoMasonryProp
129
186
  },
130
187
  );
131
188
 
132
- MasonryContentInner.displayName = 'Masonry.Content';
189
+ MasonryViewportInner.displayName = 'Masonry.Viewport';
133
190
 
134
- const MasonryContent = MasonryContentInner as <Item>(
135
- props: MasonryContentProps<Item> & {
191
+ const MasonryViewport = MasonryViewportInner as <Item>(
192
+ props: MasonryViewportProps<Item> & {
136
193
  ref?: Ref<HTMLDivElement | null>;
137
194
  },
138
195
  ) => JSX.Element;
@@ -155,7 +212,6 @@ const useColumnCount = (
155
212
  const minColumnWidthPx = minColumnWidth * remInPx;
156
213
  const maxColumnWidthPx = maxColumnWidth * remInPx;
157
214
  const gutterPx = gutter * remInPx;
158
-
159
215
  if (width <= 0 || minColumnWidthPx <= 0) {
160
216
  return 1;
161
217
  }
@@ -186,6 +242,7 @@ const useColumnCount = (
186
242
  export const Masonry = {
187
243
  Root: MasonryRoot,
188
244
  Content: MasonryContent,
245
+ Viewport: MasonryViewport,
189
246
  };
190
247
 
191
- export type { MasonryRootProps, MasonryContentProps };
248
+ export type { MasonryRootProps, MasonryContentProps, MasonryViewportProps };