@dxos/react-ui-thread 0.8.3-staging.0fa589b → 0.8.4-main.1068cf700f

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,15 +1,20 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-thread",
3
- "version": "0.8.3-staging.0fa589b",
3
+ "version": "0.8.4-main.1068cf700f",
4
4
  "description": "A set of components to use with threads, including comments and messages.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
- "sideEffects": true,
13
+ "sideEffects": false,
10
14
  "type": "module",
11
15
  "exports": {
12
16
  ".": {
17
+ "source": "./src/index.ts",
13
18
  "types": "./dist/types/src/index.d.ts",
14
19
  "browser": "./dist/lib/browser/index.mjs"
15
20
  }
@@ -23,35 +28,32 @@
23
28
  "src"
24
29
  ],
25
30
  "dependencies": {
26
- "@preact-signals/safe-react": "^0.9.0",
27
31
  "@radix-ui/react-primitive": "2.0.2",
28
32
  "date-fns": "^3.3.1",
29
- "@dxos/react-ui-editor": "0.8.3-staging.0fa589b",
30
- "@dxos/util": "0.8.3-staging.0fa589b"
33
+ "@dxos/react-ui-editor": "0.8.4-main.1068cf700f",
34
+ "@dxos/util": "0.8.4-main.1068cf700f",
35
+ "@dxos/ui-editor": "0.8.4-main.1068cf700f"
31
36
  },
32
37
  "devDependencies": {
33
- "@phosphor-icons/react": "^2.1.5",
34
- "@types/react": "~18.2.0",
35
- "@types/react-dom": "~18.2.0",
36
- "react": "~18.2.0",
37
- "react-dom": "~18.2.0",
38
- "vite": "5.4.7",
39
- "@dxos/echo-db": "0.8.3-staging.0fa589b",
40
- "@dxos/echo-schema": "0.8.3-staging.0fa589b",
41
- "@dxos/keys": "0.8.3-staging.0fa589b",
42
- "@dxos/live-object": "0.8.3-staging.0fa589b",
43
- "@dxos/log": "0.8.3-staging.0fa589b",
44
- "@dxos/random": "0.8.3-staging.0fa589b",
45
- "@dxos/react-ui-theme": "0.8.3-staging.0fa589b",
46
- "@dxos/react-ui": "0.8.3-staging.0fa589b",
47
- "@dxos/storybook-utils": "0.8.3-staging.0fa589b"
38
+ "@types/react": "~19.2.7",
39
+ "@types/react-dom": "~19.2.3",
40
+ "react": "~19.2.3",
41
+ "react-dom": "~19.2.3",
42
+ "vite": "7.1.9",
43
+ "@dxos/keys": "0.8.4-main.1068cf700f",
44
+ "@dxos/echo-db": "0.8.4-main.1068cf700f",
45
+ "@dxos/echo": "0.8.4-main.1068cf700f",
46
+ "@dxos/log": "0.8.4-main.1068cf700f",
47
+ "@dxos/random": "0.8.4-main.1068cf700f",
48
+ "@dxos/react-ui": "0.8.4-main.1068cf700f",
49
+ "@dxos/ui-theme": "0.8.4-main.1068cf700f",
50
+ "@dxos/storybook-utils": "0.8.4-main.1068cf700f"
48
51
  },
49
52
  "peerDependencies": {
50
- "@phosphor-icons/react": "^2.1.5",
51
- "react": "~18.2.0",
52
- "react-dom": "~18.2.0",
53
- "@dxos/react-ui": "0.8.3-staging.0fa589b",
54
- "@dxos/react-ui-theme": "0.8.3-staging.0fa589b"
53
+ "react": "~19.2.3",
54
+ "react-dom": "~19.2.3",
55
+ "@dxos/ui-theme": "0.8.4-main.1068cf700f",
56
+ "@dxos/react-ui": "0.8.4-main.1068cf700f"
55
57
  },
56
58
  "publishConfig": {
57
59
  "access": "public"
@@ -2,18 +2,18 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
7
6
  import React, { useState } from 'react';
8
7
 
9
8
  import { PublicKey } from '@dxos/keys';
10
- import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/react-ui-theme';
11
- import { withLayout, withTheme } from '@dxos/storybook-utils';
9
+ import { withTheme } from '@dxos/react-ui/testing';
10
+ import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/ui-theme';
11
+
12
+ import { type MessageEntity, MessageStoryText } from '../testing';
13
+ import { Thread } from '../Thread';
14
+ import { translations } from '../translations';
12
15
 
13
16
  import { MessageRoot } from './Message';
14
- import { threadLayout } from '../Thread';
15
- import { ThreadStoryContainer, MessageStoryText, type MessageEntity } from '../testing';
16
- import translations from '../translations';
17
17
 
18
18
  const DefaultStory = () => {
19
19
  const [identityKey] = useState(PublicKey.random());
@@ -25,22 +25,29 @@ const DefaultStory = () => {
25
25
  });
26
26
 
27
27
  return (
28
- <ThreadStoryContainer>
29
- <div className={threadLayout}>
28
+ <div className='mli-auto is-96 overflow-y-auto'>
29
+ <Thread.Root id='t1'>
30
30
  <MessageRoot {...message} classNames={[hoverableControls, hoverableFocusedWithinControls]}>
31
31
  <MessageStoryText {...message} onDelete={() => console.log('delete')} />
32
32
  </MessageRoot>
33
- </div>
34
- </ThreadStoryContainer>
33
+ </Thread.Root>
34
+ </div>
35
35
  );
36
36
  };
37
37
 
38
- export default {
38
+ const meta = {
39
39
  title: 'ui/react-ui-thread/Message',
40
- component: MessageRoot,
40
+ component: MessageRoot as any,
41
41
  render: DefaultStory,
42
- decorators: [withTheme, withLayout({ fullscreen: true })],
43
- parameters: { translations },
44
- };
42
+ decorators: [withTheme()],
43
+ parameters: {
44
+ layout: 'fullscreen',
45
+ translations,
46
+ },
47
+ } satisfies Meta<typeof DefaultStory>;
48
+
49
+ export default meta;
50
+
51
+ type Story = StoryObj<typeof meta>;
45
52
 
46
- export const Default = {};
53
+ export const Default: Story = {};
@@ -3,13 +3,13 @@
3
3
  //
4
4
 
5
5
  import { formatDistanceToNow } from 'date-fns/formatDistanceToNow';
6
- import React, { type ComponentPropsWithRef, forwardRef, type ComponentPropsWithoutRef } from 'react';
6
+ import React, { type ComponentPropsWithRef, type ComponentPropsWithoutRef, forwardRef } from 'react';
7
7
 
8
- // TODO(burdon): Remove dep.
9
8
  import { Avatar, type ThemedClassName, useTranslation } from '@dxos/react-ui';
10
- import { type UseTextEditorProps, keymap, listener, useTextEditor } from '@dxos/react-ui-editor';
11
- import { focusRing, mx } from '@dxos/react-ui-theme';
12
- import { hexToEmoji, hexToHue, isNotFalsy } from '@dxos/util';
9
+ import { type UseTextEditorProps, useTextEditor } from '@dxos/react-ui-editor';
10
+ import { keymap, listener } from '@dxos/ui-editor';
11
+ import { focusRing, mx } from '@dxos/ui-theme';
12
+ import { hexToEmoji, hexToHue, isTruthy } from '@dxos/util';
13
13
 
14
14
  import { translationKey } from '../translations';
15
15
  import { type MessageMetadata } from '../types';
@@ -20,6 +20,7 @@ export type MessageRootProps = ThemedClassName<ComponentPropsWithRef<'div'>> &
20
20
  MessageMetadata &
21
21
  Partial<{ continues: boolean }>;
22
22
 
23
+ // TODO(burdon): Show authorName on tooltip.
23
24
  export const MessageRoot = forwardRef<HTMLDivElement, MessageRootProps>(
24
25
  (
25
26
  { authorImgSrc, authorId, authorName, authorAvatarProps, continues = true, children, classNames, ...rootProps },
@@ -35,7 +36,7 @@ export const MessageRoot = forwardRef<HTMLDivElement, MessageRootProps>(
35
36
  className={mx('grid grid-cols-subgrid col-span-2', classNames)}
36
37
  ref={forwardedRef}
37
38
  >
38
- <div role='none' className='flex flex-col items-center gap-2 pbs-2'>
39
+ <div role='none' className='flex flex-col items-center gap-2 pbs-1'>
39
40
  <Avatar.Content
40
41
  size={avatarSize}
41
42
  hue={authorAvatarProps?.hue || hexToHue(authorId ?? '0')}
@@ -148,14 +149,14 @@ export const MessageTextbox = ({
148
149
  extensions: [
149
150
  keymap.of(keyBindings({ onSend, onClear })),
150
151
  listener({
151
- onFocus: (focusing) => {
152
+ onFocus: ({ focusing }) => {
152
153
  if (focusing) {
153
154
  onEditorFocus?.();
154
155
  }
155
156
  },
156
157
  }),
157
158
  extensions,
158
- ].filter(isNotFalsy),
159
+ ].filter(isTruthy),
159
160
  ...editorProps,
160
161
  }),
161
162
  [id, extensions],
@@ -2,50 +2,67 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
- import { Check, Trash } from '@phosphor-icons/react';
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
6
  import React, { type FC, useEffect, useMemo, useRef, useState } from 'react';
9
7
 
10
- import { createDocAccessor, createObject } from '@dxos/echo-db';
11
- import { Expando } from '@dxos/echo-schema';
8
+ import { Obj } from '@dxos/echo';
9
+ import { TestSchema } from '@dxos/echo/testing';
12
10
  import { PublicKey } from '@dxos/keys';
13
- import { live } from '@dxos/live-object';
14
11
  import { log } from '@dxos/log';
15
12
  import { faker } from '@dxos/random';
16
- import { Button, useThemeContext } from '@dxos/react-ui';
13
+ import { Icon, IconButton, useThemeContext } from '@dxos/react-ui';
14
+ import { withTheme } from '@dxos/react-ui/testing';
15
+ import { useTextEditor } from '@dxos/react-ui-editor';
17
16
  import {
18
17
  type Comment,
19
18
  type CommentsOptions,
19
+ type EditorView,
20
20
  type Range,
21
- automerge,
22
21
  comments,
23
22
  createBasicExtensions,
24
23
  createThemeExtensions,
24
+ documentId,
25
25
  listener,
26
26
  scrollThreadIntoView,
27
- useComments,
28
- useTextEditor,
29
- } from '@dxos/react-ui-editor';
30
- import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/react-ui-theme';
31
- import { withTheme } from '@dxos/storybook-utils';
27
+ setComments,
28
+ } from '@dxos/ui-editor';
29
+ import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/ui-theme';
32
30
 
33
- import { Thread, ThreadFooter, ThreadHeading } from './Thread';
34
31
  import { MessageBody, MessageHeading, MessageRoot, MessageTextbox } from '../Message';
35
32
  import { type MessageEntity } from '../testing';
36
- import translations from '../translations';
33
+ import { translations } from '../translations';
34
+
35
+ import { Thread } from './Thread';
37
36
 
38
37
  faker.seed(101);
39
38
 
40
39
  const authorId = PublicKey.random().toHex();
41
40
 
41
+ /**
42
+ * @deprecated This hook will be removed in future versions. Use the new comment sync extension instead.
43
+ * Update comments state field.
44
+ */
45
+ const useComments = (view: EditorView | null | undefined, id: string, comments?: Comment[]) => {
46
+ useEffect(() => {
47
+ if (view) {
48
+ // Check same document.
49
+ // NOTE: Hook might be called before editor state is updated.
50
+ if (id === view.state.facet(documentId)) {
51
+ view.dispatch({
52
+ effects: setComments.of({ id, comments: comments ?? [] }),
53
+ });
54
+ }
55
+ }
56
+ });
57
+ };
58
+
42
59
  //
43
60
  // Editor
44
61
  //
45
62
 
46
63
  const Editor: FC<{
47
64
  id?: string;
48
- item: Expando;
65
+ initialValue: string;
49
66
  comments: Comment[];
50
67
  selected?: string;
51
68
  onCreateComment: CommentsOptions['onCreate'];
@@ -54,7 +71,7 @@ const Editor: FC<{
54
71
  onSelectComment: CommentsOptions['onSelect'];
55
72
  }> = ({
56
73
  id = 'test',
57
- item,
74
+ initialValue,
58
75
  selected: selectedValue,
59
76
  comments: commentRanges,
60
77
  onCreateComment,
@@ -68,11 +85,10 @@ const Editor: FC<{
68
85
  const { parentRef, view } = useTextEditor(
69
86
  () => ({
70
87
  id,
71
- initialValue: item.content,
88
+ initialValue: initialValue,
72
89
  extensions: [
73
90
  createBasicExtensions(),
74
91
  createThemeExtensions({ themeMode }),
75
- automerge(createDocAccessor(item, ['content'])),
76
92
  comments({
77
93
  id,
78
94
  onCreate: onCreateComment,
@@ -82,7 +98,7 @@ const Editor: FC<{
82
98
  }),
83
99
  ],
84
100
  }),
85
- [id, item, themeMode],
101
+ [id, initialValue, themeMode],
86
102
  );
87
103
  useComments(view, id, commentRanges);
88
104
  useEffect(() => {
@@ -115,19 +131,21 @@ const StoryThread: FC<{
115
131
  onSelect: () => void;
116
132
  onResolve: () => void;
117
133
  }> = ({ thread, selected, onSelect, onResolve }) => {
118
- const containerRef = useRef<HTMLDivElement>(null);
119
134
  const { themeMode } = useThemeContext();
135
+ const containerRef = useRef<HTMLDivElement>(null);
136
+
120
137
  // TODO(wittjosiah): This is a hack to reset the editor after a message is sent.
121
- const [_count, _setCount] = useState(0);
122
- const rerenderEditor = () => _setCount((count) => count + 1);
138
+ const [state, setState] = useState({});
123
139
  const messageRef = useRef('');
124
140
  const extensions = useMemo(
125
141
  () => [
126
142
  createBasicExtensions({ placeholder: 'Enter comment' }),
127
143
  createThemeExtensions({ themeMode }),
128
- listener({ onChange: (text) => (messageRef.current = text) }),
144
+ listener({
145
+ onChange: ({ text }) => (messageRef.current = text),
146
+ }),
129
147
  ],
130
- [themeMode, _count],
148
+ [themeMode, state],
131
149
  );
132
150
 
133
151
  const [autoFocus, setAutoFocus] = useState(false);
@@ -143,7 +161,7 @@ const StoryThread: FC<{
143
161
 
144
162
  const handleCreateMessage = () => {
145
163
  if (messageRef.current?.length) {
146
- const message = live(Expando, {
164
+ const message = Obj.make(TestSchema.Expando, {
147
165
  timestamp: new Date().toISOString(),
148
166
  sender: { identityKey: authorId },
149
167
  text: messageRef.current,
@@ -152,22 +170,22 @@ const StoryThread: FC<{
152
170
 
153
171
  messageRef.current = '';
154
172
  setAutoFocus(true);
155
- rerenderEditor();
173
+ setState({});
156
174
  }
157
175
  };
158
176
 
159
177
  return (
160
- <Thread current={selected} onClickCapture={onSelect}>
178
+ <Thread.Root current={selected} onClickCapture={onSelect}>
161
179
  <div className='col-start-2 flex gap-1 text-xs text-description'>
162
180
  <span>id:{thread.id.slice(0, 4)}</span>
163
181
  <span>y:{thread.yPos}</span>
164
182
  <span className='grow' />
165
- {!thread.cursor && <Trash />}
183
+ {!thread.cursor && <Icon icon='ph--trash--regular' />}
166
184
  </div>
167
185
 
168
- <ThreadHeading>
186
+ <Thread.Header>
169
187
  {thread.range?.from} &ndash; {thread.range?.to}
170
- </ThreadHeading>
188
+ </Thread.Header>
171
189
 
172
190
  {thread.messages.map((message) => (
173
191
  <MessageRoot key={message.id} classNames={[hoverableControls, hoverableFocusedWithinControls]} {...message}>
@@ -185,21 +203,28 @@ const StoryThread: FC<{
185
203
  onEditorFocus={onSelect}
186
204
  onSend={handleCreateMessage}
187
205
  />
188
- <ThreadFooter />
189
- <Button variant='ghost' classNames='px-1' title='Resolve' onClick={onResolve}>
190
- <Check />
191
- </Button>
206
+ <Thread.Status />
207
+ <IconButton
208
+ variant='ghost'
209
+ icon='ph--check--regular'
210
+ iconOnly
211
+ classNames='pli-1'
212
+ label='Resolve'
213
+ onClick={onResolve}
214
+ />
192
215
  </div>
193
- </Thread>
216
+ </Thread.Root>
194
217
  );
195
218
  };
196
219
 
197
- const Sidebar: FC<{
220
+ type SidebarProps = {
198
221
  threads: StoryCommentThread[];
199
222
  selected?: string;
200
223
  onSelect: (thread: string) => void;
201
224
  onResolve: (thread: string) => void;
202
- }> = ({ threads, selected, onSelect, onResolve }) => {
225
+ };
226
+
227
+ const Sidebar = ({ threads, selected, onSelect, onResolve }: SidebarProps) => {
203
228
  // Sort by y-position.
204
229
  const sortedThreads = useMemo(() => {
205
230
  const sorted = [...threads];
@@ -232,8 +257,8 @@ type StoryProps = {
232
257
  autoCreate?: boolean;
233
258
  };
234
259
 
235
- const Story = ({ text, autoCreate }: StoryProps) => {
236
- const [item] = useState(createObject(live(Expando, { content: text ?? '' })));
260
+ const DefaultStory = ({ text, autoCreate }: StoryProps) => {
261
+ const [item] = useState(() => Obj.make(TestSchema.Expando, { content: text ?? '' }));
237
262
  const [threads, setThreads] = useState<StoryCommentThread[]>([]);
238
263
  const [selected, setSelected] = useState<string>();
239
264
 
@@ -327,7 +352,7 @@ const Story = ({ text, autoCreate }: StoryProps) => {
327
352
  <main className='fixed inset-0 grid grid-cols-[1fr_24rem]'>
328
353
  <div role='none' className='max-bs-full overflow-y-auto p-4'>
329
354
  <Editor
330
- item={item}
355
+ initialValue={item.content}
331
356
  selected={selected}
332
357
  comments={comments}
333
358
  onCreateComment={handleCreateComment}
@@ -349,25 +374,30 @@ const Story = ({ text, autoCreate }: StoryProps) => {
349
374
  );
350
375
  };
351
376
 
352
- export default {
377
+ const meta = {
353
378
  title: 'ui/react-ui-thread/Comments',
354
- component: StoryThread,
355
- decorators: [withTheme],
356
- render: (args: StoryProps) => <Story {...args} />,
357
- parameters: { translations, layout: 'fullscreen' },
358
- };
379
+ component: StoryThread as any,
380
+ render: DefaultStory,
381
+ decorators: [withTheme()],
382
+ parameters: {
383
+ translations,
384
+ layout: 'fullscreen',
385
+ },
386
+ } satisfies Meta<typeof DefaultStory>;
359
387
 
360
- const str = (...lines: string[]) => lines.join('\n');
388
+ export default meta;
361
389
 
362
- const document = str(
363
- '# Comments',
364
- '',
365
- str(...faker.helpers.multiple(() => [faker.lorem.paragraph({ min: 5, max: 10 }), ''], { count: 20 }).flat()),
366
- '',
367
- );
390
+ type Story = StoryObj<typeof meta>;
391
+
392
+ const str = (...lines: string[]) => lines.join('\n');
368
393
 
369
- export const Default = {
394
+ export const Default: Story = {
370
395
  args: {
371
- text: document,
396
+ text: str(
397
+ '# Comments',
398
+ '',
399
+ str(...faker.helpers.multiple(() => [faker.lorem.paragraph({ min: 5, max: 10 }), ''], { count: 20 }).flat()),
400
+ '',
401
+ ),
372
402
  },
373
403
  };
@@ -2,20 +2,20 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
7
6
  import React, { useMemo, useRef, useState } from 'react';
8
7
 
9
8
  import { PublicKey } from '@dxos/keys';
10
9
  import { faker } from '@dxos/random';
11
- import { createBasicExtensions, createThemeExtensions } from '@dxos/react-ui-editor';
12
- import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/react-ui-theme';
13
- import { withLayout, withTheme } from '@dxos/storybook-utils';
10
+ import { withTheme } from '@dxos/react-ui/testing';
11
+ import { createBasicExtensions, createThemeExtensions } from '@dxos/ui-editor';
12
+ import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/ui-theme';
14
13
 
15
- import { Thread, ThreadFooter } from './Thread';
16
14
  import { MessageRoot, MessageTextbox } from '../Message';
17
- import { ThreadStoryContainer, MessageStoryText, type MessageEntity } from '../testing';
18
- import translations from '../translations';
15
+ import { type MessageEntity, MessageStoryText } from '../testing';
16
+ import { translations } from '../translations';
17
+
18
+ import { Thread } from './Thread';
19
19
 
20
20
  faker.seed(1);
21
21
 
@@ -59,13 +59,14 @@ const DefaultStory = () => {
59
59
  };
60
60
 
61
61
  return (
62
- <ThreadStoryContainer>
63
- <Thread id='t1'>
62
+ <div className='mli-auto is-96 overflow-y-auto'>
63
+ <Thread.Root id='t1'>
64
64
  {messages.map((message) => (
65
65
  <MessageRoot key={message.id} classNames={[hoverableControls, hoverableFocusedWithinControls]} {...message}>
66
66
  <MessageStoryText {...message} text={message.text} onDelete={() => console.log('delete')} />
67
67
  </MessageRoot>
68
68
  ))}
69
+
69
70
  <MessageTextbox
70
71
  id={String(_count)}
71
72
  authorId={identityKey1.toHex()}
@@ -73,18 +74,26 @@ const DefaultStory = () => {
73
74
  extensions={extensions}
74
75
  onSend={handleSend}
75
76
  />
76
- <ThreadFooter activity>Processing...</ThreadFooter>
77
- </Thread>
78
- </ThreadStoryContainer>
77
+
78
+ <Thread.Status activity>Processing...</Thread.Status>
79
+ </Thread.Root>
80
+ </div>
79
81
  );
80
82
  };
81
83
 
82
- export default {
84
+ const meta = {
83
85
  title: 'ui/react-ui-thread/Thread',
84
- component: Thread,
86
+ component: Thread.Root,
85
87
  render: DefaultStory,
86
- decorators: [withTheme, withLayout({ fullscreen: true })],
87
- parameters: { translations },
88
- };
88
+ decorators: [withTheme()],
89
+ parameters: {
90
+ layout: 'fullscreen',
91
+ translations,
92
+ },
93
+ } satisfies Meta<typeof Thread.Root>;
94
+
95
+ export default meta;
96
+
97
+ type Story = StoryObj<typeof meta>;
89
98
 
90
- export const Default = {};
99
+ export const Default: Story = {};
@@ -2,20 +2,24 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { CaretDoubleRight, Spinner } from '@phosphor-icons/react';
6
5
  import React, { type ComponentPropsWithRef, forwardRef } from 'react';
7
6
 
8
- import { type ThemedClassName, useTranslation } from '@dxos/react-ui';
9
- import { hoverableControlItem, hoverableFocusedWithinControls, mx } from '@dxos/react-ui-theme';
7
+ import { Icon, type ThemedClassName, useTranslation } from '@dxos/react-ui';
8
+ import { hoverableControlItem, hoverableFocusedWithinControls, mx } from '@dxos/ui-theme';
10
9
 
11
10
  import { translationKey } from '../translations';
12
11
  import type { ThreadEntity } from '../types';
13
12
 
14
- export type ThreadProps = ThemedClassName<ComponentPropsWithRef<'div'>> & ThreadEntity & { current?: boolean };
15
-
13
+ // TODO(burdon): Avoid exporting fragments.
16
14
  export const threadLayout = 'is-full place-self-start grid grid-cols-[var(--rail-size)_1fr]';
17
15
 
18
- export const Thread = forwardRef<HTMLDivElement, ThreadProps>(
16
+ //
17
+ // Root
18
+ //
19
+
20
+ type ThreadRootProps = ThemedClassName<ComponentPropsWithRef<'div'>> & ThreadEntity & { current?: boolean };
21
+
22
+ const ThreadRoot = forwardRef<HTMLDivElement, ThreadRootProps>(
19
23
  ({ current, children, classNames, ...props }, forwardedRef) => {
20
24
  return (
21
25
  <div
@@ -26,8 +30,7 @@ export const Thread = forwardRef<HTMLDivElement, ThreadProps>(
26
30
  className={mx(
27
31
  threadLayout,
28
32
  hoverableFocusedWithinControls,
29
- 'pbs-2 pbe-4 bg-[var(--surface-bg)] border-separator first:border-bs-0 border-be',
30
- 'current-related attention-surface [--controls-opacity:0]',
33
+ 'bg-[var(--surface-bg)] current-related attention-surface [--controls-opacity:0]',
31
34
  classNames,
32
35
  )}
33
36
  ref={forwardedRef}
@@ -38,14 +41,18 @@ export const Thread = forwardRef<HTMLDivElement, ThreadProps>(
38
41
  },
39
42
  );
40
43
 
41
- export type ThreadHeadingProps = ThemedClassName<ComponentPropsWithRef<'div'>> & { detached?: boolean };
44
+ //
45
+ // Heading
46
+ //
47
+
48
+ type ThreadHeaderProps = ComponentPropsWithRef<'div'> & { detached?: boolean };
42
49
 
43
- export const ThreadHeading = forwardRef<HTMLParagraphElement, ThreadHeadingProps>(
44
- ({ classNames, children, detached, ...props }, forwardedRef) => {
50
+ const ThreadHeader = forwardRef<HTMLParagraphElement, ThreadHeaderProps>(
51
+ ({ children, detached, ...props }, forwardedRef) => {
45
52
  return (
46
53
  <>
47
54
  <div role='none' className='flex items-center justify-center text-description'>
48
- <CaretDoubleRight />
55
+ <Icon icon='ph--caret-double-right--regular' />
49
56
  </div>
50
57
  <div role='none' className='flex items-center overflow-hidden'>
51
58
  <p
@@ -66,11 +73,15 @@ export const ThreadHeading = forwardRef<HTMLParagraphElement, ThreadHeadingProps
66
73
  },
67
74
  );
68
75
 
69
- export type ThreadFooterProps = ThemedClassName<ComponentPropsWithRef<'div'>> & {
76
+ //
77
+ // Status
78
+ //
79
+
80
+ type ThreadStatusProps = ThemedClassName<ComponentPropsWithRef<'div'>> & {
70
81
  activity?: boolean;
71
82
  };
72
83
 
73
- export const ThreadFooter = forwardRef<HTMLDivElement, ThreadFooterProps>(
84
+ const ThreadStatus = forwardRef<HTMLDivElement, ThreadStatusProps>(
74
85
  ({ activity, classNames, children, ...props }, forwardedRef) => {
75
86
  const { t } = useTranslation(translationKey);
76
87
  return (
@@ -82,10 +93,10 @@ export const ThreadFooter = forwardRef<HTMLDivElement, ThreadFooterProps>(
82
93
  )}
83
94
  ref={forwardedRef}
84
95
  >
85
- <Spinner
86
- weight='bold'
96
+ <Icon
97
+ icon='ph--spinner--bold'
98
+ classNames='is-6 bs-4 invisible data-[visible=show]:visible animate-spin-slow'
87
99
  data-visible={activity ? 'show' : 'hide'}
88
- className='is-6 bs-4 invisible data-[visible=show]:visible animate-spin-slow'
89
100
  />
90
101
  <span className='truncate min-is-0' aria-live='polite'>
91
102
  {activity ? children : null}
@@ -95,3 +106,11 @@ export const ThreadFooter = forwardRef<HTMLDivElement, ThreadFooterProps>(
95
106
  );
96
107
  },
97
108
  );
109
+
110
+ export const Thread = {
111
+ Root: ThreadRoot,
112
+ Header: ThreadHeader,
113
+ Status: ThreadStatus,
114
+ };
115
+
116
+ export type { ThreadRootProps, ThreadHeaderProps as ThreadHeadingProps, ThreadStatusProps };