@dxos/react-ui-thread 0.8.4-main.67995b8 → 0.8.4-main.70d3990

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-thread",
3
- "version": "0.8.4-main.67995b8",
3
+ "version": "0.8.4-main.70d3990",
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",
@@ -10,9 +10,9 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
13
+ "source": "./src/index.ts",
13
14
  "types": "./dist/types/src/index.d.ts",
14
- "browser": "./dist/lib/browser/index.mjs",
15
- "source": "./src/index.ts"
15
+ "browser": "./dist/lib/browser/index.mjs"
16
16
  }
17
17
  },
18
18
  "types": "dist/types/src/index.d.ts",
@@ -27,30 +27,30 @@
27
27
  "@preact-signals/safe-react": "^0.9.0",
28
28
  "@radix-ui/react-primitive": "2.0.2",
29
29
  "date-fns": "^3.3.1",
30
- "@dxos/react-ui-editor": "0.8.4-main.67995b8",
31
- "@dxos/util": "0.8.4-main.67995b8"
30
+ "@dxos/react-ui-editor": "0.8.4-main.70d3990",
31
+ "@dxos/util": "0.8.4-main.70d3990"
32
32
  },
33
33
  "devDependencies": {
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.4-main.67995b8",
40
- "@dxos/echo-schema": "0.8.4-main.67995b8",
41
- "@dxos/keys": "0.8.4-main.67995b8",
42
- "@dxos/log": "0.8.4-main.67995b8",
43
- "@dxos/live-object": "0.8.4-main.67995b8",
44
- "@dxos/react-ui": "0.8.4-main.67995b8",
45
- "@dxos/react-ui-theme": "0.8.4-main.67995b8",
46
- "@dxos/random": "0.8.4-main.67995b8",
47
- "@dxos/storybook-utils": "0.8.4-main.67995b8"
34
+ "@types/react": "~19.2.2",
35
+ "@types/react-dom": "~19.2.2",
36
+ "react": "~19.2.0",
37
+ "react-dom": "~19.2.0",
38
+ "vite": "7.1.9",
39
+ "@dxos/echo": "0.8.4-main.70d3990",
40
+ "@dxos/keys": "0.8.4-main.70d3990",
41
+ "@dxos/live-object": "0.8.4-main.70d3990",
42
+ "@dxos/echo-db": "0.8.4-main.70d3990",
43
+ "@dxos/log": "0.8.4-main.70d3990",
44
+ "@dxos/random": "0.8.4-main.70d3990",
45
+ "@dxos/react-ui": "0.8.4-main.70d3990",
46
+ "@dxos/storybook-utils": "0.8.4-main.70d3990",
47
+ "@dxos/react-ui-theme": "0.8.4-main.70d3990"
48
48
  },
49
49
  "peerDependencies": {
50
- "react": "~18.2.0",
51
- "react-dom": "~18.2.0",
52
- "@dxos/react-ui": "0.8.4-main.67995b8",
53
- "@dxos/react-ui-theme": "0.8.4-main.67995b8"
50
+ "react": "^19.0.0",
51
+ "react-dom": "^19.0.0",
52
+ "@dxos/react-ui": "0.8.4-main.70d3990",
53
+ "@dxos/react-ui-theme": "0.8.4-main.70d3990"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
@@ -2,19 +2,19 @@
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';
9
+ import { withTheme } from '@dxos/react-ui/testing';
10
10
  import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/react-ui-theme';
11
- import { withLayout, withTheme } from '@dxos/storybook-utils';
12
11
 
13
- import { MessageRoot } from './Message';
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
- 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
8
  // TODO(burdon): Remove dep.
9
9
  import { Avatar, type ThemedClassName, useTranslation } from '@dxos/react-ui';
10
10
  import { type UseTextEditorProps, keymap, listener, useTextEditor } from '@dxos/react-ui-editor';
11
11
  import { focusRing, mx } from '@dxos/react-ui-theme';
12
- import { hexToEmoji, hexToHue, isNotFalsy } from '@dxos/util';
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,22 +2,19 @@
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, { type FC, useEffect, useMemo, useRef, useState } from 'react';
8
7
 
9
- import { createDocAccessor, createObject } from '@dxos/echo-db';
10
- import { Expando } from '@dxos/echo-schema';
8
+ import { Expando } from '@dxos/echo/internal';
11
9
  import { PublicKey } from '@dxos/keys';
12
- import { live } from '@dxos/live-object';
13
10
  import { log } from '@dxos/log';
14
11
  import { faker } from '@dxos/random';
15
- import { Button, Icon, useThemeContext } from '@dxos/react-ui';
12
+ import { Icon, IconButton, useThemeContext } from '@dxos/react-ui';
13
+ import { withTheme } from '@dxos/react-ui/testing';
16
14
  import {
17
15
  type Comment,
18
16
  type CommentsOptions,
19
17
  type Range,
20
- automerge,
21
18
  comments,
22
19
  createBasicExtensions,
23
20
  createThemeExtensions,
@@ -27,13 +24,14 @@ import {
27
24
  useTextEditor,
28
25
  } from '@dxos/react-ui-editor';
29
26
  import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/react-ui-theme';
30
- import { withTheme } from '@dxos/storybook-utils';
31
27
 
32
- import { Thread } from './Thread';
28
+ import { Obj } from '../../../../core/echo/echo/src';
33
29
  import { MessageBody, MessageHeading, MessageRoot, MessageTextbox } from '../Message';
34
30
  import { type MessageEntity } from '../testing';
35
31
  import { translations } from '../translations';
36
32
 
33
+ import { Thread } from './Thread';
34
+
37
35
  faker.seed(101);
38
36
 
39
37
  const authorId = PublicKey.random().toHex();
@@ -71,7 +69,6 @@ const Editor: FC<{
71
69
  extensions: [
72
70
  createBasicExtensions(),
73
71
  createThemeExtensions({ themeMode }),
74
- automerge(createDocAccessor(item, ['content'])),
75
72
  comments({
76
73
  id,
77
74
  onCreate: onCreateComment,
@@ -114,19 +111,21 @@ const StoryThread: FC<{
114
111
  onSelect: () => void;
115
112
  onResolve: () => void;
116
113
  }> = ({ thread, selected, onSelect, onResolve }) => {
117
- const containerRef = useRef<HTMLDivElement>(null);
118
114
  const { themeMode } = useThemeContext();
115
+ const containerRef = useRef<HTMLDivElement>(null);
116
+
119
117
  // TODO(wittjosiah): This is a hack to reset the editor after a message is sent.
120
- const [_count, _setCount] = useState(0);
121
- const rerenderEditor = () => _setCount((count) => count + 1);
118
+ const [state, setState] = useState({});
122
119
  const messageRef = useRef('');
123
120
  const extensions = useMemo(
124
121
  () => [
125
122
  createBasicExtensions({ placeholder: 'Enter comment' }),
126
123
  createThemeExtensions({ themeMode }),
127
- listener({ onChange: (text) => (messageRef.current = text) }),
124
+ listener({
125
+ onChange: ({ text }) => (messageRef.current = text),
126
+ }),
128
127
  ],
129
- [themeMode, _count],
128
+ [themeMode, state],
130
129
  );
131
130
 
132
131
  const [autoFocus, setAutoFocus] = useState(false);
@@ -142,7 +141,7 @@ const StoryThread: FC<{
142
141
 
143
142
  const handleCreateMessage = () => {
144
143
  if (messageRef.current?.length) {
145
- const message = live(Expando, {
144
+ const message = Obj.make(Expando, {
146
145
  timestamp: new Date().toISOString(),
147
146
  sender: { identityKey: authorId },
148
147
  text: messageRef.current,
@@ -151,7 +150,7 @@ const StoryThread: FC<{
151
150
 
152
151
  messageRef.current = '';
153
152
  setAutoFocus(true);
154
- rerenderEditor();
153
+ setState({});
155
154
  }
156
155
  };
157
156
 
@@ -185,9 +184,14 @@ const StoryThread: FC<{
185
184
  onSend={handleCreateMessage}
186
185
  />
187
186
  <Thread.Status />
188
- <Button variant='ghost' classNames='px-1' title='Resolve' onClick={onResolve}>
189
- <Icon icon='ph--check--regular' />
190
- </Button>
187
+ <IconButton
188
+ variant='ghost'
189
+ icon='ph--check--regular'
190
+ iconOnly
191
+ classNames='pli-1'
192
+ label='Resolve'
193
+ onClick={onResolve}
194
+ />
191
195
  </div>
192
196
  </Thread.Root>
193
197
  );
@@ -231,8 +235,8 @@ type StoryProps = {
231
235
  autoCreate?: boolean;
232
236
  };
233
237
 
234
- const Story = ({ text, autoCreate }: StoryProps) => {
235
- const [item] = useState(createObject(live(Expando, { content: text ?? '' })));
238
+ const DefaultStory = ({ text, autoCreate }: StoryProps) => {
239
+ const [item] = useState(() => Obj.make(Expando, { content: text ?? '' }));
236
240
  const [threads, setThreads] = useState<StoryCommentThread[]>([]);
237
241
  const [selected, setSelected] = useState<string>();
238
242
 
@@ -348,17 +352,24 @@ const Story = ({ text, autoCreate }: StoryProps) => {
348
352
  );
349
353
  };
350
354
 
351
- export default {
355
+ const meta = {
352
356
  title: 'ui/react-ui-thread/Comments',
353
- component: StoryThread,
357
+ component: StoryThread as any,
358
+ render: DefaultStory,
354
359
  decorators: [withTheme],
355
- render: (args: StoryProps) => <Story {...args} />,
356
- parameters: { translations, layout: 'fullscreen' },
357
- };
360
+ parameters: {
361
+ translations,
362
+ layout: 'fullscreen',
363
+ },
364
+ } satisfies Meta<typeof DefaultStory>;
365
+
366
+ export default meta;
367
+
368
+ type Story = StoryObj<typeof meta>;
358
369
 
359
370
  const str = (...lines: string[]) => lines.join('\n');
360
371
 
361
- export const Default = {
372
+ export const Default: Story = {
362
373
  args: {
363
374
  text: str(
364
375
  '# Comments',
@@ -2,21 +2,21 @@
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';
10
+ import { withTheme } from '@dxos/react-ui/testing';
11
11
  import { createBasicExtensions, createThemeExtensions } from '@dxos/react-ui-editor';
12
12
  import { hoverableControls, hoverableFocusedWithinControls } from '@dxos/react-ui-theme';
13
- import { type Meta, withLayout, withTheme } from '@dxos/storybook-utils';
14
13
 
15
- import { Thread } from './Thread';
16
14
  import { MessageRoot, MessageTextbox } from '../Message';
17
- import { MessageStoryText, type MessageEntity } from '../testing';
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: Meta<typeof Thread.Root> = {
84
+ const meta = {
85
85
  title: 'ui/react-ui-thread/Thread',
86
86
  component: Thread.Root,
87
87
  render: DefaultStory,
88
- decorators: [withTheme, withLayout({ fullscreen: true })],
89
- parameters: { translations },
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
- export const Default = {};
97
+ type Story = StoryObj<typeof meta>;
98
+
99
+ export const Default: Story = {};
@@ -45,10 +45,10 @@ const ThreadRoot = forwardRef<HTMLDivElement, ThreadRootProps>(
45
45
  // Heading
46
46
  //
47
47
 
48
- type ThreadHeaderProps = ThemedClassName<ComponentPropsWithRef<'div'>> & { detached?: boolean };
48
+ type ThreadHeaderProps = ComponentPropsWithRef<'div'> & { detached?: boolean };
49
49
 
50
50
  const ThreadHeader = forwardRef<HTMLParagraphElement, ThreadHeaderProps>(
51
- ({ classNames, children, detached, ...props }, forwardedRef) => {
51
+ ({ children, detached, ...props }, forwardedRef) => {
52
52
  return (
53
53
  <>
54
54
  <div role='none' className='flex items-center justify-center text-description'>
@@ -95,8 +95,8 @@ const ThreadStatus = forwardRef<HTMLDivElement, ThreadStatusProps>(
95
95
  >
96
96
  <Icon
97
97
  icon='ph--spinner--bold'
98
- data-visible={activity ? 'show' : 'hide'}
99
98
  classNames='is-6 bs-4 invisible data-[visible=show]:visible animate-spin-slow'
99
+ data-visible={activity ? 'show' : 'hide'}
100
100
  />
101
101
  <span className='truncate min-is-0' aria-live='polite'>
102
102
  {activity ? children : null}
package/src/testing.tsx CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { Button, Icon } from '@dxos/react-ui';
7
+ import { IconButton } from '@dxos/react-ui';
8
8
  import { hoverableControlItem, hoverableControls, hoverableFocusedWithinControls, mx } from '@dxos/react-ui-theme';
9
9
 
10
10
  import { MessageBody, MessageHeading } from './Message';
@@ -25,13 +25,14 @@ export const MessageStoryText = ({ text, onDelete, authorName, timestamp }: Mess
25
25
  <>
26
26
  <MessageHeading authorName={authorName} timestamp={timestamp}>
27
27
  {onDelete && (
28
- <Button
28
+ <IconButton
29
+ icon='ph--x--regular'
30
+ iconOnly
31
+ label='Delete'
29
32
  variant='ghost'
30
33
  classNames={['p-1.5 min-bs-0 mie-1 items-start transition-opacity', hoverableControlItem]}
31
34
  onClick={() => onDelete()}
32
- >
33
- <Icon icon='ph--x--regular' />
34
- </Button>
35
+ />
35
36
  )}
36
37
  </MessageHeading>
37
38
  <MessageBody>{text}</MessageBody>