@dxos/react-ui-masonry 0.8.4-main.406dc2a → 0.8.4-main.72ec0f3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-masonry",
3
- "version": "0.8.4-main.406dc2a",
3
+ "version": "0.8.4-main.72ec0f3",
4
4
  "description": "A masonry component.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -24,34 +24,36 @@
24
24
  "dependencies": {
25
25
  "@radix-ui/react-compose-refs": "1.1.1",
26
26
  "masonic": "^4.1.0",
27
- "@dxos/react-hooks": "0.8.4-main.406dc2a"
27
+ "react-resize-detector": "^11.0.1",
28
+ "@dxos/react-hooks": "0.8.4-main.72ec0f3",
29
+ "@dxos/types": "0.8.4-main.72ec0f3"
28
30
  },
29
31
  "devDependencies": {
30
32
  "@types/react": "~19.2.2",
31
- "@types/react-dom": "~19.2.1",
33
+ "@types/react-dom": "~19.2.2",
32
34
  "effect": "3.18.3",
33
35
  "react": "~19.2.0",
34
36
  "react-dom": "~19.2.0",
35
37
  "vite": "7.1.9",
36
- "@dxos/echo": "0.8.4-main.406dc2a",
37
- "@dxos/client": "0.8.4-main.406dc2a",
38
- "@dxos/random": "0.8.4-main.406dc2a",
39
- "@dxos/react-client": "0.8.4-main.406dc2a",
40
- "@dxos/react-ui-form": "0.8.4-main.406dc2a",
41
- "@dxos/react-ui-theme": "0.8.4-main.406dc2a",
42
- "@dxos/react-ui-stack": "0.8.4-main.406dc2a",
43
- "@dxos/storybook-utils": "0.8.4-main.406dc2a",
44
- "@dxos/schema": "0.8.4-main.406dc2a",
45
- "@dxos/react-ui": "0.8.4-main.406dc2a",
46
- "@dxos/test-utils": "0.8.4-main.406dc2a"
38
+ "@dxos/client": "0.8.4-main.72ec0f3",
39
+ "@dxos/echo": "0.8.4-main.72ec0f3",
40
+ "@dxos/random": "0.8.4-main.72ec0f3",
41
+ "@dxos/react-client": "0.8.4-main.72ec0f3",
42
+ "@dxos/react-ui": "0.8.4-main.72ec0f3",
43
+ "@dxos/react-ui-form": "0.8.4-main.72ec0f3",
44
+ "@dxos/react-ui-stack": "0.8.4-main.72ec0f3",
45
+ "@dxos/react-ui-theme": "0.8.4-main.72ec0f3",
46
+ "@dxos/schema": "0.8.4-main.72ec0f3",
47
+ "@dxos/storybook-utils": "0.8.4-main.72ec0f3",
48
+ "@dxos/test-utils": "0.8.4-main.72ec0f3"
47
49
  },
48
50
  "peerDependencies": {
49
51
  "effect": "^3.13.3",
50
52
  "react": "^19.0.0",
51
53
  "react-dom": "^19.0.0",
52
- "@dxos/random": "0.8.4-main.406dc2a",
53
- "@dxos/react-ui": "0.8.4-main.406dc2a",
54
- "@dxos/react-ui-theme": "0.8.4-main.406dc2a"
54
+ "@dxos/random": "0.8.4-main.72ec0f3",
55
+ "@dxos/react-ui": "0.8.4-main.72ec0f3",
56
+ "@dxos/react-ui-theme": "0.8.4-main.72ec0f3"
55
57
  },
56
58
  "publishConfig": {
57
59
  "access": "public"
@@ -12,12 +12,12 @@ import { useClientProvider, withClientProvider } from '@dxos/react-client/testin
12
12
  import { withTheme } from '@dxos/react-ui/testing';
13
13
  import { Card, cardNoSpacing, cardSpacing } from '@dxos/react-ui-stack';
14
14
  import { mx } from '@dxos/react-ui-theme';
15
- import { DataType } from '@dxos/schema';
16
15
  import { createObjectFactory } from '@dxos/schema/testing';
16
+ import { Organization } from '@dxos/types';
17
17
 
18
18
  import { Masonry } from './Masonry';
19
19
 
20
- const StoryItem = ({ data: { image, name, description } }: { data: DataType.Organization }) => {
20
+ const StoryItem = ({ data: { image, name, description } }: { data: Organization.Organization }) => {
21
21
  return (
22
22
  <Card.StaticRoot>
23
23
  <Card.Poster alt={name!} {...(image ? { image } : { icon: 'ph--building-office--regular' })} />
@@ -31,10 +31,10 @@ const StoryItem = ({ data: { image, name, description } }: { data: DataType.Orga
31
31
 
32
32
  const DefaultStory = () => {
33
33
  const { space } = useClientProvider();
34
- const organizations = useQuery(space, Filter.type(DataType.Organization));
34
+ const organizations = useQuery(space, Filter.type(Organization.Organization));
35
35
 
36
36
  return (
37
- <Masonry.Root<DataType.Organization>
37
+ <Masonry.Root<Organization.Organization>
38
38
  items={organizations}
39
39
  render={StoryItem}
40
40
  classNames='is-full max-is-full bs-full max-bs-full overflow-y-auto p-4'
@@ -47,12 +47,12 @@ const meta = {
47
47
  decorators: [
48
48
  withTheme,
49
49
  withClientProvider({
50
- types: [DataType.Organization],
50
+ types: [Organization.Organization],
51
51
  createIdentity: true,
52
52
  createSpace: true,
53
53
  onCreateSpace: async ({ space }) => {
54
54
  const factory = createObjectFactory(space.db, faker as any);
55
- await factory([{ type: DataType.Organization, count: 36 }]);
55
+ await factory([{ type: Organization.Organization, count: 36 }]);
56
56
  },
57
57
  }),
58
58
  ],
package/src/Masonry.tsx CHANGED
@@ -19,9 +19,11 @@ import React, {
19
19
  useMemo,
20
20
  useRef,
21
21
  } from 'react';
22
+ import { useResizeDetector } from 'react-resize-detector';
22
23
 
23
- import { useScroller, useSize } from '@dxos/react-hooks';
24
+ import { useScroller } from '@dxos/react-hooks';
24
25
  import { type ThemedClassName, usePx } from '@dxos/react-ui';
26
+ import { cardMaxInlineSize, cardMinInlineSize } from '@dxos/react-ui-theme';
25
27
  import { mx } from '@dxos/react-ui-theme';
26
28
 
27
29
  type MasonryRootProps<Item> = ThemedClassName<ComponentPropsWithRef<'div'>> &
@@ -61,8 +63,8 @@ const MasonryRootImpl = <Item,>(
61
63
  {
62
64
  columnCount,
63
65
  maxColumnCount,
64
- columnWidth = 18,
65
- maxColumnWidth,
66
+ columnWidth = cardMinInlineSize,
67
+ maxColumnWidth = cardMaxInlineSize,
66
68
  columnGutter = 1,
67
69
  rowGutter,
68
70
  items,
@@ -79,21 +81,22 @@ const MasonryRootImpl = <Item,>(
79
81
  ) => {
80
82
  const rootRef = useRef<HTMLDivElement | null>(null);
81
83
  const ref = useComposedRefs(rootRef, forwardedRef);
82
- const { width, height } = useSize(rootRef);
84
+ const { width = 0, height = 0 } = useResizeDetector({ targetRef: rootRef });
83
85
  const { scrollTop, isScrolling } = useScroller(rootRef);
84
86
  const remProps = useMemo(
85
87
  () => ({ columnWidth, maxColumnWidth, columnGutter, rowGutter }),
86
88
  [columnWidth, maxColumnWidth, columnGutter, rowGutter],
87
89
  );
88
90
  const pxProps = usePxProps(remProps);
89
- const positionerProps = useMemo(
91
+ const numItems = items.length;
92
+ const positionerProps = useMemo<UsePositionerOptions>(
90
93
  () => ({
91
94
  width,
92
95
  columnCount,
93
- maxColumnCount,
96
+ maxColumnCount: Math.max(maxColumnCount ?? 1, numItems),
94
97
  ...pxProps,
95
98
  }),
96
- [width, pxProps, columnCount, maxColumnCount],
99
+ [width, columnCount, maxColumnCount, numItems, pxProps],
97
100
  );
98
101
  const positioner = usePositioner(positionerProps, [positionerProps]);
99
102
  const resizeObserver = useResizeObserver(positioner);
@@ -110,6 +113,7 @@ const MasonryRootImpl = <Item,>(
110
113
  render,
111
114
  onRender,
112
115
  });
116
+
113
117
  return (
114
118
  <div className={mx(classNames)} {...props} ref={ref}>
115
119
  {children}