@dxos/react-ui-masonry 0.10.0 → 0.11.1
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/dist/lib/index.mjs +482 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/types/src/Masonry.d.ts +43 -6
- package/dist/types/src/Masonry.d.ts.map +1 -1
- package/dist/types/src/Masonry.stories.d.ts +9 -1
- package/dist/types/src/Masonry.stories.d.ts.map +1 -1
- package/dist/types/src/layout.d.ts +50 -0
- package/dist/types/src/layout.d.ts.map +1 -0
- package/dist/types/src/layout.test.d.ts +2 -0
- package/dist/types/src/layout.test.d.ts.map +1 -0
- package/dist/types/src/useFlip.d.ts +37 -0
- package/dist/types/src/useFlip.d.ts.map +1 -0
- package/dist/types/src/useFlip.test.d.ts +2 -0
- package/dist/types/src/useFlip.test.d.ts.map +1 -0
- package/dist/types/src/useMasonryLayout.d.ts +42 -0
- package/dist/types/src/useMasonryLayout.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -22
- package/src/Masonry.stories.tsx +149 -37
- package/src/Masonry.tsx +238 -98
- package/src/layout.test.ts +108 -0
- package/src/layout.ts +105 -0
- package/src/useFlip.test.ts +34 -0
- package/src/useFlip.ts +137 -0
- package/src/useMasonryLayout.ts +241 -0
- package/dist/lib/browser/index.mjs +0 -138
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -140
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-masonry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
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
|
-
"
|
|
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
|
|
35
|
-
"@dxos/react-ui-mosaic": "0.
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/types": "0.
|
|
32
|
+
"@dxos/echo-react": "0.11.1",
|
|
33
|
+
"@dxos/react-ui-mosaic": "0.11.1",
|
|
34
|
+
"@dxos/react-hooks": "0.11.1",
|
|
35
|
+
"@dxos/types": "0.11.1",
|
|
36
|
+
"@dxos/ui-types": "0.11.1"
|
|
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.
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/react-
|
|
50
|
-
"@dxos/react-ui": "0.
|
|
51
|
-
"@dxos/schema": "0.
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
44
|
+
"vite": "^8.1.4",
|
|
45
|
+
"@dxos/client": "0.11.1",
|
|
46
|
+
"@dxos/echo": "0.11.1",
|
|
47
|
+
"@dxos/random": "0.11.1",
|
|
48
|
+
"@dxos/react-client": "0.11.1",
|
|
49
|
+
"@dxos/react-ui-form": "0.11.1",
|
|
50
|
+
"@dxos/schema": "0.11.1",
|
|
51
|
+
"@dxos/react-ui": "0.11.1",
|
|
52
|
+
"@dxos/ui-theme": "0.11.1",
|
|
53
|
+
"@dxos/test-utils": "0.11.1",
|
|
54
|
+
"@dxos/storybook-utils": "0.11.1"
|
|
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.
|
|
62
|
-
"@dxos/react-ui": "0.
|
|
63
|
-
"@dxos/ui-theme": "0.
|
|
60
|
+
"@dxos/random": "^0.11.1",
|
|
61
|
+
"@dxos/react-ui": "^0.11.1",
|
|
62
|
+
"@dxos/ui-theme": "^0.11.1"
|
|
64
63
|
},
|
|
65
64
|
"publishConfig": {
|
|
66
65
|
"access": "public"
|
package/src/Masonry.stories.tsx
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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.
|
|
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={
|
|
29
|
-
{
|
|
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'>{
|
|
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
|
|
40
|
-
|
|
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
|
-
<
|
|
44
|
-
<
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
|