@dxos/react-ui-thread 0.8.4-main.84f28bd → 0.8.4-main.937b3ca
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/browser/index.mjs +131 -176
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/Message/Message.d.ts.map +1 -1
- package/dist/types/src/Message/Message.stories.d.ts +8 -6
- package/dist/types/src/Message/Message.stories.d.ts.map +1 -1
- package/dist/types/src/Thread/Comments.stories.d.ts +8 -25
- package/dist/types/src/Thread/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/Thread/Thread.d.ts +1 -1
- package/dist/types/src/Thread/Thread.d.ts.map +1 -1
- package/dist/types/src/Thread/Thread.stories.d.ts +29 -5
- package/dist/types/src/Thread/Thread.stories.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -25
- package/src/Message/Message.stories.tsx +19 -12
- package/src/Message/Message.tsx +9 -8
- package/src/Thread/Comments.stories.tsx +69 -39
- package/src/Thread/Thread.stories.tsx +17 -12
- package/src/Thread/Thread.tsx +8 -9
- package/src/index.ts +1 -1
- package/src/testing.tsx +7 -7
- package/src/translations.ts +1 -1
- package/dist/lib/node-esm/index.mjs +0 -268
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-thread",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.937b3ca",
|
|
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":
|
|
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.4-main.
|
|
30
|
-
"@dxos/
|
|
33
|
+
"@dxos/react-ui-editor": "0.8.4-main.937b3ca",
|
|
34
|
+
"@dxos/ui-editor": "0.8.4-main.937b3ca",
|
|
35
|
+
"@dxos/util": "0.8.4-main.937b3ca"
|
|
31
36
|
},
|
|
32
37
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@types/react": "~
|
|
35
|
-
"
|
|
36
|
-
"react": "~
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"@dxos/echo-db": "0.8.4-main.
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/react-ui-theme": "0.8.4-main.84f28bd",
|
|
47
|
-
"@dxos/storybook-utils": "0.8.4-main.84f28bd"
|
|
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.937b3ca",
|
|
44
|
+
"@dxos/echo-db": "0.8.4-main.937b3ca",
|
|
45
|
+
"@dxos/log": "0.8.4-main.937b3ca",
|
|
46
|
+
"@dxos/random": "0.8.4-main.937b3ca",
|
|
47
|
+
"@dxos/react-ui": "0.8.4-main.937b3ca",
|
|
48
|
+
"@dxos/storybook-utils": "0.8.4-main.937b3ca",
|
|
49
|
+
"@dxos/echo": "0.8.4-main.937b3ca",
|
|
50
|
+
"@dxos/ui-theme": "0.8.4-main.937b3ca"
|
|
48
51
|
},
|
|
49
52
|
"peerDependencies": {
|
|
50
|
-
"
|
|
51
|
-
"react": "~
|
|
52
|
-
"
|
|
53
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
54
|
-
"@dxos/react-ui-theme": "0.8.4-main.84f28bd"
|
|
53
|
+
"react": "~19.2.3",
|
|
54
|
+
"react-dom": "~19.2.3",
|
|
55
|
+
"@dxos/ui-theme": "0.8.4-main.937b3ca",
|
|
56
|
+
"@dxos/react-ui": "0.8.4-main.937b3ca"
|
|
55
57
|
},
|
|
56
58
|
"publishConfig": {
|
|
57
59
|
"access": "public"
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
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 {
|
|
11
|
-
import {
|
|
9
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
10
|
+
import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/ui-theme';
|
|
12
11
|
|
|
13
|
-
import {
|
|
12
|
+
import { type MessageEntity, MessageStoryText } from '../testing';
|
|
14
13
|
import { Thread } from '../Thread';
|
|
15
|
-
import { MessageStoryText, type MessageEntity } from '../testing';
|
|
16
14
|
import { translations } from '../translations';
|
|
17
15
|
|
|
16
|
+
import { MessageRoot } from './Message';
|
|
17
|
+
|
|
18
18
|
const DefaultStory = () => {
|
|
19
19
|
const [identityKey] = useState(PublicKey.random());
|
|
20
20
|
const [message] = useState<MessageEntity>({
|
|
@@ -35,12 +35,19 @@ const DefaultStory = () => {
|
|
|
35
35
|
);
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
|
|
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
|
|
43
|
-
parameters: {
|
|
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 = {};
|
package/src/Message/Message.tsx
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { formatDistanceToNow } from 'date-fns/formatDistanceToNow';
|
|
6
|
-
import React, { type ComponentPropsWithRef,
|
|
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,
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
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-
|
|
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(
|
|
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 '@
|
|
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 {
|
|
11
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
} from '@dxos/
|
|
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 } from './Thread';
|
|
34
31
|
import { MessageBody, MessageHeading, MessageRoot, MessageTextbox } from '../Message';
|
|
35
32
|
import { type MessageEntity } from '../testing';
|
|
36
33
|
import { translations } from '../translations';
|
|
37
34
|
|
|
35
|
+
import { Thread } from './Thread';
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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,
|
|
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 [
|
|
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({
|
|
144
|
+
listener({
|
|
145
|
+
onChange: ({ text }) => (messageRef.current = text),
|
|
146
|
+
}),
|
|
129
147
|
],
|
|
130
|
-
[themeMode,
|
|
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 =
|
|
164
|
+
const message = Obj.make(TestSchema.Expando, {
|
|
147
165
|
timestamp: new Date().toISOString(),
|
|
148
166
|
sender: { identityKey: authorId },
|
|
149
167
|
text: messageRef.current,
|
|
@@ -152,7 +170,7 @@ const StoryThread: FC<{
|
|
|
152
170
|
|
|
153
171
|
messageRef.current = '';
|
|
154
172
|
setAutoFocus(true);
|
|
155
|
-
|
|
173
|
+
setState({});
|
|
156
174
|
}
|
|
157
175
|
};
|
|
158
176
|
|
|
@@ -162,7 +180,7 @@ const StoryThread: FC<{
|
|
|
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 && <
|
|
183
|
+
{!thread.cursor && <Icon icon='ph--trash--regular' />}
|
|
166
184
|
</div>
|
|
167
185
|
|
|
168
186
|
<Thread.Header>
|
|
@@ -186,9 +204,14 @@ const StoryThread: FC<{
|
|
|
186
204
|
onSend={handleCreateMessage}
|
|
187
205
|
/>
|
|
188
206
|
<Thread.Status />
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
|
|
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
216
|
</Thread.Root>
|
|
194
217
|
);
|
|
@@ -232,8 +255,8 @@ type StoryProps = {
|
|
|
232
255
|
autoCreate?: boolean;
|
|
233
256
|
};
|
|
234
257
|
|
|
235
|
-
const
|
|
236
|
-
const [item] = useState(
|
|
258
|
+
const DefaultStory = ({ text, autoCreate }: StoryProps) => {
|
|
259
|
+
const [item] = useState(() => Obj.make(TestSchema.Expando, { content: text ?? '' }));
|
|
237
260
|
const [threads, setThreads] = useState<StoryCommentThread[]>([]);
|
|
238
261
|
const [selected, setSelected] = useState<string>();
|
|
239
262
|
|
|
@@ -327,7 +350,7 @@ const Story = ({ text, autoCreate }: StoryProps) => {
|
|
|
327
350
|
<main className='fixed inset-0 grid grid-cols-[1fr_24rem]'>
|
|
328
351
|
<div role='none' className='max-bs-full overflow-y-auto p-4'>
|
|
329
352
|
<Editor
|
|
330
|
-
|
|
353
|
+
initialValue={item.content}
|
|
331
354
|
selected={selected}
|
|
332
355
|
comments={comments}
|
|
333
356
|
onCreateComment={handleCreateComment}
|
|
@@ -349,17 +372,24 @@ const Story = ({ text, autoCreate }: StoryProps) => {
|
|
|
349
372
|
);
|
|
350
373
|
};
|
|
351
374
|
|
|
352
|
-
|
|
375
|
+
const meta = {
|
|
353
376
|
title: 'ui/react-ui-thread/Comments',
|
|
354
|
-
component: StoryThread,
|
|
377
|
+
component: StoryThread as any,
|
|
378
|
+
render: DefaultStory,
|
|
355
379
|
decorators: [withTheme],
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
380
|
+
parameters: {
|
|
381
|
+
translations,
|
|
382
|
+
layout: 'fullscreen',
|
|
383
|
+
},
|
|
384
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
385
|
+
|
|
386
|
+
export default meta;
|
|
387
|
+
|
|
388
|
+
type Story = StoryObj<typeof meta>;
|
|
359
389
|
|
|
360
390
|
const str = (...lines: string[]) => lines.join('\n');
|
|
361
391
|
|
|
362
|
-
export const Default = {
|
|
392
|
+
export const Default: Story = {
|
|
363
393
|
args: {
|
|
364
394
|
text: str(
|
|
365
395
|
'# Comments',
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
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 {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
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 } from './Thread';
|
|
16
14
|
import { MessageRoot, MessageTextbox } from '../Message';
|
|
17
|
-
import {
|
|
15
|
+
import { type MessageEntity, MessageStoryText } from '../testing';
|
|
18
16
|
import { translations } from '../translations';
|
|
19
17
|
|
|
18
|
+
import { Thread } from './Thread';
|
|
19
|
+
|
|
20
20
|
faker.seed(1);
|
|
21
21
|
|
|
22
22
|
const DefaultStory = () => {
|
|
@@ -81,14 +81,19 @@ const DefaultStory = () => {
|
|
|
81
81
|
);
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
const meta
|
|
84
|
+
const meta = {
|
|
85
85
|
title: 'ui/react-ui-thread/Thread',
|
|
86
86
|
component: Thread.Root,
|
|
87
87
|
render: DefaultStory,
|
|
88
|
-
decorators: [withTheme
|
|
89
|
-
parameters: {
|
|
90
|
-
|
|
88
|
+
decorators: [withTheme],
|
|
89
|
+
parameters: {
|
|
90
|
+
layout: 'fullscreen',
|
|
91
|
+
translations,
|
|
92
|
+
},
|
|
93
|
+
} satisfies Meta<typeof Thread.Root>;
|
|
91
94
|
|
|
92
95
|
export default meta;
|
|
93
96
|
|
|
94
|
-
|
|
97
|
+
type Story = StoryObj<typeof meta>;
|
|
98
|
+
|
|
99
|
+
export const Default: Story = {};
|
package/src/Thread/Thread.tsx
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
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/
|
|
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';
|
|
@@ -46,14 +45,14 @@ const ThreadRoot = forwardRef<HTMLDivElement, ThreadRootProps>(
|
|
|
46
45
|
// Heading
|
|
47
46
|
//
|
|
48
47
|
|
|
49
|
-
type ThreadHeaderProps =
|
|
48
|
+
type ThreadHeaderProps = ComponentPropsWithRef<'div'> & { detached?: boolean };
|
|
50
49
|
|
|
51
50
|
const ThreadHeader = forwardRef<HTMLParagraphElement, ThreadHeaderProps>(
|
|
52
|
-
({
|
|
51
|
+
({ children, detached, ...props }, forwardedRef) => {
|
|
53
52
|
return (
|
|
54
53
|
<>
|
|
55
54
|
<div role='none' className='flex items-center justify-center text-description'>
|
|
56
|
-
<
|
|
55
|
+
<Icon icon='ph--caret-double-right--regular' />
|
|
57
56
|
</div>
|
|
58
57
|
<div role='none' className='flex items-center overflow-hidden'>
|
|
59
58
|
<p
|
|
@@ -94,10 +93,10 @@ const ThreadStatus = forwardRef<HTMLDivElement, ThreadStatusProps>(
|
|
|
94
93
|
)}
|
|
95
94
|
ref={forwardedRef}
|
|
96
95
|
>
|
|
97
|
-
<
|
|
98
|
-
|
|
96
|
+
<Icon
|
|
97
|
+
icon='ph--spinner--bold'
|
|
98
|
+
classNames='is-6 bs-4 invisible data-[visible=show]:visible animate-spin-slow'
|
|
99
99
|
data-visible={activity ? 'show' : 'hide'}
|
|
100
|
-
className='is-6 bs-4 invisible data-[visible=show]:visible animate-spin-slow'
|
|
101
100
|
/>
|
|
102
101
|
<span className='truncate min-is-0' aria-live='polite'>
|
|
103
102
|
{activity ? children : null}
|
package/src/index.ts
CHANGED
package/src/testing.tsx
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { X } from '@phosphor-icons/react';
|
|
6
5
|
import React from 'react';
|
|
7
6
|
|
|
8
|
-
import {
|
|
9
|
-
import { hoverableControlItem, hoverableControls, hoverableFocusedWithinControls, mx } from '@dxos/
|
|
7
|
+
import { IconButton } from '@dxos/react-ui';
|
|
8
|
+
import { hoverableControlItem, hoverableControls, hoverableFocusedWithinControls, mx } from '@dxos/ui-theme';
|
|
10
9
|
|
|
11
10
|
import { MessageBody, MessageHeading } from './Message';
|
|
12
11
|
import { type MessageMetadata } from './types';
|
|
@@ -26,13 +25,14 @@ export const MessageStoryText = ({ text, onDelete, authorName, timestamp }: Mess
|
|
|
26
25
|
<>
|
|
27
26
|
<MessageHeading authorName={authorName} timestamp={timestamp}>
|
|
28
27
|
{onDelete && (
|
|
29
|
-
<
|
|
28
|
+
<IconButton
|
|
29
|
+
icon='ph--x--regular'
|
|
30
|
+
iconOnly
|
|
31
|
+
label='Delete'
|
|
30
32
|
variant='ghost'
|
|
31
33
|
classNames={['p-1.5 min-bs-0 mie-1 items-start transition-opacity', hoverableControlItem]}
|
|
32
34
|
onClick={() => onDelete()}
|
|
33
|
-
|
|
34
|
-
<X />
|
|
35
|
-
</Button>
|
|
35
|
+
/>
|
|
36
36
|
)}
|
|
37
37
|
</MessageHeading>
|
|
38
38
|
<MessageBody>{text}</MessageBody>
|