@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 +102 -5
- package/dist/lib/browser/index.mjs +113 -69
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +113 -69
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/Masonry.d.ts +39 -7
- package/dist/types/src/Masonry.d.ts.map +1 -1
- package/dist/types/src/Masonry.stories.d.ts +3 -0
- package/dist/types/src/Masonry.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -29
- package/src/Masonry.stories.tsx +31 -27
- package/src/Masonry.tsx +229 -115
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
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 {
|
|
4
|
-
import
|
|
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 {
|
|
7
|
-
import {
|
|
8
|
-
import { cardMaxInlineSize, cardMinInlineSize } from "@dxos/
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
27
|
-
const { width = 0
|
|
25
|
+
const composedRef = useComposedRefs(rootRef, forwardedRef);
|
|
26
|
+
const { width = 0 } = useResizeDetector({
|
|
28
27
|
targetRef: rootRef
|
|
29
28
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 {
|
|
5
|
-
"mappings": ";AAIA,SAASA,uBAAuB;AAChC,
|
|
6
|
-
"names": ["
|
|
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": ";AAIA,SAASA,+BAA+B;AACxC,SAASC,uBAAuB;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B2C;AAC1C,UAAME,mBAAmB5C,iBAAiB0C;AAC1C,UAAMG,WAAW5C,SAASyC;AAC1B,QAAI/B,SAAS,KAAKgC,oBAAoB,GAAG;AACvC,aAAO;IACT;AAIA,QAAIG,OAAOC,KAAKC,MAAMrC,SAASgC,mBAAmBE,SAAO;AACzD,QAAID,mBAAmB,GAAG;AACxB,YAAMK,oBAAoBtC,QAAQmC,OAAOD;AACzC,UAAII,oBAAoBL,kBAAkB;AAExC,cAAMM,UAAUH,KAAKI,KAAKxC,SAASiC,mBAAmBC,SAAO;AAC7D,YAAIlC,QAAQuC,UAAUL,YAAYF,kBAAkB;AAClDG,iBAAOI;QACT;MACF;IACF;AAEA,UAAME,UAAUtD,cAAc,OAAOiD,KAAKM,IAAIP,MAAMhD,UAAAA,IAAcgD;AAClE,WAAOC,KAAKO,IAAI,GAAGF,OAAAA;EACrB,GAAG;IAACV;IAAS/B;IAAOf;IAASE;IAAYC;IAAgBC;IAAgBC;GAAO;AAClF;AAMO,IAAMsD,UAAU;EACrB1C,MAAMpB;EACN+D,SAASzC;EACToB,UAAUM;AACZ;",
|
|
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":
|
|
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 {
|
|
6
|
-
import
|
|
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 {
|
|
9
|
-
import {
|
|
10
|
-
import { cardMaxInlineSize, cardMinInlineSize } from "@dxos/
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
29
|
-
const { width = 0
|
|
27
|
+
const composedRef = useComposedRefs(rootRef, forwardedRef);
|
|
28
|
+
const { width = 0 } = useResizeDetector({
|
|
30
29
|
targetRef: rootRef
|
|
31
30
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|