@dxos/react-ui-masonry 0.8.4-main.fffef41 → 0.9.0

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/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -1,84 +1,128 @@
1
1
  // src/Masonry.tsx
2
+ import { useArrowNavigationGroup } from "@fluentui/react-tabster";
2
3
  import { useComposedRefs } from "@radix-ui/react-compose-refs";
3
- import { useMasonry, usePositioner, useResizeObserver } from "masonic";
4
- import React, { forwardRef, useMemo, useRef } from "react";
4
+ import { createContext } from "@radix-ui/react-context";
5
+ import { VirtuosoMasonry } from "@virtuoso.dev/masonry";
6
+ import React, { useMemo, useRef } from "react";
5
7
  import { useResizeDetector } from "react-resize-detector";
6
- import { useScroller } from "@dxos/react-hooks";
7
- import { usePx } from "@dxos/react-ui";
8
- import { cardMaxInlineSize, cardMinInlineSize } from "@dxos/react-ui-theme";
9
- import { mx } from "@dxos/react-ui-theme";
10
- var usePxProps = (remProps) => {
11
- const remInPx = usePx(1);
12
- return useMemo(() => {
13
- return Object.fromEntries(Object.entries(remProps).filter(([_, value]) => Number.isFinite(value)).map(([key, value]) => {
14
- return [
15
- key,
16
- value * remInPx
17
- ];
18
- }));
19
- }, [
20
- remProps,
21
- remInPx
22
- ]);
23
- };
24
- var MasonryRootImpl = ({ columnCount, maxColumnCount, columnWidth = cardMinInlineSize, maxColumnWidth = cardMaxInlineSize, columnGutter = 1, rowGutter, items, itemHeightEstimate = 256, itemKey, overscanBy = 6, render, onRender, classNames, intrinsicHeight, ...props }, forwardedRef) => {
8
+ import { ScrollArea, usePx } from "@dxos/react-ui";
9
+ import { composable, composableProps, scrollbar } from "@dxos/react-ui";
10
+ import { cardMaxInlineSize, cardMinInlineSize } from "@dxos/ui-theme";
11
+ var MASONRY_NAME = "Masonry";
12
+ var [MasonryProvider, useMasonryContext] = createContext(MASONRY_NAME);
13
+ var [MasonryContentProvider, useMasonryContentContext] = createContext("Masonry.Content");
14
+ var MasonryRoot = ({ children, Tile, columns = void 0, maxColumns = void 0, minColumnWidth = cardMinInlineSize, maxColumnWidth = cardMaxInlineSize, gutter = 0.75 }) => /* @__PURE__ */ React.createElement(MasonryProvider, {
15
+ Tile,
16
+ columns,
17
+ maxColumns,
18
+ minColumnWidth,
19
+ maxColumnWidth,
20
+ gutter
21
+ }, children);
22
+ MasonryRoot.displayName = "Masonry.Root";
23
+ var MasonryContentInner = composable(({ children, centered, thin = true, padding = true, ...props }, forwardedRef) => {
25
24
  const rootRef = useRef(null);
26
- const ref = useComposedRefs(rootRef, forwardedRef);
27
- const { width = 0, height = 0 } = useResizeDetector({
25
+ const composedRef = useComposedRefs(rootRef, forwardedRef);
26
+ const { width = 0 } = useResizeDetector({
28
27
  targetRef: rootRef
29
28
  });
30
- const { scrollTop, isScrolling } = useScroller(rootRef);
31
- const remProps = useMemo(() => ({
32
- columnWidth,
33
- maxColumnWidth,
34
- columnGutter,
35
- rowGutter
36
- }), [
37
- columnWidth,
38
- maxColumnWidth,
39
- columnGutter,
40
- rowGutter
29
+ return /* @__PURE__ */ React.createElement(ScrollArea.Root, {
30
+ ...composableProps(props),
31
+ centered,
32
+ thin,
33
+ padding,
34
+ ref: composedRef
35
+ }, /* @__PURE__ */ React.createElement(MasonryContentProvider, {
36
+ width
37
+ }, children));
38
+ });
39
+ MasonryContentInner.displayName = "Masonry.Content";
40
+ var MasonryContent = MasonryContentInner;
41
+ var MasonryViewportInner = composable(({ items, getId, ...props }, forwardedRef) => {
42
+ const { Tile, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter } = useMasonryContext("Masonry.Viewport");
43
+ const { width } = useMasonryContentContext("Masonry.Viewport");
44
+ const columnCount = useColumnCount(width - (scrollbar.md.size + scrollbar.md.padding), columns, maxColumns, minColumnWidth, maxColumnWidth, gutter);
45
+ const arrowNavigationAttrs = useArrowNavigationGroup({
46
+ axis: "both",
47
+ memorizeCurrent: true,
48
+ tabbable: true
49
+ });
50
+ const TileAdapter = useMemo(() => {
51
+ const Adapter = ({ data, index }) => /* @__PURE__ */ React.createElement("div", {
52
+ role: "listitem",
53
+ style: {
54
+ paddingBottom: `${gutter}rem`
55
+ }
56
+ }, /* @__PURE__ */ React.createElement(Tile, {
57
+ index,
58
+ data
59
+ }));
60
+ Adapter.displayName = "Masonry.TileAdapter";
61
+ return Adapter;
62
+ }, [
63
+ Tile,
64
+ gutter
41
65
  ]);
42
- const pxProps = usePxProps(remProps);
43
- const numItems = items.length;
44
- const positionerProps = useMemo(() => ({
45
- width,
66
+ if (width <= 0) {
67
+ return null;
68
+ }
69
+ return /* @__PURE__ */ React.createElement(ScrollArea.Viewport, {
70
+ asChild: true
71
+ }, /* @__PURE__ */ React.createElement(ComposableVirtuosoMasonry, {
72
+ ...arrowNavigationAttrs,
73
+ ...composableProps(props),
74
+ ref: forwardedRef,
75
+ style: {
76
+ gap: `${gutter}rem`
77
+ },
78
+ data: items,
46
79
  columnCount,
47
- maxColumnCount: Math.max(maxColumnCount ?? 1, numItems),
48
- ...pxProps
49
- }), [
80
+ ItemContent: TileAdapter
81
+ }));
82
+ });
83
+ var ComposableVirtuosoMasonry = composable(({ ...props }, _forwardedRef) => {
84
+ return /* @__PURE__ */ React.createElement(VirtuosoMasonry, props);
85
+ });
86
+ MasonryViewportInner.displayName = "Masonry.Viewport";
87
+ var MasonryViewport = MasonryViewportInner;
88
+ var useColumnCount = (width, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter) => {
89
+ const remInPx = usePx(1);
90
+ return useMemo(() => {
91
+ if (columns != null) {
92
+ return columns;
93
+ }
94
+ const minColumnWidthPx = minColumnWidth * remInPx;
95
+ const maxColumnWidthPx = maxColumnWidth * remInPx;
96
+ const gutterPx = gutter * remInPx;
97
+ if (width <= 0 || minColumnWidthPx <= 0) {
98
+ return 1;
99
+ }
100
+ let cols = Math.floor(width / (minColumnWidthPx + gutterPx));
101
+ if (maxColumnWidthPx > 0) {
102
+ const effectiveColWidth = width / cols - gutterPx;
103
+ if (effectiveColWidth > maxColumnWidthPx) {
104
+ const maxCols = Math.ceil(width / (maxColumnWidthPx + gutterPx));
105
+ if (width / maxCols - gutterPx >= minColumnWidthPx) {
106
+ cols = maxCols;
107
+ }
108
+ }
109
+ }
110
+ const clamped = maxColumns != null ? Math.min(cols, maxColumns) : cols;
111
+ return Math.max(1, clamped);
112
+ }, [
113
+ remInPx,
50
114
  width,
51
- columnCount,
52
- maxColumnCount,
53
- numItems,
54
- pxProps
55
- ]);
56
- const positioner = usePositioner(positionerProps, [
57
- positionerProps
115
+ columns,
116
+ maxColumns,
117
+ minColumnWidth,
118
+ maxColumnWidth,
119
+ gutter
58
120
  ]);
59
- const resizeObserver = useResizeObserver(positioner);
60
- const children = useMasonry({
61
- height: intrinsicHeight ? Infinity : height,
62
- scrollTop,
63
- isScrolling,
64
- resizeObserver,
65
- positioner,
66
- items,
67
- itemHeightEstimate,
68
- itemKey,
69
- overscanBy,
70
- render,
71
- onRender
72
- });
73
- return /* @__PURE__ */ React.createElement("div", {
74
- className: mx(classNames),
75
- ...props,
76
- ref
77
- }, children);
78
121
  };
79
- var MasonryRoot = /* @__PURE__ */ forwardRef(MasonryRootImpl);
80
122
  var Masonry = {
81
- Root: MasonryRoot
123
+ Root: MasonryRoot,
124
+ Content: MasonryContent,
125
+ Viewport: MasonryViewport
82
126
  };
83
127
  export {
84
128
  Masonry
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/Masonry.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport {\n type UseMasonryOptions,\n type UsePositionerOptions,\n useMasonry,\n usePositioner,\n useResizeObserver,\n} from 'masonic';\nimport React, {\n type ComponentPropsWithRef,\n type ForwardedRef,\n type JSX,\n type Ref,\n forwardRef,\n useMemo,\n useRef,\n} from 'react';\nimport { useResizeDetector } from 'react-resize-detector';\n\nimport { useScroller } from '@dxos/react-hooks';\nimport { type ThemedClassName, usePx } from '@dxos/react-ui';\nimport { cardMaxInlineSize, cardMinInlineSize } from '@dxos/react-ui-theme';\nimport { mx } from '@dxos/react-ui-theme';\n\ntype MasonryRootProps<Item> = ThemedClassName<ComponentPropsWithRef<'div'>> &\n Omit<UsePositionerOptions, 'width'> &\n Omit<\n UseMasonryOptions<Item>,\n | 'height'\n | 'scrollTop'\n | 'isScrolling'\n | 'resizeObserver'\n | 'positioner'\n | 'as'\n | 'id'\n | 'itemAs'\n | 'itemStyle'\n | 'className'\n | 'style'\n | 'role'\n | 'tabIndex'\n | 'containerRef'\n > & { intrinsicHeight?: boolean };\n\nconst usePxProps = (remProps: Omit<UsePositionerOptions, 'width' | 'columnCount' | 'maxColumnCount'>) => {\n const remInPx = usePx(1);\n return useMemo(() => {\n return Object.fromEntries(\n Object.entries(remProps)\n .filter(([_, value]) => Number.isFinite(value))\n .map(([key, value]) => {\n return [key, value * remInPx];\n }),\n );\n }, [remProps, remInPx]);\n};\n\nconst MasonryRootImpl = <Item,>(\n {\n columnCount,\n maxColumnCount,\n columnWidth = cardMinInlineSize,\n maxColumnWidth = cardMaxInlineSize,\n columnGutter = 1,\n rowGutter,\n items,\n itemHeightEstimate = 256,\n itemKey,\n overscanBy = 6,\n render,\n onRender,\n classNames,\n intrinsicHeight,\n ...props\n }: MasonryRootProps<Item>,\n forwardedRef: ForwardedRef<HTMLDivElement>,\n) => {\n const rootRef = useRef<HTMLDivElement | null>(null);\n const ref = useComposedRefs(rootRef, forwardedRef);\n const { width = 0, height = 0 } = useResizeDetector({ targetRef: rootRef });\n const { scrollTop, isScrolling } = useScroller(rootRef);\n const remProps = useMemo(\n () => ({ columnWidth, maxColumnWidth, columnGutter, rowGutter }),\n [columnWidth, maxColumnWidth, columnGutter, rowGutter],\n );\n const pxProps = usePxProps(remProps);\n const numItems = items.length;\n const positionerProps = useMemo<UsePositionerOptions>(\n () => ({\n width,\n columnCount,\n maxColumnCount: Math.max(maxColumnCount ?? 1, numItems),\n ...pxProps,\n }),\n [width, columnCount, maxColumnCount, numItems, pxProps],\n );\n const positioner = usePositioner(positionerProps, [positionerProps]);\n const resizeObserver = useResizeObserver(positioner);\n const children = useMasonry({\n height: intrinsicHeight ? Infinity : height,\n scrollTop,\n isScrolling,\n resizeObserver,\n positioner,\n items,\n itemHeightEstimate,\n itemKey,\n overscanBy,\n render,\n onRender,\n });\n\n return (\n <div className={mx(classNames)} {...props} ref={ref}>\n {children}\n </div>\n );\n};\n\nconst MasonryRoot = forwardRef(MasonryRootImpl) as <Item>(\n props: MasonryRootProps<Item> & {\n ref?: Ref<HTMLDivElement | null>;\n },\n) => JSX.Element;\n\nexport const Masonry = {\n Root: MasonryRoot,\n};\n\nexport type { MasonryRootProps };\n"],
5
- "mappings": ";AAIA,SAASA,uBAAuB;AAChC,SAGEC,YACAC,eACAC,yBACK;AACP,OAAOC,SAKLC,YACAC,SACAC,cACK;AACP,SAASC,yBAAyB;AAElC,SAASC,mBAAmB;AAC5B,SAA+BC,aAAa;AAC5C,SAASC,mBAAmBC,yBAAyB;AACrD,SAASC,UAAU;AAsBnB,IAAMC,aAAa,CAACC,aAAAA;AAClB,QAAMC,UAAUC,MAAM,CAAA;AACtB,SAAOC,QAAQ,MAAA;AACb,WAAOC,OAAOC,YACZD,OAAOE,QAAQN,QAAAA,EACZO,OAAO,CAAC,CAACC,GAAGC,KAAAA,MAAWC,OAAOC,SAASF,KAAAA,CAAAA,EACvCG,IAAI,CAAC,CAACC,KAAKJ,KAAAA,MAAM;AAChB,aAAO;QAACI;QAAKJ,QAAQR;;IACvB,CAAA,CAAA;EAEN,GAAG;IAACD;IAAUC;GAAQ;AACxB;AAEA,IAAMa,kBAAkB,CACtB,EACEC,aACAC,gBACAC,cAAcC,mBACdC,iBAAiBC,mBACjBC,eAAe,GACfC,WACAC,OACAC,qBAAqB,KACrBC,SACAC,aAAa,GACbC,QACAC,UACAC,YACAC,iBACA,GAAGC,MAAAA,GAELC,iBAAAA;AAEA,QAAMC,UAAUC,OAA8B,IAAA;AAC9C,QAAMC,MAAMC,gBAAgBH,SAASD,YAAAA;AACrC,QAAM,EAAEK,QAAQ,GAAGC,SAAS,EAAC,IAAKC,kBAAkB;IAAEC,WAAWP;EAAQ,CAAA;AACzE,QAAM,EAAEQ,WAAWC,YAAW,IAAKC,YAAYV,OAAAA;AAC/C,QAAMjC,WAAWG,QACf,OAAO;IAAEc;IAAaE;IAAgBE;IAAcC;EAAU,IAC9D;IAACL;IAAaE;IAAgBE;IAAcC;GAAU;AAExD,QAAMsB,UAAU7C,WAAWC,QAAAA;AAC3B,QAAM6C,WAAWtB,MAAMuB;AACvB,QAAMC,kBAAkB5C,QACtB,OAAO;IACLkC;IACAtB;IACAC,gBAAgBgC,KAAKC,IAAIjC,kBAAkB,GAAG6B,QAAAA;IAC9C,GAAGD;EACL,IACA;IAACP;IAAOtB;IAAaC;IAAgB6B;IAAUD;GAAQ;AAEzD,QAAMM,aAAaC,cAAcJ,iBAAiB;IAACA;GAAgB;AACnE,QAAMK,iBAAiBC,kBAAkBH,UAAAA;AACzC,QAAMI,WAAWC,WAAW;IAC1BjB,QAAQR,kBAAkB0B,WAAWlB;IACrCG;IACAC;IACAU;IACAF;IACA3B;IACAC;IACAC;IACAC;IACAC;IACAC;EACF,CAAA;AAEA,SACE,sBAAA,cAAC6B,OAAAA;IAAIC,WAAWC,GAAG9B,UAAAA;IAAc,GAAGE;IAAOI;KACxCmB,QAAAA;AAGP;AAEA,IAAMM,cAAcC,2BAAW/C,eAAAA;AAMxB,IAAMgD,UAAU;EACrBC,MAAMH;AACR;",
6
- "names": ["useComposedRefs", "useMasonry", "usePositioner", "useResizeObserver", "React", "forwardRef", "useMemo", "useRef", "useResizeDetector", "useScroller", "usePx", "cardMaxInlineSize", "cardMinInlineSize", "mx", "usePxProps", "remProps", "remInPx", "usePx", "useMemo", "Object", "fromEntries", "entries", "filter", "_", "value", "Number", "isFinite", "map", "key", "MasonryRootImpl", "columnCount", "maxColumnCount", "columnWidth", "cardMinInlineSize", "maxColumnWidth", "cardMaxInlineSize", "columnGutter", "rowGutter", "items", "itemHeightEstimate", "itemKey", "overscanBy", "render", "onRender", "classNames", "intrinsicHeight", "props", "forwardedRef", "rootRef", "useRef", "ref", "useComposedRefs", "width", "height", "useResizeDetector", "targetRef", "scrollTop", "isScrolling", "useScroller", "pxProps", "numItems", "length", "positionerProps", "Math", "max", "positioner", "usePositioner", "resizeObserver", "useResizeObserver", "children", "useMasonry", "Infinity", "div", "className", "mx", "MasonryRoot", "forwardRef", "Masonry", "Root"]
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useArrowNavigationGroup } from '@fluentui/react-tabster';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContext } from '@radix-ui/react-context';\nimport { VirtuosoMasonry, type VirtuosoMasonryProps } from '@virtuoso.dev/masonry';\nimport React, { type ComponentType, type JSX, type PropsWithChildren, type Ref, useMemo, useRef } from 'react';\nimport { useResizeDetector } from 'react-resize-detector';\n\nimport { ScrollArea, ScrollAreaRootProps, ThemedClassName, usePx } from '@dxos/react-ui';\nimport { composable, composableProps, scrollbar } from '@dxos/react-ui';\nimport { cardMaxInlineSize, cardMinInlineSize } from '@dxos/ui-theme';\n\n//\n// Context\n//\n\ntype MasonryContextValue = {\n /** Render component for each masonry item. */\n Tile: ComponentType<{ data: any; index: number }>;\n /** Override auto-calculated column count. */\n columns: number | undefined;\n /** Upper bound on number of columns. */\n maxColumns: number | undefined;\n /** Minimum column width in rem. */\n minColumnWidth: number;\n /** Maximum column width in rem. */\n maxColumnWidth: number;\n /** Space between columns and rows in rem. */\n gutter: number;\n};\n\nconst MASONRY_NAME = 'Masonry';\n\nconst [MasonryProvider, useMasonryContext] = createContext<MasonryContextValue>(MASONRY_NAME);\n\n/** Content-scoped context: measured width of the ScrollArea.Root, shared with Viewport. */\ntype MasonryContentContextValue = {\n width: number;\n};\n\nconst [MasonryContentProvider, useMasonryContentContext] = createContext<MasonryContentContextValue>('Masonry.Content');\n\n//\n// Root\n//\n\ntype MasonryRootProps = PropsWithChildren<Partial<MasonryContextValue>>;\n\nconst MasonryRoot = ({\n children,\n Tile,\n columns = undefined,\n maxColumns = undefined,\n minColumnWidth = cardMinInlineSize,\n maxColumnWidth = cardMaxInlineSize,\n gutter = 0.75,\n}: MasonryRootProps) => (\n <MasonryProvider\n Tile={Tile!}\n columns={columns}\n maxColumns={maxColumns}\n minColumnWidth={minColumnWidth}\n maxColumnWidth={maxColumnWidth}\n gutter={gutter}\n >\n {children}\n </MasonryProvider>\n);\n\nMasonryRoot.displayName = 'Masonry.Root';\n\n//\n// Content\n//\n// The outer wrapper: renders the ScrollArea.Root, measures available width,\n// and publishes that width via context for Masonry.Viewport to consume.\n// Style this layer (centered/thin/padding) to control the scroll container.\n//\n\ntype MasonryContentProps = ThemedClassName<\n PropsWithChildren<Pick<ScrollAreaRootProps, 'centered' | 'thin' | 'padding'>>\n>;\n\nconst MasonryContentInner = composable<HTMLDivElement, MasonryContentProps>(\n ({ children, centered, thin = true, padding = true, ...props }, forwardedRef) => {\n const rootRef = useRef<HTMLDivElement | null>(null);\n const composedRef = useComposedRefs(rootRef, forwardedRef);\n const { width = 0 } = useResizeDetector({ targetRef: rootRef });\n\n // NOTE: Masonry currently doesn't support an external scroller.\n // https://github.com/petyosi/react-virtuoso/issues/1305\n return (\n <ScrollArea.Root {...composableProps(props)} centered={centered} thin={thin} padding={padding} ref={composedRef}>\n <MasonryContentProvider width={width}>{children}</MasonryContentProvider>\n </ScrollArea.Root>\n );\n },\n);\n\nMasonryContentInner.displayName = 'Masonry.Content';\n\nconst MasonryContent = MasonryContentInner as (\n props: MasonryContentProps & {\n ref?: Ref<HTMLDivElement | null>;\n },\n) => JSX.Element;\n\n//\n// Viewport\n//\n// The inner render layer: renders the ScrollArea.Viewport wrapped around\n// VirtuosoMasonry. Style this layer separately from Content to control\n// the tile grid (e.g. inner padding, alignment).\n//\n\ntype MasonryViewportProps<Item> = ThemedClassName<{\n /** Items to render in the masonry grid. */\n items: readonly Item[];\n /** Extract a stable key from an item, aligned with react-ui-mosaic's getId. */\n getId?: (data: Item) => string;\n}>;\n\nconst MasonryViewportInner = composable<HTMLDivElement, MasonryViewportProps<any>>(\n ({ items, getId, ...props }, forwardedRef) => {\n const { Tile, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter } = useMasonryContext('Masonry.Viewport');\n const { width } = useMasonryContentContext('Masonry.Viewport');\n const columnCount = useColumnCount(\n width - (scrollbar.md.size + scrollbar.md.padding),\n columns,\n maxColumns,\n minColumnWidth,\n maxColumnWidth,\n gutter,\n );\n\n // Arrow-key navigation across tiles. Uses Tabster's `both` axis so all\n // four arrows move focus through the items. True 2D (grid) axis doesn't\n // work inside a masonry because VirtuosoMasonry lays items out column-\n // first in the DOM — tabster's Grid direction requires the next DOM\n // element to be to the right of the current for ArrowRight, which is\n // never the case between columns here. `both` treats the keys as flat\n // next/previous-focusable, which gives predictable wrap-around in DOM\n // order for all four directions.\n const arrowNavigationAttrs = useArrowNavigationGroup({\n axis: 'both',\n memorizeCurrent: true,\n tabbable: true,\n });\n\n const TileAdapter = useMemo(() => {\n const Adapter = ({ data, index }: { data: any; index: number }) => (\n <div role='listitem' style={{ paddingBottom: `${gutter}rem` }}>\n <Tile index={index} data={data} />\n </div>\n );\n Adapter.displayName = 'Masonry.TileAdapter';\n return Adapter;\n }, [Tile, gutter]);\n\n if (width <= 0) {\n return null;\n }\n\n return (\n <ScrollArea.Viewport asChild>\n <ComposableVirtuosoMasonry\n {...arrowNavigationAttrs}\n {...composableProps(props)}\n ref={forwardedRef}\n style={{ gap: `${gutter}rem` }}\n data={items as any[]}\n columnCount={columnCount}\n ItemContent={TileAdapter}\n />\n </ScrollArea.Viewport>\n );\n },\n);\n\nconst ComposableVirtuosoMasonry = composable<HTMLDivElement, VirtuosoMasonryProps<any, any>>(\n ({ ...props }, _forwardedRef) => {\n return <VirtuosoMasonry {...props} />;\n },\n);\n\nMasonryViewportInner.displayName = 'Masonry.Viewport';\n\nconst MasonryViewport = MasonryViewportInner as <Item>(\n props: MasonryViewportProps<Item> & {\n ref?: Ref<HTMLDivElement | null>;\n },\n) => JSX.Element;\n\n/** Compute column count from container width and column constraints. */\nconst useColumnCount = (\n width: number,\n columns: number | undefined,\n maxColumns: number | undefined,\n minColumnWidth: number,\n maxColumnWidth: number,\n gutter: number,\n) => {\n const remInPx = usePx(1);\n return useMemo(() => {\n if (columns != null) {\n return columns;\n }\n\n const minColumnWidthPx = minColumnWidth * remInPx;\n const maxColumnWidthPx = maxColumnWidth * remInPx;\n const gutterPx = gutter * remInPx;\n if (width <= 0 || minColumnWidthPx <= 0) {\n return 1;\n }\n\n // Each tile has paddingRight: gutter, so every slot (including the last) occupies\n // (colWidth + gutterPx). The container therefore fits floor(containerWidth / (colWidth + gutterPx)) columns.\n let cols = Math.floor(width / (minColumnWidthPx + gutterPx));\n if (maxColumnWidthPx > 0) {\n const effectiveColWidth = width / cols - gutterPx;\n if (effectiveColWidth > maxColumnWidthPx) {\n // Try to add columns to keep cards below maxColumnWidth, but never violate minColumnWidth.\n const maxCols = Math.ceil(width / (maxColumnWidthPx + gutterPx));\n if (width / maxCols - gutterPx >= minColumnWidthPx) {\n cols = maxCols;\n }\n }\n }\n\n const clamped = maxColumns != null ? Math.min(cols, maxColumns) : cols;\n return Math.max(1, clamped);\n }, [remInPx, width, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter]);\n};\n\n//\n// Masonry\n//\n\nexport const Masonry = {\n Root: MasonryRoot,\n Content: MasonryContent,\n Viewport: MasonryViewport,\n};\n\nexport type { MasonryRootProps, MasonryContentProps, MasonryViewportProps };\n"],
5
+ "mappings": "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",
6
+ "names": ["useArrowNavigationGroup", "useComposedRefs", "createContext", "VirtuosoMasonry", "React", "useMemo", "useRef", "useResizeDetector", "ScrollArea", "usePx", "composable", "composableProps", "scrollbar", "cardMaxInlineSize", "cardMinInlineSize", "MASONRY_NAME", "MasonryProvider", "useMasonryContext", "MasonryContentProvider", "useMasonryContentContext", "MasonryRoot", "children", "Tile", "columns", "undefined", "maxColumns", "minColumnWidth", "maxColumnWidth", "gutter", "displayName", "MasonryContentInner", "centered", "thin", "padding", "props", "forwardedRef", "rootRef", "composedRef", "width", "targetRef", "Root", "ref", "MasonryContent", "MasonryViewportInner", "items", "getId", "columnCount", "useColumnCount", "md", "size", "arrowNavigationAttrs", "axis", "memorizeCurrent", "tabbable", "TileAdapter", "Adapter", "data", "index", "div", "role", "style", "paddingBottom", "Viewport", "asChild", "ComposableVirtuosoMasonry", "gap", "ItemContent", "_forwardedRef", "MasonryViewport", "remInPx", "minColumnWidthPx", "maxColumnWidthPx", "gutterPx", "cols", "Math", "floor", "effectiveColWidth", "maxCols", "ceil", "clamped", "min", "max", "Masonry", "Content"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/Masonry.tsx":{"bytes":10980,"imports":[{"path":"@radix-ui/react-compose-refs","kind":"import-statement","external":true},{"path":"masonic","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-resize-detector","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":454,"imports":[{"path":"src/Masonry.tsx","kind":"import-statement","original":"./Masonry"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6186},"dist/lib/browser/index.mjs":{"imports":[{"path":"@radix-ui/react-compose-refs","kind":"import-statement","external":true},{"path":"masonic","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-resize-detector","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"exports":["Masonry"],"entryPoint":"src/index.ts","inputs":{"src/Masonry.tsx":{"bytesInOutput":2410},"src/index.ts":{"bytesInOutput":0}},"bytes":2486}}}
1
+ {"inputs":{"src/Masonry.tsx":{"bytes":23119,"imports":[{"path":"@fluentui/react-tabster","kind":"import-statement","external":true},{"path":"@radix-ui/react-compose-refs","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@virtuoso.dev/masonry","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-resize-detector","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":375,"imports":[{"path":"src/Masonry.tsx","kind":"import-statement","original":"./Masonry"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12330},"dist/lib/browser/index.mjs":{"imports":[{"path":"@fluentui/react-tabster","kind":"import-statement","external":true},{"path":"@radix-ui/react-compose-refs","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@virtuoso.dev/masonry","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-resize-detector","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"exports":["Masonry"],"entryPoint":"src/index.ts","inputs":{"src/Masonry.tsx":{"bytesInOutput":4463},"src/index.ts":{"bytesInOutput":0}},"bytes":4539}}}
@@ -1,86 +1,130 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/Masonry.tsx
4
+ import { useArrowNavigationGroup } from "@fluentui/react-tabster";
4
5
  import { useComposedRefs } from "@radix-ui/react-compose-refs";
5
- import { useMasonry, usePositioner, useResizeObserver } from "masonic";
6
- import React, { forwardRef, useMemo, useRef } from "react";
6
+ import { createContext } from "@radix-ui/react-context";
7
+ import { VirtuosoMasonry } from "@virtuoso.dev/masonry";
8
+ import React, { useMemo, useRef } from "react";
7
9
  import { useResizeDetector } from "react-resize-detector";
8
- import { useScroller } from "@dxos/react-hooks";
9
- import { usePx } from "@dxos/react-ui";
10
- import { cardMaxInlineSize, cardMinInlineSize } from "@dxos/react-ui-theme";
11
- import { mx } from "@dxos/react-ui-theme";
12
- var usePxProps = (remProps) => {
13
- const remInPx = usePx(1);
14
- return useMemo(() => {
15
- return Object.fromEntries(Object.entries(remProps).filter(([_, value]) => Number.isFinite(value)).map(([key, value]) => {
16
- return [
17
- key,
18
- value * remInPx
19
- ];
20
- }));
21
- }, [
22
- remProps,
23
- remInPx
24
- ]);
25
- };
26
- var MasonryRootImpl = ({ columnCount, maxColumnCount, columnWidth = cardMinInlineSize, maxColumnWidth = cardMaxInlineSize, columnGutter = 1, rowGutter, items, itemHeightEstimate = 256, itemKey, overscanBy = 6, render, onRender, classNames, intrinsicHeight, ...props }, forwardedRef) => {
10
+ import { ScrollArea, usePx } from "@dxos/react-ui";
11
+ import { composable, composableProps, scrollbar } from "@dxos/react-ui";
12
+ import { cardMaxInlineSize, cardMinInlineSize } from "@dxos/ui-theme";
13
+ var MASONRY_NAME = "Masonry";
14
+ var [MasonryProvider, useMasonryContext] = createContext(MASONRY_NAME);
15
+ var [MasonryContentProvider, useMasonryContentContext] = createContext("Masonry.Content");
16
+ var MasonryRoot = ({ children, Tile, columns = void 0, maxColumns = void 0, minColumnWidth = cardMinInlineSize, maxColumnWidth = cardMaxInlineSize, gutter = 0.75 }) => /* @__PURE__ */ React.createElement(MasonryProvider, {
17
+ Tile,
18
+ columns,
19
+ maxColumns,
20
+ minColumnWidth,
21
+ maxColumnWidth,
22
+ gutter
23
+ }, children);
24
+ MasonryRoot.displayName = "Masonry.Root";
25
+ var MasonryContentInner = composable(({ children, centered, thin = true, padding = true, ...props }, forwardedRef) => {
27
26
  const rootRef = useRef(null);
28
- const ref = useComposedRefs(rootRef, forwardedRef);
29
- const { width = 0, height = 0 } = useResizeDetector({
27
+ const composedRef = useComposedRefs(rootRef, forwardedRef);
28
+ const { width = 0 } = useResizeDetector({
30
29
  targetRef: rootRef
31
30
  });
32
- const { scrollTop, isScrolling } = useScroller(rootRef);
33
- const remProps = useMemo(() => ({
34
- columnWidth,
35
- maxColumnWidth,
36
- columnGutter,
37
- rowGutter
38
- }), [
39
- columnWidth,
40
- maxColumnWidth,
41
- columnGutter,
42
- rowGutter
31
+ return /* @__PURE__ */ React.createElement(ScrollArea.Root, {
32
+ ...composableProps(props),
33
+ centered,
34
+ thin,
35
+ padding,
36
+ ref: composedRef
37
+ }, /* @__PURE__ */ React.createElement(MasonryContentProvider, {
38
+ width
39
+ }, children));
40
+ });
41
+ MasonryContentInner.displayName = "Masonry.Content";
42
+ var MasonryContent = MasonryContentInner;
43
+ var MasonryViewportInner = composable(({ items, getId, ...props }, forwardedRef) => {
44
+ const { Tile, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter } = useMasonryContext("Masonry.Viewport");
45
+ const { width } = useMasonryContentContext("Masonry.Viewport");
46
+ const columnCount = useColumnCount(width - (scrollbar.md.size + scrollbar.md.padding), columns, maxColumns, minColumnWidth, maxColumnWidth, gutter);
47
+ const arrowNavigationAttrs = useArrowNavigationGroup({
48
+ axis: "both",
49
+ memorizeCurrent: true,
50
+ tabbable: true
51
+ });
52
+ const TileAdapter = useMemo(() => {
53
+ const Adapter = ({ data, index }) => /* @__PURE__ */ React.createElement("div", {
54
+ role: "listitem",
55
+ style: {
56
+ paddingBottom: `${gutter}rem`
57
+ }
58
+ }, /* @__PURE__ */ React.createElement(Tile, {
59
+ index,
60
+ data
61
+ }));
62
+ Adapter.displayName = "Masonry.TileAdapter";
63
+ return Adapter;
64
+ }, [
65
+ Tile,
66
+ gutter
43
67
  ]);
44
- const pxProps = usePxProps(remProps);
45
- const numItems = items.length;
46
- const positionerProps = useMemo(() => ({
47
- width,
68
+ if (width <= 0) {
69
+ return null;
70
+ }
71
+ return /* @__PURE__ */ React.createElement(ScrollArea.Viewport, {
72
+ asChild: true
73
+ }, /* @__PURE__ */ React.createElement(ComposableVirtuosoMasonry, {
74
+ ...arrowNavigationAttrs,
75
+ ...composableProps(props),
76
+ ref: forwardedRef,
77
+ style: {
78
+ gap: `${gutter}rem`
79
+ },
80
+ data: items,
48
81
  columnCount,
49
- maxColumnCount: Math.max(maxColumnCount ?? 1, numItems),
50
- ...pxProps
51
- }), [
82
+ ItemContent: TileAdapter
83
+ }));
84
+ });
85
+ var ComposableVirtuosoMasonry = composable(({ ...props }, _forwardedRef) => {
86
+ return /* @__PURE__ */ React.createElement(VirtuosoMasonry, props);
87
+ });
88
+ MasonryViewportInner.displayName = "Masonry.Viewport";
89
+ var MasonryViewport = MasonryViewportInner;
90
+ var useColumnCount = (width, columns, maxColumns, minColumnWidth, maxColumnWidth, gutter) => {
91
+ const remInPx = usePx(1);
92
+ return useMemo(() => {
93
+ if (columns != null) {
94
+ return columns;
95
+ }
96
+ const minColumnWidthPx = minColumnWidth * remInPx;
97
+ const maxColumnWidthPx = maxColumnWidth * remInPx;
98
+ const gutterPx = gutter * remInPx;
99
+ if (width <= 0 || minColumnWidthPx <= 0) {
100
+ return 1;
101
+ }
102
+ let cols = Math.floor(width / (minColumnWidthPx + gutterPx));
103
+ if (maxColumnWidthPx > 0) {
104
+ const effectiveColWidth = width / cols - gutterPx;
105
+ if (effectiveColWidth > maxColumnWidthPx) {
106
+ const maxCols = Math.ceil(width / (maxColumnWidthPx + gutterPx));
107
+ if (width / maxCols - gutterPx >= minColumnWidthPx) {
108
+ cols = maxCols;
109
+ }
110
+ }
111
+ }
112
+ const clamped = maxColumns != null ? Math.min(cols, maxColumns) : cols;
113
+ return Math.max(1, clamped);
114
+ }, [
115
+ remInPx,
52
116
  width,
53
- columnCount,
54
- maxColumnCount,
55
- numItems,
56
- pxProps
57
- ]);
58
- const positioner = usePositioner(positionerProps, [
59
- positionerProps
117
+ columns,
118
+ maxColumns,
119
+ minColumnWidth,
120
+ maxColumnWidth,
121
+ gutter
60
122
  ]);
61
- const resizeObserver = useResizeObserver(positioner);
62
- const children = useMasonry({
63
- height: intrinsicHeight ? Infinity : height,
64
- scrollTop,
65
- isScrolling,
66
- resizeObserver,
67
- positioner,
68
- items,
69
- itemHeightEstimate,
70
- itemKey,
71
- overscanBy,
72
- render,
73
- onRender
74
- });
75
- return /* @__PURE__ */ React.createElement("div", {
76
- className: mx(classNames),
77
- ...props,
78
- ref
79
- }, children);
80
123
  };
81
- var MasonryRoot = /* @__PURE__ */ forwardRef(MasonryRootImpl);
82
124
  var Masonry = {
83
- Root: MasonryRoot
125
+ Root: MasonryRoot,
126
+ Content: MasonryContent,
127
+ Viewport: MasonryViewport
84
128
  };
85
129
  export {
86
130
  Masonry