@dxos/react-ui-masonry 0.10.0 → 0.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-masonry",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "A masonry component.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,8 +16,7 @@
16
16
  ".": {
17
17
  "source": "./src/index.ts",
18
18
  "types": "./dist/types/src/index.d.ts",
19
- "browser": "./dist/lib/browser/index.mjs",
20
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "import": "./dist/lib/index.mjs"
21
20
  }
22
21
  },
23
22
  "types": "dist/types/src/index.d.ts",
@@ -29,12 +28,12 @@
29
28
  "@fluentui/react-tabster": "9.26.11",
30
29
  "@radix-ui/react-compose-refs": "1.1.1",
31
30
  "@radix-ui/react-context": "1.1.1",
32
- "@virtuoso.dev/masonry": "^1.4.2",
33
31
  "react-resize-detector": "^11.0.1",
34
- "@dxos/react-hooks": "0.10.0",
35
- "@dxos/react-ui-mosaic": "0.10.0",
36
- "@dxos/ui-types": "0.10.0",
37
- "@dxos/types": "0.10.0"
32
+ "@dxos/echo-react": "0.11.0",
33
+ "@dxos/react-hooks": "0.11.0",
34
+ "@dxos/react-ui-mosaic": "0.11.0",
35
+ "@dxos/types": "0.11.0",
36
+ "@dxos/ui-types": "0.11.0"
38
37
  },
39
38
  "devDependencies": {
40
39
  "@types/react": "~19.2.17",
@@ -42,25 +41,25 @@
42
41
  "effect": "3.21.4",
43
42
  "react": "~19.2.7",
44
43
  "react-dom": "~19.2.7",
45
- "vite": "^8.0.16",
46
- "@dxos/random": "0.10.0",
47
- "@dxos/client": "0.10.0",
48
- "@dxos/react-client": "0.10.0",
49
- "@dxos/react-ui-form": "0.10.0",
50
- "@dxos/react-ui": "0.10.0",
51
- "@dxos/schema": "0.10.0",
52
- "@dxos/storybook-utils": "0.10.0",
53
- "@dxos/test-utils": "0.10.0",
54
- "@dxos/ui-theme": "0.10.0",
55
- "@dxos/echo": "0.10.0"
44
+ "vite": "^8.1.4",
45
+ "@dxos/client": "0.11.0",
46
+ "@dxos/echo": "0.11.0",
47
+ "@dxos/random": "0.11.0",
48
+ "@dxos/react-ui-form": "0.11.0",
49
+ "@dxos/react-client": "0.11.0",
50
+ "@dxos/schema": "0.11.0",
51
+ "@dxos/storybook-utils": "0.11.0",
52
+ "@dxos/react-ui": "0.11.0",
53
+ "@dxos/ui-theme": "0.11.0",
54
+ "@dxos/test-utils": "0.11.0"
56
55
  },
57
56
  "peerDependencies": {
58
57
  "effect": "3.21.4",
59
58
  "react": "~19.2.7",
60
59
  "react-dom": "~19.2.7",
61
- "@dxos/random": "0.10.0",
62
- "@dxos/react-ui": "0.10.0",
63
- "@dxos/ui-theme": "0.10.0"
60
+ "@dxos/random": "^0.11.0",
61
+ "@dxos/ui-theme": "^0.11.0",
62
+ "@dxos/react-ui": "^0.11.0"
64
63
  },
65
64
  "publishConfig": {
66
65
  "access": "public"
@@ -3,71 +3,183 @@
3
3
  //
4
4
 
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
- import React from 'react';
6
+ import React, { useState } from 'react';
7
7
 
8
- import { Filter } from '@dxos/echo';
9
8
  import { random } from '@dxos/random';
10
- import { useQuery } from '@dxos/react-client/echo';
11
- import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
12
- import { Card, Icon } from '@dxos/react-ui';
9
+ import { Card, Panel, Toolbar } from '@dxos/react-ui';
13
10
  import { withLayout, withTheme } from '@dxos/react-ui/testing';
14
- import { createObjectFactory } from '@dxos/schema/testing';
15
- import { Organization } from '@dxos/types';
16
11
 
17
- import { Masonry, MasonryRootProps } from './Masonry';
12
+ import { Masonry, type MasonryRootProps } from './Masonry';
18
13
 
19
- const StoryItem = ({ data: { image, name, description } }: { data: Organization.Organization }) => {
14
+ random.seed(1);
15
+
16
+ /** Item counts the toolbar can switch between to exercise the layout under different loads. */
17
+ const ITEM_COUNTS = [10, 100, 200, 500] as const;
18
+
19
+ /** Fisher-Yates shuffle (seeded) so switching sets re-randomizes tile order. */
20
+ const shuffle = <T,>(array: readonly T[]): T[] => {
21
+ const copy = [...array];
22
+ for (let index = copy.length - 1; index > 0; index--) {
23
+ const swap = random.number.int({ min: 0, max: index });
24
+ [copy[index], copy[swap]] = [copy[swap], copy[index]];
25
+ }
26
+ return copy;
27
+ };
28
+
29
+ type PersonData = {
30
+ id: string;
31
+ fullName: string;
32
+ jobTitle?: string;
33
+ department?: string;
34
+ image?: string;
35
+ emails?: { value: string; label?: string }[];
36
+ notes?: string;
37
+ };
38
+
39
+ // A small fixed pool of inline (data-URI) images, cycled by index, so the bench is fully
40
+ // self-contained — even the 500 preset issues zero network requests. Distinct hues keep cards varied.
41
+ const IMAGE_POOL = [
42
+ '#e11d48',
43
+ '#db2777',
44
+ '#c026d3',
45
+ '#9333ea',
46
+ '#7c3aed',
47
+ '#4f46e5',
48
+ '#2563eb',
49
+ '#0891b2',
50
+ '#059669',
51
+ '#65a30d',
52
+ '#ca8a04',
53
+ '#ea580c',
54
+ ].map(
55
+ (color) =>
56
+ `data:image/svg+xml,${encodeURIComponent(
57
+ `<svg xmlns='http://www.w3.org/2000/svg' width='256' height='256'><rect width='256' height='256' fill='${color}'/></svg>`,
58
+ )}`,
59
+ );
60
+
61
+ // Generate plain (non-ECHO) data so even the largest preset mounts instantly — the masonry is a
62
+ // pure layout component, so seeding a database would only add unrelated cost. Variable notes and a
63
+ // cycled image make cards differ in height and exercise the column-balancing layout.
64
+ const createPeople = (count: number): PersonData[] =>
65
+ Array.from({ length: count }, (_, index) => {
66
+ const fullName = random.person.fullName();
67
+ const slug = fullName
68
+ .toLowerCase()
69
+ .replace(/[^a-z0-9]+/g, '.')
70
+ .replace(/^\.+|\.+$/g, '');
71
+ return {
72
+ id: `person-${index}`,
73
+ fullName,
74
+ jobTitle: random.person.jobTitle(),
75
+ department: random.commerce.department(),
76
+ image: IMAGE_POOL[index % IMAGE_POOL.length],
77
+ emails: [
78
+ { value: `${slug}@example.com` },
79
+ ...(index % 3 === 0 ? [{ label: 'work', value: `${slug}@work.example.com` }] : []),
80
+ ],
81
+ notes: index % 2 === 0 ? random.lorem.sentences(random.number.int({ min: 1, max: 4 })) : undefined,
82
+ };
83
+ });
84
+
85
+ // Seed the largest preset once so switching counts is a cheap slice.
86
+ const PEOPLE = createPeople(ITEM_COUNTS[ITEM_COUNTS.length - 1]);
87
+
88
+ const StoryItem = ({ data: person }: { data: PersonData }) => {
89
+ const { fullName, jobTitle, department, image, emails, notes } = person;
90
+ const role = [jobTitle, department].filter(Boolean).join(' · ');
20
91
  return (
21
92
  <Card.Root>
22
93
  <Card.Header>
23
- <Card.Block>
24
- <Icon icon='ph--building-office--regular' />
25
- </Card.Block>
26
- <Card.Title>{name}</Card.Title>
94
+ <Card.Title>{fullName}</Card.Title>
27
95
  </Card.Header>
28
- <Card.Poster alt={name!} {...(image ? { image } : { icon: 'ph--building-office--regular' })} />
29
- {description && (
96
+ {image && <Card.Poster alt={fullName ?? ''} image={image} />}
97
+ {role && (
98
+ <Card.Row classNames='px-2'>
99
+ <Card.Text variant='description'>{role}</Card.Text>
100
+ </Card.Row>
101
+ )}
102
+ {emails && emails.length > 0 && (
103
+ <Card.Row classNames='px-2'>
104
+ <Card.Text variant='description'>{emails.map((email) => email.value).join(', ')}</Card.Text>
105
+ </Card.Row>
106
+ )}
107
+ {notes && (
30
108
  <Card.Row classNames='px-2 pb-2'>
31
- <Card.Text variant='description'>{description}</Card.Text>
109
+ <Card.Text variant='description'>{notes}</Card.Text>
32
110
  </Card.Row>
33
111
  )}
34
112
  </Card.Root>
35
113
  );
36
114
  };
37
115
 
116
+ // A random subset of the generated people is rendered so the toolbar can switch the item count
117
+ // (bulk render under load, re-shuffled each time) and add/remove single tiles (the small-edit
118
+ // reflow animation).
38
119
  const DefaultStory = (props: MasonryRootProps) => {
39
- const { space } = useClientStory();
40
- const organizations = useQuery(space?.db, Filter.type(Organization.Organization));
120
+ const [visible, setVisible] = useState<PersonData[]>(() => shuffle(PEOPLE).slice(0, ITEM_COUNTS[0]));
121
+
122
+ const addOne = () =>
123
+ setVisible((current) => {
124
+ const shown = new Set(current.map((person) => person.id));
125
+ const candidates = PEOPLE.filter((person) => !shown.has(person.id));
126
+ if (candidates.length === 0) {
127
+ return current;
128
+ }
129
+ const person = candidates[random.number.int({ min: 0, max: candidates.length - 1 })];
130
+ const next = [...current];
131
+ next.splice(random.number.int({ min: 0, max: current.length }), 0, person);
132
+ return next;
133
+ });
134
+
135
+ const removeOne = () =>
136
+ setVisible((current) => {
137
+ if (current.length === 0) {
138
+ return current;
139
+ }
140
+ const index = random.number.int({ min: 0, max: current.length - 1 });
141
+ return current.filter((_, position) => position !== index);
142
+ });
41
143
 
42
144
  return (
43
- <Masonry.Root {...props} Tile={StoryItem}>
44
- <Masonry.Content centered>
45
- <Masonry.Viewport items={organizations} />
46
- </Masonry.Content>
47
- </Masonry.Root>
145
+ <Panel.Root>
146
+ <Panel.Toolbar asChild>
147
+ <Toolbar.Root>
148
+ {ITEM_COUNTS.map((count) => (
149
+ <Toolbar.Button key={count} onClick={() => setVisible(shuffle(PEOPLE).slice(0, count))}>
150
+ {count}
151
+ </Toolbar.Button>
152
+ ))}
153
+ <Toolbar.Button onClick={addOne}>Add one</Toolbar.Button>
154
+ <Toolbar.Button onClick={removeOne}>Remove one</Toolbar.Button>
155
+ <Toolbar.Button onClick={() => setVisible([])}>Clear</Toolbar.Button>
156
+ </Toolbar.Root>
157
+ </Panel.Toolbar>
158
+ <Panel.Content>
159
+ <Masonry.Root {...props} Tile={StoryItem}>
160
+ <Masonry.Content>
161
+ <Masonry.Viewport items={visible} getId={(person) => person.id} />
162
+ </Masonry.Content>
163
+ </Masonry.Root>
164
+ </Panel.Content>
165
+ </Panel.Root>
48
166
  );
49
167
  };
50
168
 
51
169
  const meta = {
52
170
  title: 'ui/react-ui-masonry/Masonry',
53
171
  render: DefaultStory,
54
- decorators: [
55
- withTheme(),
56
- withLayout({ layout: 'fullscreen' }),
57
- withClientProvider({
58
- types: [Organization.Organization],
59
- createIdentity: true,
60
- createSpace: true,
61
- onCreateSpace: async ({ space }) => {
62
- const factory = createObjectFactory(space.db, random as any);
63
- await factory([{ type: Organization.Organization, count: 36 }]);
64
- },
65
- }),
66
- ],
172
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
67
173
  parameters: {
68
174
  layout: 'fullscreen',
69
175
  },
70
- } satisfies Meta;
176
+ argTypes: {
177
+ animate: { control: 'boolean' },
178
+ },
179
+ args: {
180
+ animate: true,
181
+ },
182
+ } satisfies Meta<typeof DefaultStory>;
71
183
 
72
184
  export default meta;
73
185