@dxos/react-ui-thread 0.8.4-main.3eb6e50203 → 0.8.4-main.3fbcb4aa9b
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 +35 -66
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +25 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/types/src/Message/Message.d.ts +2 -2
- package/dist/types/src/Message/Message.d.ts.map +1 -1
- package/dist/types/src/Message/Message.stories.d.ts +10 -10
- package/dist/types/src/Message/Message.stories.d.ts.map +1 -1
- package/dist/types/src/Thread/Comments.stories.d.ts +12 -12
- package/dist/types/src/Thread/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/Thread/Thread.d.ts +25 -11
- package/dist/types/src/Thread/Thread.d.ts.map +1 -1
- package/dist/types/src/Thread/Thread.stories.d.ts +15 -11
- package/dist/types/src/Thread/Thread.stories.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- 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 +10 -10
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +1 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -19
- package/src/Message/Message.stories.tsx +5 -5
- package/src/Message/Message.tsx +14 -17
- package/src/Thread/Comments.stories.tsx +15 -16
- package/src/Thread/Thread.stories.tsx +8 -8
- package/src/Thread/Thread.tsx +20 -18
- package/src/index.ts +0 -3
- package/src/testing.tsx +3 -6
- package/src/translations.ts +10 -10
- package/src/types.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-thread",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.3fbcb4aa9b",
|
|
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",
|
|
@@ -12,48 +12,54 @@
|
|
|
12
12
|
"author": "DXOS.org",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"type": "module",
|
|
15
|
+
"imports": {
|
|
16
|
+
"#translations": "./src/translations.ts"
|
|
17
|
+
},
|
|
15
18
|
"exports": {
|
|
16
19
|
".": {
|
|
17
20
|
"source": "./src/index.ts",
|
|
18
21
|
"types": "./dist/types/src/index.d.ts",
|
|
19
22
|
"browser": "./dist/lib/browser/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./translations": {
|
|
25
|
+
"source": "./src/translations.ts",
|
|
26
|
+
"types": "./dist/types/src/translations.d.ts",
|
|
27
|
+
"browser": "./dist/lib/browser/translations.mjs",
|
|
28
|
+
"node": "./dist/lib/node-esm/translations.mjs"
|
|
20
29
|
}
|
|
21
30
|
},
|
|
22
31
|
"types": "dist/types/src/index.d.ts",
|
|
23
|
-
"typesVersions": {
|
|
24
|
-
"*": {}
|
|
25
|
-
},
|
|
26
32
|
"files": [
|
|
27
33
|
"dist",
|
|
28
34
|
"src"
|
|
29
35
|
],
|
|
30
36
|
"dependencies": {
|
|
31
37
|
"@radix-ui/react-primitive": "2.0.2",
|
|
32
|
-
"date-fns": "^3.
|
|
33
|
-
"@dxos/util": "0.8.4-main.
|
|
34
|
-
"@dxos/react-ui-editor": "0.8.4-main.
|
|
35
|
-
"@dxos/ui-editor": "0.8.4-main.
|
|
38
|
+
"date-fns": "^3.6.0",
|
|
39
|
+
"@dxos/util": "0.8.4-main.3fbcb4aa9b",
|
|
40
|
+
"@dxos/react-ui-editor": "0.8.4-main.3fbcb4aa9b",
|
|
41
|
+
"@dxos/ui-editor": "0.8.4-main.3fbcb4aa9b"
|
|
36
42
|
},
|
|
37
43
|
"devDependencies": {
|
|
38
44
|
"@types/react": "~19.2.7",
|
|
39
45
|
"@types/react-dom": "~19.2.3",
|
|
40
46
|
"react": "~19.2.3",
|
|
41
47
|
"react-dom": "~19.2.3",
|
|
42
|
-
"vite": "
|
|
43
|
-
"@dxos/echo
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/echo": "0.8.4-main.
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
50
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
48
|
+
"vite": "^8.0.10",
|
|
49
|
+
"@dxos/echo": "0.8.4-main.3fbcb4aa9b",
|
|
50
|
+
"@dxos/keys": "0.8.4-main.3fbcb4aa9b",
|
|
51
|
+
"@dxos/log": "0.8.4-main.3fbcb4aa9b",
|
|
52
|
+
"@dxos/echo-db": "0.8.4-main.3fbcb4aa9b",
|
|
53
|
+
"@dxos/random": "0.8.4-main.3fbcb4aa9b",
|
|
54
|
+
"@dxos/react-ui": "0.8.4-main.3fbcb4aa9b",
|
|
55
|
+
"@dxos/storybook-utils": "0.8.4-main.3fbcb4aa9b",
|
|
56
|
+
"@dxos/ui-theme": "0.8.4-main.3fbcb4aa9b"
|
|
51
57
|
},
|
|
52
58
|
"peerDependencies": {
|
|
53
59
|
"react": "~19.2.3",
|
|
54
60
|
"react-dom": "~19.2.3",
|
|
55
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
56
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
61
|
+
"@dxos/react-ui": "0.8.4-main.3fbcb4aa9b",
|
|
62
|
+
"@dxos/ui-theme": "0.8.4-main.3fbcb4aa9b"
|
|
57
63
|
},
|
|
58
64
|
"publishConfig": {
|
|
59
65
|
"access": "public"
|
|
@@ -6,13 +6,13 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import React, { useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
10
|
import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/ui-theme';
|
|
11
11
|
|
|
12
|
+
import { translations } from '#translations';
|
|
13
|
+
|
|
12
14
|
import { type MessageEntity, MessageStoryText } from '../testing';
|
|
13
15
|
import { Thread } from '../Thread';
|
|
14
|
-
import { translations } from '../translations';
|
|
15
|
-
|
|
16
16
|
import { MessageRoot } from './Message';
|
|
17
17
|
|
|
18
18
|
const DefaultStory = () => {
|
|
@@ -25,7 +25,7 @@ const DefaultStory = () => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
return (
|
|
28
|
-
<div className='
|
|
28
|
+
<div className='mx-auto w-96 overflow-y-auto'>
|
|
29
29
|
<Thread.Root id='t1'>
|
|
30
30
|
<MessageRoot {...message} classNames={[hoverableControls, hoverableFocusedWithinControls]}>
|
|
31
31
|
<MessageStoryText {...message} onDelete={() => console.log('delete')} />
|
|
@@ -39,7 +39,7 @@ const meta = {
|
|
|
39
39
|
title: 'ui/react-ui-thread/Message',
|
|
40
40
|
component: MessageRoot as any,
|
|
41
41
|
render: DefaultStory,
|
|
42
|
-
decorators: [withTheme()],
|
|
42
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
43
43
|
parameters: {
|
|
44
44
|
layout: 'fullscreen',
|
|
45
45
|
translations,
|
package/src/Message/Message.tsx
CHANGED
|
@@ -8,17 +8,18 @@ import React, { type ComponentPropsWithRef, type ComponentPropsWithoutRef, forwa
|
|
|
8
8
|
import { Avatar, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
9
9
|
import { type UseTextEditorProps, useTextEditor } from '@dxos/react-ui-editor';
|
|
10
10
|
import { keymap, listener } from '@dxos/ui-editor';
|
|
11
|
-
import {
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
12
|
import { hexToEmoji, hexToHue, isTruthy } from '@dxos/util';
|
|
13
13
|
|
|
14
|
-
import { translationKey } from '
|
|
14
|
+
import { translationKey } from '#translations';
|
|
15
|
+
|
|
15
16
|
import { type MessageMetadata } from '../types';
|
|
16
17
|
|
|
17
18
|
const avatarSize = 7;
|
|
18
19
|
|
|
19
|
-
export type MessageRootProps = ThemedClassName<
|
|
20
|
-
MessageMetadata &
|
|
21
|
-
|
|
20
|
+
export type MessageRootProps = ThemedClassName<
|
|
21
|
+
ComponentPropsWithRef<'div'> & MessageMetadata & Partial<{ continues: boolean }>
|
|
22
|
+
>;
|
|
22
23
|
|
|
23
24
|
// TODO(burdon): Show authorName on tooltip.
|
|
24
25
|
export const MessageRoot = forwardRef<HTMLDivElement, MessageRootProps>(
|
|
@@ -26,28 +27,25 @@ export const MessageRoot = forwardRef<HTMLDivElement, MessageRootProps>(
|
|
|
26
27
|
{ authorImgSrc, authorId, authorName, authorAvatarProps, continues = true, children, classNames, ...rootProps },
|
|
27
28
|
forwardedRef,
|
|
28
29
|
) => {
|
|
30
|
+
// Must wrap the message since Avatar.Label may be used in the content.
|
|
29
31
|
return (
|
|
30
|
-
// Must wrap the message since Avatar.Label may be used in the content.
|
|
31
32
|
<Avatar.Root>
|
|
32
33
|
<div
|
|
33
|
-
role='none'
|
|
34
34
|
data-testid='thread.message'
|
|
35
35
|
{...rootProps}
|
|
36
36
|
className={mx('grid grid-cols-subgrid col-span-2', classNames)}
|
|
37
37
|
ref={forwardedRef}
|
|
38
38
|
>
|
|
39
|
-
<div
|
|
39
|
+
<div className='flex flex-col items-center gap-2 pt-1'>
|
|
40
40
|
<Avatar.Content
|
|
41
41
|
size={avatarSize}
|
|
42
42
|
hue={authorAvatarProps?.hue || hexToHue(authorId ?? '0')}
|
|
43
43
|
fallback={authorAvatarProps?.emoji || hexToEmoji(authorId ?? '0')}
|
|
44
44
|
{...(authorImgSrc && { imgSrc: authorImgSrc })}
|
|
45
45
|
/>
|
|
46
|
-
{continues && <div
|
|
47
|
-
</div>
|
|
48
|
-
<div role='none' className='plb-1 min-is-0'>
|
|
49
|
-
{children}
|
|
46
|
+
{continues && <div className='w-px grow bg-separator' />}
|
|
50
47
|
</div>
|
|
48
|
+
<div className='py-1 min-w-0'>{children}</div>
|
|
51
49
|
</div>
|
|
52
50
|
</Avatar.Root>
|
|
53
51
|
);
|
|
@@ -59,7 +57,7 @@ export type MessageHeadingProps = ThemedClassName<ComponentPropsWithoutRef<'div'
|
|
|
59
57
|
|
|
60
58
|
export const MessageHeading = ({ children, classNames, timestamp, authorName, ...props }: MessageHeadingProps) => {
|
|
61
59
|
return (
|
|
62
|
-
<div
|
|
60
|
+
<div {...props} className={mx('flex gap-2 items-start', classNames)}>
|
|
63
61
|
<p className='grow'>
|
|
64
62
|
<MessageAuthorName authorName={authorName} />
|
|
65
63
|
{timestamp && <MessageTime timestamp={timestamp} />}
|
|
@@ -74,7 +72,7 @@ export type MessageAuthorNameProps = Pick<MessageMetadata, 'authorName'>;
|
|
|
74
72
|
export const MessageAuthorName = ({ authorName }: MessageAuthorNameProps) => {
|
|
75
73
|
const { t } = useTranslation(translationKey);
|
|
76
74
|
return (
|
|
77
|
-
<Avatar.Label classNames='block truncate text-sm text-subdued'>{authorName ?? t('anonymous
|
|
75
|
+
<Avatar.Label classNames='block truncate text-sm text-subdued'>{authorName ?? t('anonymous.label')}</Avatar.Label>
|
|
78
76
|
);
|
|
79
77
|
};
|
|
80
78
|
|
|
@@ -84,7 +82,7 @@ export const MessageTime = ({ timestamp }: MessageTimeProps) => {
|
|
|
84
82
|
const { dtLocale } = useTranslation(translationKey);
|
|
85
83
|
const dt = timestamp ? new Date(timestamp) : undefined;
|
|
86
84
|
return (
|
|
87
|
-
<time className='block text-subdued text-xs
|
|
85
|
+
<time className='block text-subdued text-xs pb-0.5' dateTime={dt?.toISOString()}>
|
|
88
86
|
{dt ? formatDistanceToNow(dt, { locale: dtLocale, addSuffix: true }) : ''}
|
|
89
87
|
</time>
|
|
90
88
|
);
|
|
@@ -165,9 +163,8 @@ export const MessageTextbox = ({
|
|
|
165
163
|
return (
|
|
166
164
|
<MessageRoot {...{ id, authorId, authorName, authorImgSrc, authorAvatarProps }} continues={false}>
|
|
167
165
|
<div
|
|
168
|
-
role='none'
|
|
169
166
|
ref={parentRef}
|
|
170
|
-
className={mx('
|
|
167
|
+
className={mx('py-0.5 me-1 rounded-xs dx-focus-ring', disabled && 'opacity-50')}
|
|
171
168
|
{...focusAttributes}
|
|
172
169
|
/>
|
|
173
170
|
</MessageRoot>
|
|
@@ -9,15 +9,13 @@ import { Obj } from '@dxos/echo';
|
|
|
9
9
|
import { TestSchema } from '@dxos/echo/testing';
|
|
10
10
|
import { PublicKey } from '@dxos/keys';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
|
-
import {
|
|
12
|
+
import { random } from '@dxos/random';
|
|
13
13
|
import { Icon, IconButton, useThemeContext } from '@dxos/react-ui';
|
|
14
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
15
14
|
import { useTextEditor } from '@dxos/react-ui-editor';
|
|
15
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
16
16
|
import {
|
|
17
|
-
type Comment,
|
|
18
17
|
type CommentsOptions,
|
|
19
18
|
type EditorView,
|
|
20
|
-
type Range,
|
|
21
19
|
comments,
|
|
22
20
|
createBasicExtensions,
|
|
23
21
|
createThemeExtensions,
|
|
@@ -26,15 +24,16 @@ import {
|
|
|
26
24
|
scrollThreadIntoView,
|
|
27
25
|
setComments,
|
|
28
26
|
} from '@dxos/ui-editor';
|
|
27
|
+
import { type Comment, type Range } from '@dxos/ui-editor/types';
|
|
29
28
|
import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/ui-theme';
|
|
30
29
|
|
|
30
|
+
import { translations } from '#translations';
|
|
31
|
+
|
|
31
32
|
import { MessageBody, MessageHeading, MessageRoot, MessageTextbox } from '../Message';
|
|
32
33
|
import { type MessageEntity } from '../testing';
|
|
33
|
-
import { translations } from '../translations';
|
|
34
|
-
|
|
35
34
|
import { Thread } from './Thread';
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
random.seed(101);
|
|
38
37
|
|
|
39
38
|
const authorId = PublicKey.random().toHex();
|
|
40
39
|
|
|
@@ -208,7 +207,7 @@ const StoryThread: FC<{
|
|
|
208
207
|
variant='ghost'
|
|
209
208
|
icon='ph--check--regular'
|
|
210
209
|
iconOnly
|
|
211
|
-
classNames='
|
|
210
|
+
classNames='px-1'
|
|
212
211
|
label='Resolve'
|
|
213
212
|
onClick={onResolve}
|
|
214
213
|
/>
|
|
@@ -252,12 +251,12 @@ const Sidebar = ({ threads, selected, onSelect, onResolve }: SidebarProps) => {
|
|
|
252
251
|
// Story container.
|
|
253
252
|
//
|
|
254
253
|
|
|
255
|
-
type
|
|
254
|
+
type DefaultStoryProps = {
|
|
256
255
|
text?: string;
|
|
257
256
|
autoCreate?: boolean;
|
|
258
257
|
};
|
|
259
258
|
|
|
260
|
-
const DefaultStory = ({ text, autoCreate }:
|
|
259
|
+
const DefaultStory = ({ text, autoCreate }: DefaultStoryProps) => {
|
|
261
260
|
const [item] = useState(() => Obj.make(TestSchema.Expando, { content: text ?? '' }));
|
|
262
261
|
const [threads, setThreads] = useState<StoryCommentThread[]>([]);
|
|
263
262
|
const [selected, setSelected] = useState<string>();
|
|
@@ -277,12 +276,12 @@ const DefaultStory = ({ text, autoCreate }: StoryProps) => {
|
|
|
277
276
|
cursor,
|
|
278
277
|
yPos: location ? Math.floor(location.top) : undefined,
|
|
279
278
|
messages: autoCreate
|
|
280
|
-
?
|
|
279
|
+
? random.helpers.multiple(
|
|
281
280
|
() => ({
|
|
282
281
|
id: PublicKey.random().toHex(),
|
|
283
282
|
timestamp: new Date().toISOString(),
|
|
284
283
|
authorId: PublicKey.random().toHex(),
|
|
285
|
-
text:
|
|
284
|
+
text: random.lorem.sentence(),
|
|
286
285
|
}),
|
|
287
286
|
{ count: { min: 1, max: 3 } },
|
|
288
287
|
)
|
|
@@ -350,7 +349,7 @@ const DefaultStory = ({ text, autoCreate }: StoryProps) => {
|
|
|
350
349
|
|
|
351
350
|
return (
|
|
352
351
|
<main className='fixed inset-0 grid grid-cols-[1fr_24rem]'>
|
|
353
|
-
<div
|
|
352
|
+
<div className='max-h-full overflow-y-auto p-4'>
|
|
354
353
|
<Editor
|
|
355
354
|
initialValue={item.content}
|
|
356
355
|
selected={selected}
|
|
@@ -362,7 +361,7 @@ const DefaultStory = ({ text, autoCreate }: StoryProps) => {
|
|
|
362
361
|
/>
|
|
363
362
|
</div>
|
|
364
363
|
|
|
365
|
-
<div
|
|
364
|
+
<div className='max-h-full overflow-y-auto p-4'>
|
|
366
365
|
<Sidebar
|
|
367
366
|
threads={visibleThreads}
|
|
368
367
|
selected={selected}
|
|
@@ -378,7 +377,7 @@ const meta = {
|
|
|
378
377
|
title: 'ui/react-ui-thread/Comments',
|
|
379
378
|
component: StoryThread as any,
|
|
380
379
|
render: DefaultStory,
|
|
381
|
-
decorators: [withTheme()],
|
|
380
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
382
381
|
parameters: {
|
|
383
382
|
translations,
|
|
384
383
|
layout: 'fullscreen',
|
|
@@ -396,7 +395,7 @@ export const Default: Story = {
|
|
|
396
395
|
text: str(
|
|
397
396
|
'# Comments',
|
|
398
397
|
'',
|
|
399
|
-
str(...
|
|
398
|
+
str(...random.helpers.multiple(() => [random.lorem.paragraph({ min: 5, max: 10 }), ''], { count: 20 }).flat()),
|
|
400
399
|
'',
|
|
401
400
|
),
|
|
402
401
|
},
|
|
@@ -6,18 +6,18 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import React, { useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
|
-
import {
|
|
10
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
11
|
import { createBasicExtensions, createThemeExtensions } from '@dxos/ui-editor';
|
|
12
12
|
import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/ui-theme';
|
|
13
13
|
|
|
14
|
+
import { translations } from '#translations';
|
|
15
|
+
|
|
14
16
|
import { MessageRoot, MessageTextbox } from '../Message';
|
|
15
17
|
import { type MessageEntity, MessageStoryText } from '../testing';
|
|
16
|
-
import { translations } from '../translations';
|
|
17
|
-
|
|
18
18
|
import { Thread } from './Thread';
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
random.seed(1);
|
|
21
21
|
|
|
22
22
|
const DefaultStory = () => {
|
|
23
23
|
const [pending, setPending] = useState(false);
|
|
@@ -28,7 +28,7 @@ const DefaultStory = () => {
|
|
|
28
28
|
id: `m${i + 1}`,
|
|
29
29
|
timestamp: new Date().toISOString(),
|
|
30
30
|
authorId: [identityKey1.toHex(), identityKey2.toHex()][i % 2],
|
|
31
|
-
text:
|
|
31
|
+
text: random.lorem.paragraph(),
|
|
32
32
|
})),
|
|
33
33
|
);
|
|
34
34
|
|
|
@@ -59,7 +59,7 @@ const DefaultStory = () => {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
return (
|
|
62
|
-
<div className='
|
|
62
|
+
<div className='mx-auto w-96 overflow-y-auto'>
|
|
63
63
|
<Thread.Root id='t1'>
|
|
64
64
|
{messages.map((message) => (
|
|
65
65
|
<MessageRoot key={message.id} classNames={[hoverableControls, hoverableFocusedWithinControls]} {...message}>
|
|
@@ -85,7 +85,7 @@ const meta = {
|
|
|
85
85
|
title: 'ui/react-ui-thread/Thread',
|
|
86
86
|
component: Thread.Root,
|
|
87
87
|
render: DefaultStory,
|
|
88
|
-
decorators: [withTheme()],
|
|
88
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
89
89
|
parameters: {
|
|
90
90
|
layout: 'fullscreen',
|
|
91
91
|
translations,
|
package/src/Thread/Thread.tsx
CHANGED
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, { ComponentPropsWithRef, forwardRef, PropsWithChildren } from 'react';
|
|
6
6
|
|
|
7
7
|
import { Icon, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
8
8
|
import { hoverableControlItem, hoverableFocusedWithinControls, mx } from '@dxos/ui-theme';
|
|
9
9
|
|
|
10
|
-
import { translationKey } from '
|
|
10
|
+
import { translationKey } from '#translations';
|
|
11
|
+
|
|
11
12
|
import type { ThreadEntity } from '../types';
|
|
12
13
|
|
|
13
14
|
// TODO(burdon): Avoid exporting fragments.
|
|
14
|
-
export const threadLayout = '
|
|
15
|
+
export const threadLayout = 'w-full place-self-start grid grid-cols-[var(--dx-rail-size)_1fr]';
|
|
15
16
|
|
|
16
17
|
//
|
|
17
18
|
// Root
|
|
18
19
|
//
|
|
19
20
|
|
|
20
|
-
type ThreadRootProps = ThemedClassName<
|
|
21
|
+
type ThreadRootProps = ThemedClassName<
|
|
22
|
+
PropsWithChildren<
|
|
23
|
+
ThreadEntity & { current?: boolean } & Pick<ComponentPropsWithRef<'div'>, 'onClickCapture' | 'onFocusCapture'>
|
|
24
|
+
>
|
|
25
|
+
>;
|
|
21
26
|
|
|
22
27
|
const ThreadRoot = forwardRef<HTMLDivElement, ThreadRootProps>(
|
|
23
28
|
({ current, children, classNames, ...props }, forwardedRef) => {
|
|
@@ -30,7 +35,7 @@ const ThreadRoot = forwardRef<HTMLDivElement, ThreadRootProps>(
|
|
|
30
35
|
className={mx(
|
|
31
36
|
threadLayout,
|
|
32
37
|
hoverableFocusedWithinControls,
|
|
33
|
-
'bg-[var(--surface-bg)] current-related attention-surface [--controls-opacity:0]',
|
|
38
|
+
'bg-[var(--surface-bg)] current-related dx-attention-surface [--controls-opacity:0]',
|
|
34
39
|
classNames,
|
|
35
40
|
)}
|
|
36
41
|
ref={forwardedRef}
|
|
@@ -45,24 +50,21 @@ const ThreadRoot = forwardRef<HTMLDivElement, ThreadRootProps>(
|
|
|
45
50
|
// Heading
|
|
46
51
|
//
|
|
47
52
|
|
|
48
|
-
type ThreadHeaderProps =
|
|
53
|
+
type ThreadHeaderProps = PropsWithChildren<{ detached?: boolean }>;
|
|
49
54
|
|
|
50
55
|
const ThreadHeader = forwardRef<HTMLParagraphElement, ThreadHeaderProps>(
|
|
51
56
|
({ children, detached, ...props }, forwardedRef) => {
|
|
52
57
|
return (
|
|
53
58
|
<>
|
|
54
|
-
<div
|
|
59
|
+
<div className='flex items-center justify-center text-description'>
|
|
55
60
|
<Icon icon='ph--caret-double-right--regular' />
|
|
56
61
|
</div>
|
|
57
|
-
<div
|
|
62
|
+
<div className='flex items-center overflow-hidden'>
|
|
58
63
|
<p
|
|
59
64
|
role='heading'
|
|
60
65
|
data-testid='thread.heading'
|
|
61
66
|
{...props}
|
|
62
|
-
className={mx(
|
|
63
|
-
'mie-2 text-description font-medium truncate italic',
|
|
64
|
-
detached && 'line-through decoration-1',
|
|
65
|
-
)}
|
|
67
|
+
className={mx('me-2 text-description font-medium truncate italic', detached && 'line-through decoration-1')}
|
|
66
68
|
ref={forwardedRef}
|
|
67
69
|
>
|
|
68
70
|
{children}
|
|
@@ -77,7 +79,7 @@ const ThreadHeader = forwardRef<HTMLParagraphElement, ThreadHeaderProps>(
|
|
|
77
79
|
// Status
|
|
78
80
|
//
|
|
79
81
|
|
|
80
|
-
type ThreadStatusProps = ThemedClassName<
|
|
82
|
+
type ThreadStatusProps = ThemedClassName<PropsWithChildren> & {
|
|
81
83
|
activity?: boolean;
|
|
82
84
|
};
|
|
83
85
|
|
|
@@ -88,20 +90,20 @@ const ThreadStatus = forwardRef<HTMLDivElement, ThreadStatusProps>(
|
|
|
88
90
|
<div
|
|
89
91
|
{...props}
|
|
90
92
|
className={mx(
|
|
91
|
-
'col-start-2 grid grid-cols-[min-content_1fr_max-content] pb-2
|
|
93
|
+
'col-start-2 grid grid-cols-[min-content_1fr_max-content] pb-2 pe-2 text-xs text-description',
|
|
92
94
|
classNames,
|
|
93
95
|
)}
|
|
94
96
|
ref={forwardedRef}
|
|
95
97
|
>
|
|
96
98
|
<Icon
|
|
97
99
|
icon='ph--spinner--bold'
|
|
98
|
-
classNames='
|
|
100
|
+
classNames='w-6 h-4 invisible data-[visible=show]:visible animate-spin-slow'
|
|
99
101
|
data-visible={activity ? 'show' : 'hide'}
|
|
100
102
|
/>
|
|
101
|
-
<span className='truncate min-
|
|
103
|
+
<span className='truncate min-w-0' aria-live='polite'>
|
|
102
104
|
{activity ? children : null}
|
|
103
105
|
</span>
|
|
104
|
-
<span className={mx('text-end', hoverableControlItem)}>{t('enter
|
|
106
|
+
<span className={mx('text-end', hoverableControlItem)}>{t('enter-to-send.message')}</span>
|
|
105
107
|
</div>
|
|
106
108
|
);
|
|
107
109
|
},
|
|
@@ -113,4 +115,4 @@ export const Thread = {
|
|
|
113
115
|
Status: ThreadStatus,
|
|
114
116
|
};
|
|
115
117
|
|
|
116
|
-
export type { ThreadRootProps, ThreadHeaderProps
|
|
118
|
+
export type { ThreadRootProps, ThreadHeaderProps, ThreadStatusProps };
|
package/src/index.ts
CHANGED
package/src/testing.tsx
CHANGED
|
@@ -30,7 +30,7 @@ export const MessageStoryText = ({ text, onDelete, authorName, timestamp }: Mess
|
|
|
30
30
|
iconOnly
|
|
31
31
|
label='Delete'
|
|
32
32
|
variant='ghost'
|
|
33
|
-
classNames={['p-1.5 min-
|
|
33
|
+
classNames={['p-1.5 min-h-0 me-1 items-start transition-opacity', hoverableControlItem]}
|
|
34
34
|
onClick={() => onDelete()}
|
|
35
35
|
/>
|
|
36
36
|
)}
|
|
@@ -46,11 +46,8 @@ export type MessagePartProps<PartValue> = {
|
|
|
46
46
|
|
|
47
47
|
export const MessageStoryBlock = <PartValue,>({ part }: MessagePartProps<PartValue>) => {
|
|
48
48
|
return (
|
|
49
|
-
<div
|
|
50
|
-
|
|
51
|
-
className={mx('grid grid-cols-subgrid col-span-3', hoverableControls, hoverableFocusedWithinControls)}
|
|
52
|
-
>
|
|
53
|
-
<pre className='font-mono max-is-full overflow-x-auto col-span-3'>
|
|
49
|
+
<div className={mx('grid grid-cols-subgrid col-span-3', hoverableControls, hoverableFocusedWithinControls)}>
|
|
50
|
+
<pre className='font-mono max-w-full overflow-x-auto col-span-3'>
|
|
54
51
|
<code>{JSON.stringify(part, undefined, 2)}</code>
|
|
55
52
|
</pre>
|
|
56
53
|
</div>
|
package/src/translations.ts
CHANGED
|
@@ -10,16 +10,16 @@ export const translations = [
|
|
|
10
10
|
{
|
|
11
11
|
'en-US': {
|
|
12
12
|
[translationKey]: {
|
|
13
|
-
'plugin
|
|
14
|
-
'thread
|
|
15
|
-
'thread
|
|
16
|
-
'delete
|
|
17
|
-
'create
|
|
18
|
-
'message
|
|
19
|
-
'comment
|
|
20
|
-
'settings
|
|
21
|
-
'anonymous
|
|
22
|
-
'enter
|
|
13
|
+
'plugin.name': 'Threads',
|
|
14
|
+
'thread-title.placeholder': 'New thread',
|
|
15
|
+
'thread-title.label': 'Title',
|
|
16
|
+
'delete-thread.label': 'Delete',
|
|
17
|
+
'create-thread.label': 'Create thread',
|
|
18
|
+
'message.placeholder': 'Enter message...',
|
|
19
|
+
'comment.placeholder': 'Enter comment...',
|
|
20
|
+
'settings-standalone.label': 'Enable standalone thread creation',
|
|
21
|
+
'anonymous.label': 'Anonymous',
|
|
22
|
+
'enter-to-send.message': 'Enter to add ⏎',
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
25
|
},
|