@estiva-app/ui 0.98.0 → 0.99.0
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/README.md +1 -1
- package/dist/AppProvider.d.ts +6 -3
- package/dist/AppProvider.d.ts.map +1 -1
- package/dist/ArchiveDialog.d.ts +35 -0
- package/dist/ArchiveDialog.d.ts.map +1 -0
- package/dist/AttachedCard.d.ts +13 -2
- package/dist/AttachedCard.d.ts.map +1 -1
- package/dist/Card.d.ts +6 -1
- package/dist/Card.d.ts.map +1 -1
- package/dist/ChipInput.d.ts +3 -1
- package/dist/ChipInput.d.ts.map +1 -1
- package/dist/CollapsibleSection.d.ts +27 -2
- package/dist/CollapsibleSection.d.ts.map +1 -1
- package/dist/CommentBox.d.ts +2 -2
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/ConfirmDialog.d.ts +15 -2
- package/dist/ConfirmDialog.d.ts.map +1 -1
- package/dist/ConversationCard.d.ts +6 -1
- package/dist/ConversationCard.d.ts.map +1 -1
- package/dist/ConversationLayout.d.ts +19 -4
- package/dist/ConversationLayout.d.ts.map +1 -1
- package/dist/ConversationPlace.d.ts +17 -0
- package/dist/ConversationPlace.d.ts.map +1 -0
- package/dist/DocumentEditor.d.ts +38 -0
- package/dist/DocumentEditor.d.ts.map +1 -1
- package/dist/DocumentField.d.ts +50 -0
- package/dist/DocumentField.d.ts.map +1 -0
- package/dist/EditableText.d.ts +38 -4
- package/dist/EditableText.d.ts.map +1 -1
- package/dist/EmptyState.d.ts +10 -5
- package/dist/EmptyState.d.ts.map +1 -1
- package/dist/FormDialog.d.ts +38 -0
- package/dist/FormDialog.d.ts.map +1 -0
- package/dist/InlineText.d.ts.map +1 -1
- package/dist/MoveDialog.d.ts +61 -0
- package/dist/MoveDialog.d.ts.map +1 -0
- package/dist/NavItem.d.ts +9 -2
- package/dist/NavItem.d.ts.map +1 -1
- package/dist/NavTree.d.ts +16 -3
- package/dist/NavTree.d.ts.map +1 -1
- package/dist/PinnedComment.d.ts +3 -1
- package/dist/PinnedComment.d.ts.map +1 -1
- package/dist/ReactionHorizon.d.ts +5 -1
- package/dist/ReactionHorizon.d.ts.map +1 -1
- package/dist/ResolveDialog.d.ts +3 -1
- package/dist/ResolveDialog.d.ts.map +1 -1
- package/dist/SelectionToolbar.d.ts +2 -2
- package/dist/Thread.d.ts +6 -3
- package/dist/Thread.d.ts.map +1 -1
- package/dist/commentBoxFrame.d.ts.map +1 -1
- package/dist/conversation.examples.d.ts +4 -1
- package/dist/conversation.examples.d.ts.map +1 -1
- package/dist/conversationScroll.d.ts +80 -0
- package/dist/conversationScroll.d.ts.map +1 -0
- package/dist/editor.d.ts +1 -0
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +228 -69
- package/dist/editor.js.map +4 -4
- package/dist/eslint/index.js +2 -2
- package/dist/eslint/index.js.map +2 -2
- package/dist/eslint/no-field-outside-a-form.d.ts +2 -2
- package/dist/eslint/no-field-outside-a-form.d.ts.map +1 -1
- package/dist/eslint/no-native-title.d.ts +1 -1
- package/dist/eslint/no-native-title.d.ts.map +1 -1
- package/dist/formBusy.d.ts +5 -2
- package/dist/formBusy.d.ts.map +1 -1
- package/dist/index.d.ts +14 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2210 -1458
- package/dist/index.js.map +4 -4
- package/dist/looks.d.ts +8 -0
- package/dist/looks.d.ts.map +1 -1
- package/dist/seenOnScreen.d.ts +27 -0
- package/dist/seenOnScreen.d.ts.map +1 -0
- package/dist/showInConversation.d.ts +31 -0
- package/dist/showInConversation.d.ts.map +1 -0
- package/dist/threadCard.d.ts +13 -0
- package/dist/threadCard.d.ts.map +1 -1
- package/package.json +1 -1
- package/registry.json +904 -139
- package/src/AppProvider.mdx +4 -0
- package/src/AppProvider.test.tsx +34 -2
- package/src/AppProvider.tsx +17 -6
- package/src/ArchiveDialog.mdx +70 -0
- package/src/ArchiveDialog.stories.tsx +64 -0
- package/src/ArchiveDialog.test.tsx +90 -0
- package/src/ArchiveDialog.tsx +70 -0
- package/src/AttachedCard.mdx +6 -0
- package/src/AttachedCard.stories.tsx +9 -1
- package/src/AttachedCard.test.tsx +111 -2
- package/src/AttachedCard.tsx +77 -7
- package/src/Card.mdx +20 -1
- package/src/Card.stories.tsx +20 -0
- package/src/Card.test.tsx +87 -1
- package/src/Card.tsx +51 -3
- package/src/ChipInput.mdx +7 -1
- package/src/ChipInput.stories.tsx +9 -0
- package/src/ChipInput.test.tsx +42 -0
- package/src/ChipInput.tsx +7 -3
- package/src/CollapsibleSection.mdx +20 -1
- package/src/CollapsibleSection.stories.tsx +19 -1
- package/src/CollapsibleSection.test.tsx +85 -2
- package/src/CollapsibleSection.tsx +54 -15
- package/src/CommentBox.mdx +2 -1
- package/src/CommentBox.test.tsx +81 -1
- package/src/CommentBox.tsx +32 -11
- package/src/ConfirmDialog.mdx +25 -3
- package/src/ConfirmDialog.stories.tsx +27 -0
- package/src/ConfirmDialog.test.tsx +87 -1
- package/src/ConfirmDialog.tsx +39 -8
- package/src/ConversationCard.mdx +4 -0
- package/src/ConversationCard.stories.tsx +11 -1
- package/src/ConversationCard.test.tsx +116 -0
- package/src/ConversationCard.tsx +53 -36
- package/src/ConversationLayout.mdx +30 -4
- package/src/ConversationLayout.scroll.test.tsx +411 -0
- package/src/ConversationLayout.stories.tsx +79 -1
- package/src/ConversationLayout.test.tsx +79 -0
- package/src/ConversationLayout.tsx +136 -15
- package/src/ConversationPlace.mdx +53 -0
- package/src/ConversationPlace.stories.tsx +48 -0
- package/src/ConversationPlace.test.tsx +51 -0
- package/src/ConversationPlace.tsx +30 -0
- package/src/DocumentEditor.mdx +2 -1
- package/src/DocumentEditor.tsx +118 -64
- package/src/DocumentField.mdx +83 -0
- package/src/DocumentField.stories.tsx +110 -0
- package/src/DocumentField.test.tsx +281 -0
- package/src/DocumentField.tsx +199 -0
- package/src/EditableText.buttons.test.tsx +318 -0
- package/src/EditableText.mdx +50 -2
- package/src/EditableText.stories.tsx +96 -2
- package/src/EditableText.tsx +189 -5
- package/src/EmptyState.mdx +33 -8
- package/src/EmptyState.stories.tsx +26 -1
- package/src/EmptyState.test.tsx +63 -2
- package/src/EmptyState.tsx +28 -6
- package/src/Form.mdx +3 -1
- package/src/FormDialog.mdx +78 -0
- package/src/FormDialog.stories.tsx +90 -0
- package/src/FormDialog.test.tsx +183 -0
- package/src/FormDialog.tsx +93 -0
- package/src/InlineText.mdx +1 -0
- package/src/InlineText.tsx +2 -1
- package/src/MoveDialog.mdx +74 -0
- package/src/MoveDialog.stories.tsx +121 -0
- package/src/MoveDialog.test.tsx +203 -0
- package/src/MoveDialog.tsx +183 -0
- package/src/NavItem.mdx +15 -0
- package/src/NavItem.stories.tsx +15 -0
- package/src/NavItem.test.tsx +64 -1
- package/src/NavItem.tsx +10 -2
- package/src/NavTree.mdx +26 -4
- package/src/NavTree.stories.tsx +59 -0
- package/src/NavTree.test.tsx +232 -2
- package/src/NavTree.tsx +93 -43
- package/src/PinnedComment.mdx +6 -1
- package/src/PinnedComment.stories.tsx +11 -1
- package/src/PinnedComment.tsx +15 -2
- package/src/ReactionHorizon.mdx +3 -0
- package/src/ReactionHorizon.stories.tsx +3 -0
- package/src/ReactionHorizon.test.tsx +55 -0
- package/src/ReactionHorizon.tsx +30 -11
- package/src/ReplyCard.mdx +3 -0
- package/src/ReplyCard.stories.tsx +19 -1
- package/src/ResolveDialog.mdx +2 -0
- package/src/ResolveDialog.test.tsx +21 -0
- package/src/ResolveDialog.tsx +11 -39
- package/src/SelectionToolbar.tsx +2 -2
- package/src/Textarea.mdx +1 -0
- package/src/Thread.mdx +18 -1
- package/src/Thread.stories.tsx +55 -3
- package/src/Thread.test.tsx +11 -0
- package/src/Thread.tsx +53 -11
- package/src/commentBoxFrame.tsx +2 -2
- package/src/conversation.examples.tsx +10 -2
- package/src/conversationScroll.ts +155 -0
- package/src/editor.ts +1 -0
- package/src/editorSelection.test.tsx +53 -0
- package/src/eslint/no-field-outside-a-form.test.ts +4 -0
- package/src/eslint/no-field-outside-a-form.ts +2 -2
- package/src/eslint/no-native-title.ts +1 -1
- package/src/formBusy.ts +5 -2
- package/src/index.ts +16 -6
- package/src/looks.ts +10 -0
- package/src/registry/registry.test.ts +12 -6
- package/src/seenOnScreen.test.tsx +182 -0
- package/src/seenOnScreen.ts +146 -0
- package/src/showInConversation.test.tsx +168 -0
- package/src/showInConversation.ts +93 -0
- package/src/threadCard.ts +16 -0
- package/stories/Choosing.mdx +7 -2
- package/tailwind-preset.js +7 -0
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import { Fragment, useEffect, useLayoutEffect, useRef, useState, type ReactNode, type Ref, type UIEventHandler } from 'react'
|
|
1
|
+
import { Fragment, useCallback, useEffect, useLayoutEffect, useRef, useState, type ReactNode, type Ref, type UIEvent, type UIEventHandler } from 'react'
|
|
2
2
|
import { Card } from './Card'
|
|
3
3
|
import { Chip } from './Chip'
|
|
4
4
|
import { CollapsibleSection } from './CollapsibleSection'
|
|
5
5
|
import { cn } from './cn'
|
|
6
6
|
import { ContainerHeader } from './ContainerHeader'
|
|
7
|
+
import { anchorIn, cardIn, isNearBottom, places, sendsInLayout, useSteadyScroll } from './conversationScroll'
|
|
7
8
|
import { Divider } from './Divider'
|
|
8
9
|
import { EmptyState } from './EmptyState'
|
|
9
10
|
import { ErrorBoundary } from './ErrorBoundary'
|
|
10
11
|
import { Panel } from './Panel'
|
|
11
12
|
import { ScrollArea } from './ScrollArea'
|
|
13
|
+
import { useWatchSeen, type SeenOnScreen } from './seenOnScreen'
|
|
12
14
|
import { SkeletonConversation } from './Skeleton'
|
|
13
|
-
import { caretOnOpen, InConversationItem, InThreadCard, LineByLayout, useFaceLine, type ConversationItemState } from './threadCard'
|
|
15
|
+
import { caretOnOpen, InConversationItem, InThreadCard, LineByLayout, SHOWN_CLASSES, useFaceLine, type ConversationItemState } from './threadCard'
|
|
14
16
|
|
|
15
17
|
/** One comment in the list, and its thread when it is open. */
|
|
16
18
|
export interface ConversationItem {
|
|
17
19
|
id: string
|
|
18
20
|
/** The comment: a `ConversationCard`. */
|
|
19
21
|
card: ReactNode
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Its thread: a `Thread` with the same `place` as the layout's `threads`, drawn while it is the open one. Give every
|
|
24
|
+
* comment one, even with no replies yet: a card without one cannot be opened. Or a function that draws it, called
|
|
25
|
+
* only while it is the open one: for an app that builds only the open thread.
|
|
26
|
+
*/
|
|
27
|
+
thread?: ReactNode | (() => ReactNode)
|
|
22
28
|
/** Resolved. In one column it waits under "Resolved", closed, at the end; in two columns it stays in its place. */
|
|
23
29
|
resolved?: boolean
|
|
24
30
|
/** What it was on was deleted from the page. In one column it waits under "On deleted blocks", closed, before "Resolved"; a resolved one is under "Resolved". */
|
|
@@ -35,6 +41,8 @@ export interface ConversationLayoutProps {
|
|
|
35
41
|
items: readonly ConversationItem[]
|
|
36
42
|
/** The id of the comment whose thread is open. */
|
|
37
43
|
open?: string
|
|
44
|
+
/** Two columns: what the 384px column holds while no thread is open, the page's own panel beside its comments (an overview). Nothing: no column. */
|
|
45
|
+
aside?: ReactNode
|
|
38
46
|
/**
|
|
39
47
|
* A comment asks to open or close its thread: a press anywhere on its card, its replies row, or Reply. In one column
|
|
40
48
|
* a second press closes it. The layout draws it open in place, with no jump, and puts the caret in its box; the app
|
|
@@ -53,10 +61,18 @@ export interface ConversationLayoutProps {
|
|
|
53
61
|
loading?: boolean
|
|
54
62
|
/** What an empty conversation says: words, or the app's own `EmptyState` (a read that failed says so). `null`: nothing. */
|
|
55
63
|
empty?: ReactNode
|
|
56
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Two columns: the conversation's own name in the app (its address). Where the reader left it is remembered by it in
|
|
66
|
+
* this tab, and going back to it lands there: at the newest if it was left there, else on the same comment. Without
|
|
67
|
+
* it, it opens at the newest each time it is drawn. `useLeftAt` with the same name says when it was left, for a "New" line.
|
|
68
|
+
*/
|
|
69
|
+
rememberAs?: string
|
|
70
|
+
/** Two columns: the comments' scrolling box. Where it scrolls is the layout's: an app reads it, and keeps no place of its own in it. */
|
|
57
71
|
bodyRef?: Ref<HTMLDivElement>
|
|
58
72
|
/** Two columns: the comments' box scrolled. */
|
|
59
73
|
onBodyScroll?: UIEventHandler<HTMLDivElement>
|
|
74
|
+
/** What `useSeenOnScreen` made for this conversation: the layout watches its comments, and says in it which were seen. */
|
|
75
|
+
seen?: SeenOnScreen
|
|
60
76
|
/** Two columns: the comments' own header, a `PageHeader`, over their column only, so the thread beside them runs the page's full height (Peek's way). */
|
|
61
77
|
header?: ReactNode
|
|
62
78
|
/** Its name: one column's, in its header. Two columns, said with the message if the column breaks (the page's own bar is `header`). */
|
|
@@ -80,6 +96,9 @@ interface ListProps {
|
|
|
80
96
|
caret: number
|
|
81
97
|
}
|
|
82
98
|
|
|
99
|
+
/** An item's thread as it is drawn: the app's element, or what its function draws, asked only while it is open. */
|
|
100
|
+
const threadOf = (item: ConversationItem | undefined): ReactNode => (typeof item?.thread === 'function' ? item.thread() : item?.thread)
|
|
101
|
+
|
|
83
102
|
/** The list's own room: placeholders, the empty line, or the comments 8px apart. */
|
|
84
103
|
function List({ items, open, under, above, loading, empty, change, caret }: ListProps) {
|
|
85
104
|
if (loading) return <SkeletonConversation />
|
|
@@ -99,7 +118,7 @@ function List({ items, open, under, above, loading, empty, change, caret }: List
|
|
|
99
118
|
return (
|
|
100
119
|
<Fragment key={item.id}>
|
|
101
120
|
{item.before}
|
|
102
|
-
<div data-conversation-item={item.id} className=
|
|
121
|
+
<div data-conversation-item={item.id} className={cn('flex flex-col', SHOWN_CLASSES)}>
|
|
103
122
|
<InConversationItem.Provider value={stateOf(item)}>{item.card}</InConversationItem.Provider>
|
|
104
123
|
</div>
|
|
105
124
|
</Fragment>
|
|
@@ -189,14 +208,14 @@ function UnderItem({ item, isOpen, state, caret }: { item: ConversationItem; isO
|
|
|
189
208
|
hover="hairline"
|
|
190
209
|
hovered={isOpen}
|
|
191
210
|
quietUntilHover={!isOpen}
|
|
192
|
-
className={cn('relative flex flex-col', isOpen && 'pb-2')}
|
|
211
|
+
className={cn('relative flex flex-col', isOpen && 'pb-2', SHOWN_CLASSES)}
|
|
193
212
|
>
|
|
194
213
|
<InConversationItem.Provider value={state}>
|
|
195
214
|
<InThreadCard.Provider value={isOpen}>
|
|
196
215
|
<LineByLayout.Provider value>
|
|
197
216
|
{/* Over this card's edge, 1px out each way: the comment keeps its place and width, open or closed. */}
|
|
198
217
|
<div className="-m-px flex flex-col">{item.card}</div>
|
|
199
|
-
{isOpen && <caretOnOpen.Provider value={caret}>{item
|
|
218
|
+
{isOpen && <caretOnOpen.Provider value={caret}>{threadOf(item)}</caretOnOpen.Provider>}
|
|
200
219
|
</LineByLayout.Provider>
|
|
201
220
|
</InThreadCard.Provider>
|
|
202
221
|
</InConversationItem.Provider>
|
|
@@ -209,6 +228,9 @@ function UnderItem({ item, isOpen, state, caret }: { item: ConversationItem; isO
|
|
|
209
228
|
)
|
|
210
229
|
}
|
|
211
230
|
|
|
231
|
+
/** The place of a conversation with no name: placed once each time it is drawn, and not remembered. */
|
|
232
|
+
const FRESH: object = {}
|
|
233
|
+
|
|
212
234
|
/**
|
|
213
235
|
* Where a conversation's cards sit, in one of two ways every app picks from (where it sits is the app's, the record
|
|
214
236
|
* says). Two columns: the comments fill the page and an open thread stands beside them, 384px. One column: the
|
|
@@ -219,6 +241,7 @@ export function ConversationLayout({
|
|
|
219
241
|
threads,
|
|
220
242
|
items,
|
|
221
243
|
open,
|
|
244
|
+
aside,
|
|
222
245
|
onOpenChange,
|
|
223
246
|
box,
|
|
224
247
|
above,
|
|
@@ -229,14 +252,28 @@ export function ConversationLayout({
|
|
|
229
252
|
header,
|
|
230
253
|
title = 'Comments',
|
|
231
254
|
actions,
|
|
255
|
+
rememberAs,
|
|
232
256
|
bodyRef,
|
|
233
257
|
onBodyScroll,
|
|
258
|
+
seen,
|
|
234
259
|
className,
|
|
235
260
|
}: ConversationLayoutProps) {
|
|
261
|
+
const beside = threads === 'beside'
|
|
236
262
|
// One column: the pressed comment stays where it was on screen. Opening one thread closes the other, and when that
|
|
237
263
|
// one stood above it, everything under it would rise by its height (Katerina, 31 October). Where it was is noted at
|
|
238
264
|
// the press; once the change is drawn, before it is painted, the column scrolls by however far it went.
|
|
239
265
|
const body = useRef<HTMLDivElement>(null)
|
|
266
|
+
// The comments' box is the layout's, and lent to the app as `bodyRef`.
|
|
267
|
+
const setBody = useCallback(
|
|
268
|
+
(el: HTMLDivElement | null) => {
|
|
269
|
+
body.current = el
|
|
270
|
+
if (typeof bodyRef === 'function') bodyRef(el)
|
|
271
|
+
else if (bodyRef) bodyRef.current = el
|
|
272
|
+
},
|
|
273
|
+
[bodyRef],
|
|
274
|
+
)
|
|
275
|
+
// A comment is read by being seen (Peek's way, Katerina, 30 October): each one in the list is watched.
|
|
276
|
+
useWatchSeen(seen, body, 'data-conversation-item')
|
|
240
277
|
const pressed = useRef<{ id: string; top: number } | null>(null)
|
|
241
278
|
const itemAt = (id: string) => body.current?.querySelector<HTMLElement>(`[data-conversation-item="${CSS.escape(id)}"]`) ?? null
|
|
242
279
|
// A thread that opens puts the caret in its box (Katerina, 31 October); the one open when the page is drawn does not.
|
|
@@ -266,14 +303,89 @@ export function ConversationLayout({
|
|
|
266
303
|
if (open !== undefined && open !== was.current) setCaret((n) => n + 1)
|
|
267
304
|
was.current = open
|
|
268
305
|
}, [open])
|
|
306
|
+
|
|
307
|
+
/*
|
|
308
|
+
Two columns: where the comments scroll, Peek's way (C1 of the audit of 2 November). Was the reader at the live edge
|
|
309
|
+
when something arrived? Only then does it follow: a comment that arrives follows only a reader already at the bottom.
|
|
310
|
+
*/
|
|
311
|
+
const nearBottom = useRef(true)
|
|
312
|
+
// The conversation placed last: once per name (once per drawing, without one), and once its comments are read;
|
|
313
|
+
// none while they are being read. Where the reader is is recorded only while it is placed.
|
|
314
|
+
const placedFor = useRef<string | object | null>(null)
|
|
315
|
+
const placeKey = rememberAs ?? FRESH
|
|
316
|
+
const scrolled = (event: UIEvent<HTMLDivElement>) => {
|
|
317
|
+
const el = body.current
|
|
318
|
+
if (beside && el) {
|
|
319
|
+
nearBottom.current = isNearBottom(el)
|
|
320
|
+
if (rememberAs && placedFor.current === rememberAs) places.set(rememberAs, { atBottom: nearBottom.current, offset: el.scrollTop, anchor: anchorIn(el), leftAt: Date.now() })
|
|
321
|
+
}
|
|
322
|
+
onBodyScroll?.(event)
|
|
323
|
+
}
|
|
324
|
+
// Opening lands at the newest, before the paint. Going back to one lands where it was left (Peek's OPT-3): at the
|
|
325
|
+
// newest if it was left there, so what arrived meanwhile is in view; else on the comment that was at the top.
|
|
326
|
+
useLayoutEffect(() => {
|
|
327
|
+
if (!beside) return
|
|
328
|
+
if (loading) {
|
|
329
|
+
// Its placeholders stand in its comments' place: once they are read it is placed again, and meanwhile nothing
|
|
330
|
+
// is recorded, so the offset the shorter placeholders pull it to is never taken for where the reader left it.
|
|
331
|
+
placedFor.current = null
|
|
332
|
+
return
|
|
333
|
+
}
|
|
334
|
+
if (placedFor.current === placeKey) return
|
|
335
|
+
const el = body.current
|
|
336
|
+
if (!el) return
|
|
337
|
+
const left = rememberAs ? places.get(rememberAs) : undefined
|
|
338
|
+
if (left && !left.atBottom) {
|
|
339
|
+
// That comment back at the same height, not the same offset: what is above it can change height while the
|
|
340
|
+
// reader is away (a "new reply" mark cleared once read, a reactions line).
|
|
341
|
+
el.scrollTop = left.offset
|
|
342
|
+
const card = left.anchor && cardIn(el, left.anchor.id)
|
|
343
|
+
if (card && left.anchor) el.scrollTop += card.getBoundingClientRect().top - el.getBoundingClientRect().top - left.anchor.top
|
|
344
|
+
nearBottom.current = false
|
|
345
|
+
} else {
|
|
346
|
+
el.scrollTop = el.scrollHeight
|
|
347
|
+
nearBottom.current = true
|
|
348
|
+
if (rememberAs) places.set(rememberAs, { atBottom: true, offset: el.scrollTop, leftAt: Date.now() })
|
|
349
|
+
}
|
|
350
|
+
placedFor.current = placeKey
|
|
351
|
+
}, [beside, placeKey, rememberAs, loading])
|
|
352
|
+
// From there, it stays where the reader is while its cards, chips and pictures fill in (Peek's OPT-10).
|
|
353
|
+
const placed = useCallback(() => placedFor.current === placeKey, [placeKey])
|
|
354
|
+
useSteadyScroll(body, nearBottom, placed, loading, beside)
|
|
355
|
+
// Leaving: the moment it was left is when "New" starts on the way back.
|
|
356
|
+
useEffect(() => {
|
|
357
|
+
if (!beside || !rememberAs) return
|
|
358
|
+
return () => {
|
|
359
|
+
const left = places.get(rememberAs)
|
|
360
|
+
if (left) places.set(rememberAs, { ...left, leftAt: Date.now() })
|
|
361
|
+
}
|
|
362
|
+
}, [beside, rememberAs])
|
|
363
|
+
// A comment arrives: follow only a reader who was watching the live edge.
|
|
364
|
+
useLayoutEffect(() => {
|
|
365
|
+
if (!beside || loading || !nearBottom.current) return
|
|
366
|
+
const el = body.current
|
|
367
|
+
if (el) el.scrollTop = el.scrollHeight
|
|
368
|
+
}, [beside, items.length, loading])
|
|
369
|
+
// The reader's own comment, sent from the box, brings them down to it as it is drawn (Peek's OPT-6); a refusal leaves
|
|
370
|
+
// where they actually are to decide what follows next.
|
|
371
|
+
const [sends] = useState(() => ({
|
|
372
|
+
sending: () => {
|
|
373
|
+
nearBottom.current = true
|
|
374
|
+
},
|
|
375
|
+
refused: () => {
|
|
376
|
+
if (body.current) nearBottom.current = isNearBottom(body.current)
|
|
377
|
+
},
|
|
378
|
+
}))
|
|
269
379
|
if (threads === 'under') {
|
|
270
380
|
return (
|
|
271
|
-
<Panel className={cn('w-[384px] flex-none', className)} title={title} actions={actions} bodyRef={
|
|
381
|
+
<Panel className={cn('w-[384px] flex-none', className)} title={title} actions={actions} bodyRef={setBody} bodyClassName="flex flex-col gap-2 p-3" footer={box && <div className="p-3">{box}</div>}>
|
|
272
382
|
<List items={items} open={open} under above={above} loading={loading} empty={empty} change={change} caret={caret} />
|
|
273
383
|
</Panel>
|
|
274
384
|
)
|
|
275
385
|
}
|
|
276
|
-
const opened = items.find((item) => item.id === open)
|
|
386
|
+
const opened = threadOf(items.find((item) => item.id === open))
|
|
387
|
+
// The column: the open thread, or while none is, the page's own panel (Peek's Overview); neither, no column.
|
|
388
|
+
const side = opened || aside
|
|
277
389
|
return (
|
|
278
390
|
<div className={cn('flex min-h-0 min-w-0 flex-1', className)}>
|
|
279
391
|
{/* If the column throws, its name stays with the message, as a Panel's does; the thread beside it stays. */}
|
|
@@ -288,7 +400,7 @@ export function ConversationLayout({
|
|
|
288
400
|
>
|
|
289
401
|
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
|
|
290
402
|
{header}
|
|
291
|
-
<ScrollArea className="min-h-0 flex-1" viewportRef={
|
|
403
|
+
<ScrollArea className="min-h-0 flex-1" viewportRef={setBody} onScroll={scrolled} contentClassName="flex min-h-full flex-col">
|
|
292
404
|
{top != null && top !== false && top !== '' && <div className="shrink-0 px-4 pt-4">{top}</div>}
|
|
293
405
|
{/* A short conversation sits on its box, as a chat does: the newest comment by the box (Peek's way). */}
|
|
294
406
|
<div className="min-h-0 flex-1" />
|
|
@@ -298,12 +410,21 @@ export function ConversationLayout({
|
|
|
298
410
|
</div>
|
|
299
411
|
</ScrollArea>
|
|
300
412
|
{/* Peek's composer room: 12px all round (useFileConversationView's `p-3`), under the list's 16px. */}
|
|
301
|
-
{box &&
|
|
413
|
+
{box && (
|
|
414
|
+
<div className="shrink-0 p-3">
|
|
415
|
+
<sendsInLayout.Provider value={sends}>{box}</sendsInLayout.Provider>
|
|
416
|
+
</div>
|
|
417
|
+
)}
|
|
302
418
|
</div>
|
|
303
419
|
</ErrorBoundary>
|
|
304
|
-
{
|
|
305
|
-
|
|
306
|
-
|
|
420
|
+
{side && (
|
|
421
|
+
// Its own catch, as Peek's column had: a thread or a panel that throws says so in the column, and the comments stay.
|
|
422
|
+
// One catch per thread, and one for the aside: a thread that threw is let go once it is closed or another opens,
|
|
423
|
+
// as Peek's column, drawn only while a thread was open, let it go on closing. Each thread is drawn afresh.
|
|
424
|
+
<div className="flex w-[384px] shrink-0 flex-col overflow-hidden border-l border-border-subtle">
|
|
425
|
+
<ErrorBoundary key={opened ? `thread:${open}` : 'aside'} label="thread panel">
|
|
426
|
+
{opened ? <caretOnOpen.Provider value={caret}>{opened}</caretOnOpen.Provider> : aside}
|
|
427
|
+
</ErrorBoundary>
|
|
307
428
|
</div>
|
|
308
429
|
)}
|
|
309
430
|
</div>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
|
|
2
|
+
import * as Stories from './ConversationPlace.stories'
|
|
3
|
+
|
|
4
|
+
<Meta of={Stories} />
|
|
5
|
+
|
|
6
|
+
# ConversationPlace
|
|
7
|
+
|
|
8
|
+
Above a conversation shown away from where it was said: how it is related, and where it was said.
|
|
9
|
+
|
|
10
|
+
<Canvas of={Stories.MentionedIn} />
|
|
11
|
+
|
|
12
|
+
## When
|
|
13
|
+
|
|
14
|
+
- A list of conversations from elsewhere on a page's Activity: each card under the line saying how it is related to the page (`relation`, "Mentioned in") and the place's name (`place`).
|
|
15
|
+
- Another relation, in your words: the same line, the same look.
|
|
16
|
+
|
|
17
|
+
<Canvas of={Stories.OnAnItemUnderIt} />
|
|
18
|
+
|
|
19
|
+
- The place's name has not come yet: leave `place` out. The relation is drawn alone, never a placeholder: "Loading…" beside a real comment reads worse than a line that has not said where it is from yet.
|
|
20
|
+
|
|
21
|
+
<Canvas of={Stories.PlaceNotNamedYet} />
|
|
22
|
+
|
|
23
|
+
<Canvas of={Stories.LongPlace} />
|
|
24
|
+
|
|
25
|
+
## When not
|
|
26
|
+
|
|
27
|
+
- The conversation is on this page: its card alone → **ConversationCard**.
|
|
28
|
+
- A comment on a part of the page: what it is on goes inside the card, in its `about` → **QuotedLine**.
|
|
29
|
+
|
|
30
|
+
## How
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { ConversationCard, ConversationPlace } from '@estiva-app/ui'
|
|
34
|
+
|
|
35
|
+
<ConversationPlace relation="Mentioned in" place={nameOf(address)} data-relation="mention">
|
|
36
|
+
<ConversationCard author={author} time={time} readOnly onClick={openWhereSaid}>
|
|
37
|
+
{words}
|
|
38
|
+
</ConversationCard>
|
|
39
|
+
</ConversationPlace>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- The words are yours: `relation` is how the conversation is related, `place` the name your app gives the place.
|
|
43
|
+
- The card is yours too: it goes in as `children`, under the line, 4px below it.
|
|
44
|
+
- The place's name is cut to the column.
|
|
45
|
+
- Anything else you pass (a `data-…` mark) lands on the row, so you can find it.
|
|
46
|
+
|
|
47
|
+
## What it owns
|
|
48
|
+
|
|
49
|
+
Nothing. It only draws. Clicks and keys are yours.
|
|
50
|
+
|
|
51
|
+
## Props
|
|
52
|
+
|
|
53
|
+
<Controls />
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { ConversationCard } from './ConversationCard'
|
|
3
|
+
import { Column, ONE, TWO, WORDS } from './conversation.examples'
|
|
4
|
+
import { ConversationPlace } from './ConversationPlace'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where a conversation shown away from its place was said, above its card: how it is related, and the place's name.
|
|
8
|
+
* The words are the app's; these are the ones the specification uses (SPEC §6.4).
|
|
9
|
+
*/
|
|
10
|
+
const meta = {
|
|
11
|
+
title: 'Conversation/ConversationPlace',
|
|
12
|
+
component: ConversationPlace,
|
|
13
|
+
parameters: { layout: 'padded' },
|
|
14
|
+
args: { relation: 'Mentioned in', place: 'Item one' },
|
|
15
|
+
argTypes: { children: { control: false } },
|
|
16
|
+
decorators: [(Story) => <Column>{Story()}</Column>],
|
|
17
|
+
render: (args) => (
|
|
18
|
+
<ConversationPlace {...args}>
|
|
19
|
+
<ConversationCard author={ONE} time="11:08 AM" readOnly onClick={() => {}}>
|
|
20
|
+
{WORDS}
|
|
21
|
+
</ConversationCard>
|
|
22
|
+
</ConversationPlace>
|
|
23
|
+
),
|
|
24
|
+
} satisfies Meta<typeof ConversationPlace>
|
|
25
|
+
|
|
26
|
+
export default meta
|
|
27
|
+
type Story = StoryObj<typeof meta>
|
|
28
|
+
|
|
29
|
+
/** Said somewhere else, naming this page: the relation and where it was said. */
|
|
30
|
+
export const MentionedIn: Story = {}
|
|
31
|
+
|
|
32
|
+
/** The conversation of something under this page: another relation, in the app's words. */
|
|
33
|
+
export const OnAnItemUnderIt: Story = {
|
|
34
|
+
args: { relation: 'On an item', place: 'Item two' },
|
|
35
|
+
render: (args) => (
|
|
36
|
+
<ConversationPlace {...args}>
|
|
37
|
+
<ConversationCard author={TWO} time="Yesterday" onClick={() => {}}>
|
|
38
|
+
{WORDS}
|
|
39
|
+
</ConversationCard>
|
|
40
|
+
</ConversationPlace>
|
|
41
|
+
),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The place's name has not come yet: the relation alone, never a placeholder. */
|
|
45
|
+
export const PlaceNotNamedYet: Story = { args: { place: undefined } }
|
|
46
|
+
|
|
47
|
+
/** A long name is cut to the column. */
|
|
48
|
+
export const LongPlace: Story = { args: { place: 'Item one, with a name long enough to be cut short at the column’s edge' } }
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* What the ConversationPlace page claims, pinned: above a conversation shown
|
|
4
|
+
* away from where it was said, the line says how it is related and where, in
|
|
5
|
+
* the app's words; a place not named yet draws nothing rather than a
|
|
6
|
+
* placeholder; and the row keeps what the app marks it with. Peek's Activity
|
|
7
|
+
* row (TopicActivity), moved.
|
|
8
|
+
*/
|
|
9
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
10
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
11
|
+
import { ConversationPlace } from './ConversationPlace'
|
|
12
|
+
|
|
13
|
+
afterEach(cleanup)
|
|
14
|
+
|
|
15
|
+
describe('ConversationPlace', () => {
|
|
16
|
+
it('says how the conversation is related and where it was said, above it', () => {
|
|
17
|
+
render(
|
|
18
|
+
<ConversationPlace relation="Mentioned in" place="Item one">
|
|
19
|
+
<p>The conversation</p>
|
|
20
|
+
</ConversationPlace>,
|
|
21
|
+
)
|
|
22
|
+
const relation = screen.getByText('Mentioned in')
|
|
23
|
+
const place = screen.getByText('Item one')
|
|
24
|
+
const card = screen.getByText('The conversation')
|
|
25
|
+
expect(relation.compareDocumentPosition(place) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
|
26
|
+
expect(place.compareDocumentPosition(card) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('a place not named yet draws nothing beside the relation, never a placeholder', () => {
|
|
30
|
+
const { container } = render(
|
|
31
|
+
<ConversationPlace relation="On an item">
|
|
32
|
+
<p>The conversation</p>
|
|
33
|
+
</ConversationPlace>,
|
|
34
|
+
)
|
|
35
|
+
expect(screen.getByText('On an item')).toBeTruthy()
|
|
36
|
+
expect(container.textContent).toBe('On an itemThe conversation')
|
|
37
|
+
cleanup()
|
|
38
|
+
const empty = render(<ConversationPlace relation="On an item" place="" />)
|
|
39
|
+
expect(empty.container.textContent).toBe('On an item')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('keeps what the app marks the row with, so the app can find it', () => {
|
|
43
|
+
const { container } = render(
|
|
44
|
+
<ConversationPlace relation="Mentioned in" place="Item one" data-relation="mention">
|
|
45
|
+
<p>The conversation</p>
|
|
46
|
+
</ConversationPlace>,
|
|
47
|
+
)
|
|
48
|
+
const row = container.querySelector('[data-relation="mention"]')
|
|
49
|
+
expect(row?.textContent).toBe('Mentioned inItem oneThe conversation')
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ComponentPropsWithRef, ReactNode } from 'react'
|
|
2
|
+
import { Chip } from './Chip'
|
|
3
|
+
import { cn } from './cn'
|
|
4
|
+
|
|
5
|
+
export interface ConversationPlaceProps extends Omit<ComponentPropsWithRef<'div'>, 'children'> {
|
|
6
|
+
/** How the conversation is related to the page it is shown on, in the app's words: "Mentioned in". */
|
|
7
|
+
relation: string
|
|
8
|
+
/** Where it was said: the place's name. Absent or empty while it resolves, and then nothing is drawn for it. */
|
|
9
|
+
place?: string
|
|
10
|
+
/** The conversation, as the app draws it: its card. */
|
|
11
|
+
children?: ReactNode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Where a conversation shown away from its place was said: a chip saying how it is related ("Mentioned in"), the
|
|
16
|
+
* place's name beside it, and the conversation's card under them. Peek's Activity row (TopicActivity), moved, as it
|
|
17
|
+
* draws it: a place not named yet is drawn as nothing, never as a placeholder ("Loading…" beside a real message reads
|
|
18
|
+
* worse than a row that has not said where it is from yet).
|
|
19
|
+
*/
|
|
20
|
+
export function ConversationPlace({ relation, place, children, className, ...props }: ConversationPlaceProps) {
|
|
21
|
+
return (
|
|
22
|
+
<div className={cn('flex flex-col gap-1', className)} {...props}>
|
|
23
|
+
<div className="flex items-center gap-2">
|
|
24
|
+
<Chip type="neutral" label={relation} />
|
|
25
|
+
{place && <span className="truncate text-caption text-text-muted">{place}</span>}
|
|
26
|
+
</div>
|
|
27
|
+
{children}
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
package/src/DocumentEditor.mdx
CHANGED
|
@@ -29,7 +29,7 @@ One document's text as one surface that is always an editor, the same in every a
|
|
|
29
29
|
|
|
30
30
|
- Something sent, a comment or a line in a conversation → **CommentBox**. Nothing is sent from here; it saves.
|
|
31
31
|
- One line, a title or the line under it → **InlineText**.
|
|
32
|
-
- Text in a form → **TextInput** or **Textarea**.
|
|
32
|
+
- Text in a form → **TextInput** or **Textarea**; a document written in a form, sent with it → **DocumentField**.
|
|
33
33
|
|
|
34
34
|
## How
|
|
35
35
|
|
|
@@ -97,6 +97,7 @@ It does these by itself. Write none of them around it.
|
|
|
97
97
|
| Where each link sits — chip, row, or card in the row's place — kept current as you type, and its menu: Open, Show as Row or Card | a line rule, a card slot, a link menu |
|
|
98
98
|
| A pasted picture uploaded and placed; the file dialog's blur is not leaving | an upload state |
|
|
99
99
|
| Read only: no caret, no `/`, `[` or `@`, no format buttons; still focusable, so a selection's Comment shows | a reading view |
|
|
100
|
+
| Selected words painted in the selected colour, the one the format buttons' link field keeps them in | a `::selection` rule |
|
|
100
101
|
|
|
101
102
|
## Keys
|
|
102
103
|
|