@dxos/react-ui-masonry 0.8.4-main.74a063c4e0 → 0.8.4-main.765dc60934

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.74a063c4e0",
3
+ "version": "0.8.4-main.765dc60934",
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,14 +26,15 @@
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-ui-mosaic": "0.8.4-main.74a063c4e0",
34
- "@dxos/types": "0.8.4-main.74a063c4e0",
35
- "@dxos/react-hooks": "0.8.4-main.74a063c4e0",
36
- "@dxos/ui-types": "0.8.4-main.74a063c4e0"
34
+ "@dxos/react-hooks": "0.8.4-main.765dc60934",
35
+ "@dxos/react-ui-mosaic": "0.8.4-main.765dc60934",
36
+ "@dxos/types": "0.8.4-main.765dc60934",
37
+ "@dxos/ui-types": "0.8.4-main.765dc60934"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@types/react": "~19.2.7",
@@ -41,26 +42,26 @@
41
42
  "effect": "3.20.0",
42
43
  "react": "~19.2.3",
43
44
  "react-dom": "~19.2.3",
44
- "vite": "^7.1.11",
45
- "@dxos/client": "0.8.4-main.74a063c4e0",
46
- "@dxos/echo": "0.8.4-main.74a063c4e0",
47
- "@dxos/random": "0.8.4-main.74a063c4e0",
48
- "@dxos/react-client": "0.8.4-main.74a063c4e0",
49
- "@dxos/react-ui": "0.8.4-main.74a063c4e0",
50
- "@dxos/react-ui-stack": "0.8.4-main.74a063c4e0",
51
- "@dxos/react-ui-form": "0.8.4-main.74a063c4e0",
52
- "@dxos/schema": "0.8.4-main.74a063c4e0",
53
- "@dxos/storybook-utils": "0.8.4-main.74a063c4e0",
54
- "@dxos/test-utils": "0.8.4-main.74a063c4e0",
55
- "@dxos/ui-theme": "0.8.4-main.74a063c4e0"
45
+ "vite": "^8.0.13",
46
+ "@dxos/echo": "0.8.4-main.765dc60934",
47
+ "@dxos/client": "0.8.4-main.765dc60934",
48
+ "@dxos/random": "0.8.4-main.765dc60934",
49
+ "@dxos/react-ui": "0.8.4-main.765dc60934",
50
+ "@dxos/react-ui-stack": "0.8.4-main.765dc60934",
51
+ "@dxos/react-client": "0.8.4-main.765dc60934",
52
+ "@dxos/schema": "0.8.4-main.765dc60934",
53
+ "@dxos/react-ui-form": "0.8.4-main.765dc60934",
54
+ "@dxos/storybook-utils": "0.8.4-main.765dc60934",
55
+ "@dxos/ui-theme": "0.8.4-main.765dc60934",
56
+ "@dxos/test-utils": "0.8.4-main.765dc60934"
56
57
  },
57
58
  "peerDependencies": {
58
59
  "effect": "3.20.0",
59
60
  "react": "~19.2.3",
60
61
  "react-dom": "~19.2.3",
61
- "@dxos/random": "0.8.4-main.74a063c4e0",
62
- "@dxos/react-ui": "0.8.4-main.74a063c4e0",
63
- "@dxos/ui-theme": "0.8.4-main.74a063c4e0"
62
+ "@dxos/random": "0.8.4-main.765dc60934",
63
+ "@dxos/ui-theme": "0.8.4-main.765dc60934",
64
+ "@dxos/react-ui": "0.8.4-main.765dc60934"
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';
@@ -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';
@@ -34,6 +35,13 @@ const MASONRY_NAME = 'Masonry';
34
35
 
35
36
  const [MasonryProvider, useMasonryContext] = createContext<MasonryContextValue>(MASONRY_NAME);
36
37
 
38
+ /** Content-scoped context: measured width of the ScrollArea.Root, shared with Viewport. */
39
+ type MasonryContentContextValue = {
40
+ width: number;
41
+ };
42
+
43
+ const [MasonryContentProvider, useMasonryContentContext] = createContext<MasonryContentContextValue>('Masonry.Content');
44
+
37
45
  //
38
46
  // Root
39
47
  //
@@ -66,23 +74,58 @@ MasonryRoot.displayName = 'Masonry.Root';
66
74
  //
67
75
  // Content
68
76
  //
77
+ // The outer wrapper: renders the ScrollArea.Root, measures available width,
78
+ // and publishes that width via context for Masonry.Viewport to consume.
79
+ // Style this layer (centered/thin/padding) to control the scroll container.
80
+ //
69
81
 
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'>
82
+ type MasonryContentProps = ThemedClassName<
83
+ PropsWithChildren<Pick<ScrollAreaRootProps, 'centered' | 'thin' | 'padding'>>
77
84
  >;
78
85
 
79
- const MasonryContentInner = composable<HTMLDivElement, MasonryContentProps<any>>(
80
- ({ items, getId, centered, thin = true, padding = true, ...props }, forwardedRef) => {
86
+ const MasonryContentInner = composable<HTMLDivElement, MasonryContentProps>(
87
+ ({ children, centered, thin = true, padding = true, ...props }, forwardedRef) => {
81
88
  const rootRef = useRef<HTMLDivElement | null>(null);
82
89
  const composedRef = useComposedRefs(rootRef, forwardedRef);
83
90
  const { width = 0 } = useResizeDetector({ targetRef: rootRef });
84
91
 
85
- const { Tile, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter } = useMasonryContext('Masonry.Content');
92
+ // NOTE: Masonry currently doesn't support an external scroller.
93
+ // https://github.com/petyosi/react-virtuoso/issues/1305
94
+ return (
95
+ <ScrollArea.Root {...composableProps(props)} centered={centered} thin={thin} padding={padding} ref={composedRef}>
96
+ <MasonryContentProvider width={width}>{children}</MasonryContentProvider>
97
+ </ScrollArea.Root>
98
+ );
99
+ },
100
+ );
101
+
102
+ MasonryContentInner.displayName = 'Masonry.Content';
103
+
104
+ const MasonryContent = MasonryContentInner as (
105
+ props: MasonryContentProps & {
106
+ ref?: Ref<HTMLDivElement | null>;
107
+ },
108
+ ) => JSX.Element;
109
+
110
+ //
111
+ // Viewport
112
+ //
113
+ // The inner render layer: renders the ScrollArea.Viewport wrapped around
114
+ // VirtuosoMasonry. Style this layer separately from Content to control
115
+ // the tile grid (e.g. inner padding, alignment).
116
+ //
117
+
118
+ type MasonryViewportProps<Item> = ThemedClassName<{
119
+ /** Items to render in the masonry grid. */
120
+ items: Item[];
121
+ /** Extract a stable key from an item, aligned with react-ui-mosaic's getId. */
122
+ getId?: (data: Item) => string;
123
+ }>;
124
+
125
+ const MasonryViewportInner = composable<HTMLDivElement, MasonryViewportProps<any>>(
126
+ ({ items, getId, ...props }, forwardedRef) => {
127
+ const { Tile, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter } = useMasonryContext('Masonry.Viewport');
128
+ const { width } = useMasonryContentContext('Masonry.Viewport');
86
129
  const columnCount = useColumnCount(
87
130
  width - (scrollbar.thin.size + scrollbar.thin.padding),
88
131
  columns,
@@ -92,45 +135,60 @@ const MasonryContentInner = composable<HTMLDivElement, MasonryContentProps<any>>
92
135
  gutter,
93
136
  );
94
137
 
138
+ // Arrow-key navigation across tiles. Uses Tabster's `both` axis so all
139
+ // four arrows move focus through the items. True 2D (grid) axis doesn't
140
+ // work inside a masonry because VirtuosoMasonry lays items out column-
141
+ // first in the DOM — tabster's Grid direction requires the next DOM
142
+ // element to be to the right of the current for ArrowRight, which is
143
+ // never the case between columns here. `both` treats the keys as flat
144
+ // next/previous-focusable, which gives predictable wrap-around in DOM
145
+ // order for all four directions.
146
+ const arrowNavigationAttrs = useArrowNavigationGroup({
147
+ axis: 'both',
148
+ memorizeCurrent: true,
149
+ tabbable: true,
150
+ });
151
+
95
152
  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
- };
153
+ const Adapter = ({ data, index }: { data: any; index: number }) => (
154
+ <div role='listitem' style={{ paddingBottom: `${gutter}rem` }}>
155
+ <Tile index={index} data={data} />
156
+ </div>
157
+ );
103
158
  Adapter.displayName = 'Masonry.TileAdapter';
104
159
  return Adapter;
105
160
  }, [Tile, gutter]);
106
161
 
107
- // NOTE: Masonry currently doesn't support an external scroller.
108
- // https://github.com/petyosi/react-virtuoso/issues/1305
162
+ if (width <= 0) {
163
+ return null;
164
+ }
165
+
109
166
  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>
167
+ <ScrollArea.Viewport asChild>
168
+ <ComposableVirtuosoMasonry
169
+ {...arrowNavigationAttrs}
170
+ {...composableProps(props)}
171
+ ref={forwardedRef}
172
+ style={{ gap: `${gutter}rem` }}
173
+ data={items}
174
+ columnCount={columnCount}
175
+ ItemContent={TileAdapter}
176
+ />
177
+ </ScrollArea.Viewport>
122
178
  );
123
179
  },
124
180
  );
125
181
 
126
- const ComposableVirtuosoMasonry = composable<HTMLDivElement, VirtuosoMasonryProps<any, any>>(({ ...props }) => {
127
- return <VirtuosoMasonry {...props} />;
128
- });
182
+ const ComposableVirtuosoMasonry = composable<HTMLDivElement, VirtuosoMasonryProps<any, any>>(
183
+ ({ ...props }, _forwardedRef) => {
184
+ return <VirtuosoMasonry {...props} />;
185
+ },
186
+ );
129
187
 
130
- MasonryContentInner.displayName = 'Masonry.Content';
188
+ MasonryViewportInner.displayName = 'Masonry.Viewport';
131
189
 
132
- const MasonryContent = MasonryContentInner as <Item>(
133
- props: MasonryContentProps<Item> & {
190
+ const MasonryViewport = MasonryViewportInner as <Item>(
191
+ props: MasonryViewportProps<Item> & {
134
192
  ref?: Ref<HTMLDivElement | null>;
135
193
  },
136
194
  ) => JSX.Element;
@@ -153,7 +211,6 @@ const useColumnCount = (
153
211
  const minColumnWidthPx = minColumnWidth * remInPx;
154
212
  const maxColumnWidthPx = maxColumnWidth * remInPx;
155
213
  const gutterPx = gutter * remInPx;
156
-
157
214
  if (width <= 0 || minColumnWidthPx <= 0) {
158
215
  return 1;
159
216
  }
@@ -184,6 +241,7 @@ const useColumnCount = (
184
241
  export const Masonry = {
185
242
  Root: MasonryRoot,
186
243
  Content: MasonryContent,
244
+ Viewport: MasonryViewport,
187
245
  };
188
246
 
189
- export type { MasonryRootProps, MasonryContentProps };
247
+ export type { MasonryRootProps, MasonryContentProps, MasonryViewportProps };