@dxos/react-ui-masonry 0.8.4-main.ae835ea → 0.8.4-main.e8ec1fe

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.ae835ea",
3
+ "version": "0.8.4-main.e8ec1fe",
4
4
  "description": "A masonry component.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -24,7 +24,9 @@
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.ae835ea"
27
+ "react-resize-detector": "^11.0.1",
28
+ "@dxos/react-hooks": "0.8.4-main.e8ec1fe",
29
+ "@dxos/types": "0.8.4-main.e8ec1fe"
28
30
  },
29
31
  "devDependencies": {
30
32
  "@types/react": "~19.2.2",
@@ -33,25 +35,25 @@
33
35
  "react": "~19.2.0",
34
36
  "react-dom": "~19.2.0",
35
37
  "vite": "7.1.9",
36
- "@dxos/client": "0.8.4-main.ae835ea",
37
- "@dxos/echo": "0.8.4-main.ae835ea",
38
- "@dxos/random": "0.8.4-main.ae835ea",
39
- "@dxos/react-ui": "0.8.4-main.ae835ea",
40
- "@dxos/react-client": "0.8.4-main.ae835ea",
41
- "@dxos/react-ui-stack": "0.8.4-main.ae835ea",
42
- "@dxos/react-ui-theme": "0.8.4-main.ae835ea",
43
- "@dxos/schema": "0.8.4-main.ae835ea",
44
- "@dxos/storybook-utils": "0.8.4-main.ae835ea",
45
- "@dxos/react-ui-form": "0.8.4-main.ae835ea",
46
- "@dxos/test-utils": "0.8.4-main.ae835ea"
38
+ "@dxos/echo": "0.8.4-main.e8ec1fe",
39
+ "@dxos/react-client": "0.8.4-main.e8ec1fe",
40
+ "@dxos/react-ui": "0.8.4-main.e8ec1fe",
41
+ "@dxos/random": "0.8.4-main.e8ec1fe",
42
+ "@dxos/react-ui-form": "0.8.4-main.e8ec1fe",
43
+ "@dxos/react-ui-stack": "0.8.4-main.e8ec1fe",
44
+ "@dxos/client": "0.8.4-main.e8ec1fe",
45
+ "@dxos/storybook-utils": "0.8.4-main.e8ec1fe",
46
+ "@dxos/test-utils": "0.8.4-main.e8ec1fe",
47
+ "@dxos/react-ui-theme": "0.8.4-main.e8ec1fe",
48
+ "@dxos/schema": "0.8.4-main.e8ec1fe"
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.ae835ea",
53
- "@dxos/react-ui-theme": "0.8.4-main.ae835ea",
54
- "@dxos/react-ui": "0.8.4-main.ae835ea"
54
+ "@dxos/random": "0.8.4-main.e8ec1fe",
55
+ "@dxos/react-ui-theme": "0.8.4-main.e8ec1fe",
56
+ "@dxos/react-ui": "0.8.4-main.e8ec1fe"
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'>> &
@@ -57,13 +59,12 @@ const usePxProps = (remProps: Omit<UsePositionerOptions, 'width' | 'columnCount'
57
59
  }, [remProps, remInPx]);
58
60
  };
59
61
 
60
- // TODO(burdon): Currently not responsive to width.
61
62
  const MasonryRootImpl = <Item,>(
62
63
  {
63
64
  columnCount,
64
65
  maxColumnCount,
65
- columnWidth = 18, // cardMaxWidth
66
- maxColumnWidth = 22,
66
+ columnWidth = cardMinInlineSize,
67
+ maxColumnWidth = cardMaxInlineSize,
67
68
  columnGutter = 1,
68
69
  rowGutter,
69
70
  items,
@@ -80,21 +81,22 @@ const MasonryRootImpl = <Item,>(
80
81
  ) => {
81
82
  const rootRef = useRef<HTMLDivElement | null>(null);
82
83
  const ref = useComposedRefs(rootRef, forwardedRef);
83
- const { width, height } = useSize(rootRef);
84
+ const { width = 0, height = 0 } = useResizeDetector({ targetRef: rootRef });
84
85
  const { scrollTop, isScrolling } = useScroller(rootRef);
85
86
  const remProps = useMemo(
86
87
  () => ({ columnWidth, maxColumnWidth, columnGutter, rowGutter }),
87
88
  [columnWidth, maxColumnWidth, columnGutter, rowGutter],
88
89
  );
89
90
  const pxProps = usePxProps(remProps);
91
+ const numItems = items.length;
90
92
  const positionerProps = useMemo<UsePositionerOptions>(
91
93
  () => ({
92
94
  width,
93
95
  columnCount,
94
- maxColumnCount,
96
+ maxColumnCount: Math.max(maxColumnCount ?? 1, numItems),
95
97
  ...pxProps,
96
98
  }),
97
- [width, pxProps, columnCount, maxColumnCount],
99
+ [width, columnCount, maxColumnCount, numItems, pxProps],
98
100
  );
99
101
  const positioner = usePositioner(positionerProps, [positionerProps]);
100
102
  const resizeObserver = useResizeObserver(positioner);