@dxos/react-ui-masonry 0.8.4-main.2c6827d
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 +8 -0
- package/README.md +3 -0
- package/dist/lib/browser/index.mjs +86 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node-esm/index.mjs +88 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/Masonry.d.ts +13 -0
- package/dist/types/src/Masonry.d.ts.map +1 -0
- package/dist/types/src/Masonry.stories.d.ts +12 -0
- package/dist/types/src/Masonry.stories.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +61 -0
- package/src/Masonry.stories.tsx +70 -0
- package/src/Masonry.tsx +134 -0
- package/src/index.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
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:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/Masonry.tsx
|
|
2
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
3
|
+
import { useMasonry, usePositioner, useResizeObserver } from "masonic";
|
|
4
|
+
import React, { forwardRef, useMemo, useRef } from "react";
|
|
5
|
+
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) => {
|
|
25
|
+
const rootRef = useRef(null);
|
|
26
|
+
const ref = useComposedRefs(rootRef, forwardedRef);
|
|
27
|
+
const { width = 0, height = 0 } = useResizeDetector({
|
|
28
|
+
targetRef: rootRef
|
|
29
|
+
});
|
|
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
|
|
41
|
+
]);
|
|
42
|
+
const pxProps = usePxProps(remProps);
|
|
43
|
+
const numItems = items.length;
|
|
44
|
+
const positionerProps = useMemo(() => ({
|
|
45
|
+
width,
|
|
46
|
+
columnCount,
|
|
47
|
+
maxColumnCount: Math.max(maxColumnCount ?? 1, numItems),
|
|
48
|
+
...pxProps
|
|
49
|
+
}), [
|
|
50
|
+
width,
|
|
51
|
+
columnCount,
|
|
52
|
+
maxColumnCount,
|
|
53
|
+
numItems,
|
|
54
|
+
pxProps
|
|
55
|
+
]);
|
|
56
|
+
const positioner = usePositioner(positionerProps, [
|
|
57
|
+
positionerProps
|
|
58
|
+
]);
|
|
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
|
+
};
|
|
79
|
+
var MasonryRoot = /* @__PURE__ */ forwardRef(MasonryRootImpl);
|
|
80
|
+
var Masonry = {
|
|
81
|
+
Root: MasonryRoot
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
Masonry
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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,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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"]
|
|
7
|
+
}
|
|
@@ -0,0 +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}}}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/Masonry.tsx
|
|
4
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
5
|
+
import { useMasonry, usePositioner, useResizeObserver } from "masonic";
|
|
6
|
+
import React, { forwardRef, useMemo, useRef } from "react";
|
|
7
|
+
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) => {
|
|
27
|
+
const rootRef = useRef(null);
|
|
28
|
+
const ref = useComposedRefs(rootRef, forwardedRef);
|
|
29
|
+
const { width = 0, height = 0 } = useResizeDetector({
|
|
30
|
+
targetRef: rootRef
|
|
31
|
+
});
|
|
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
|
|
43
|
+
]);
|
|
44
|
+
const pxProps = usePxProps(remProps);
|
|
45
|
+
const numItems = items.length;
|
|
46
|
+
const positionerProps = useMemo(() => ({
|
|
47
|
+
width,
|
|
48
|
+
columnCount,
|
|
49
|
+
maxColumnCount: Math.max(maxColumnCount ?? 1, numItems),
|
|
50
|
+
...pxProps
|
|
51
|
+
}), [
|
|
52
|
+
width,
|
|
53
|
+
columnCount,
|
|
54
|
+
maxColumnCount,
|
|
55
|
+
numItems,
|
|
56
|
+
pxProps
|
|
57
|
+
]);
|
|
58
|
+
const positioner = usePositioner(positionerProps, [
|
|
59
|
+
positionerProps
|
|
60
|
+
]);
|
|
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
|
+
};
|
|
81
|
+
var MasonryRoot = /* @__PURE__ */ forwardRef(MasonryRootImpl);
|
|
82
|
+
var Masonry = {
|
|
83
|
+
Root: MasonryRoot
|
|
84
|
+
};
|
|
85
|
+
export {
|
|
86
|
+
Masonry
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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;\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B,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"]
|
|
7
|
+
}
|
|
@@ -0,0 +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/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6188},"dist/lib/node-esm/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":2579}}}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type UseMasonryOptions, type UsePositionerOptions } from 'masonic';
|
|
2
|
+
import { type ComponentPropsWithRef, type JSX, type Ref } from 'react';
|
|
3
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
4
|
+
type MasonryRootProps<Item> = ThemedClassName<ComponentPropsWithRef<'div'>> & Omit<UsePositionerOptions, 'width'> & Omit<UseMasonryOptions<Item>, 'height' | 'scrollTop' | 'isScrolling' | 'resizeObserver' | 'positioner' | 'as' | 'id' | 'itemAs' | 'itemStyle' | 'className' | 'style' | 'role' | 'tabIndex' | 'containerRef'> & {
|
|
5
|
+
intrinsicHeight?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const Masonry: {
|
|
8
|
+
Root: <Item>(props: MasonryRootProps<Item> & {
|
|
9
|
+
ref?: Ref<HTMLDivElement | null>;
|
|
10
|
+
}) => JSX.Element;
|
|
11
|
+
};
|
|
12
|
+
export type { MasonryRootProps };
|
|
13
|
+
//# sourceMappingURL=Masonry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Masonry.d.ts","sourceRoot":"","sources":["../../../src/Masonry.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAI1B,MAAM,SAAS,CAAC;AACjB,OAAc,EACZ,KAAK,qBAAqB,EAE1B,KAAK,GAAG,EACR,KAAK,GAAG,EAIT,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,KAAK,eAAe,EAAS,MAAM,gBAAgB,CAAC;AAI7D,KAAK,gBAAgB,CAAC,IAAI,IAAI,eAAe,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,GACzE,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC,GACnC,IAAI,CACF,iBAAiB,CAAC,IAAI,CAAC,EACrB,QAAQ,GACR,WAAW,GACX,aAAa,GACb,gBAAgB,GAChB,YAAY,GACZ,IAAI,GACJ,IAAI,GACJ,QAAQ,GACR,WAAW,GACX,WAAW,GACX,OAAO,GACP,MAAM,GACN,UAAU,GACV,cAAc,CACjB,GAAG;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAmFpC,eAAO,MAAM,OAAO;WANgC,IAAI,SAC/C,gBAAgB,CAAC,IAAI,CAAC,GAAG;QAC9B,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;KAClC,KACE,GAAG,CAAC,OAAO;CAIf,CAAC;AAEF,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type StoryObj } from '@storybook/react-vite';
|
|
2
|
+
declare const meta: {
|
|
3
|
+
title: string;
|
|
4
|
+
decorators: import("@storybook/react").Decorator[];
|
|
5
|
+
parameters: {
|
|
6
|
+
layout: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
type Story = StoryObj<typeof meta>;
|
|
11
|
+
export declare const Default: Story;
|
|
12
|
+
//# sourceMappingURL=Masonry.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Masonry.stories.d.ts","sourceRoot":"","sources":["../../../src/Masonry.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAwCjE,QAAA,MAAM,IAAI;;;;;;CAiBsB,CAAC;AAEjC,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAErB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC"}
|