@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.
Files changed (193) hide show
  1. package/README.md +1 -1
  2. package/dist/AppProvider.d.ts +6 -3
  3. package/dist/AppProvider.d.ts.map +1 -1
  4. package/dist/ArchiveDialog.d.ts +35 -0
  5. package/dist/ArchiveDialog.d.ts.map +1 -0
  6. package/dist/AttachedCard.d.ts +13 -2
  7. package/dist/AttachedCard.d.ts.map +1 -1
  8. package/dist/Card.d.ts +6 -1
  9. package/dist/Card.d.ts.map +1 -1
  10. package/dist/ChipInput.d.ts +3 -1
  11. package/dist/ChipInput.d.ts.map +1 -1
  12. package/dist/CollapsibleSection.d.ts +27 -2
  13. package/dist/CollapsibleSection.d.ts.map +1 -1
  14. package/dist/CommentBox.d.ts +2 -2
  15. package/dist/CommentBox.d.ts.map +1 -1
  16. package/dist/ConfirmDialog.d.ts +15 -2
  17. package/dist/ConfirmDialog.d.ts.map +1 -1
  18. package/dist/ConversationCard.d.ts +6 -1
  19. package/dist/ConversationCard.d.ts.map +1 -1
  20. package/dist/ConversationLayout.d.ts +19 -4
  21. package/dist/ConversationLayout.d.ts.map +1 -1
  22. package/dist/ConversationPlace.d.ts +17 -0
  23. package/dist/ConversationPlace.d.ts.map +1 -0
  24. package/dist/DocumentEditor.d.ts +38 -0
  25. package/dist/DocumentEditor.d.ts.map +1 -1
  26. package/dist/DocumentField.d.ts +50 -0
  27. package/dist/DocumentField.d.ts.map +1 -0
  28. package/dist/EditableText.d.ts +38 -4
  29. package/dist/EditableText.d.ts.map +1 -1
  30. package/dist/EmptyState.d.ts +10 -5
  31. package/dist/EmptyState.d.ts.map +1 -1
  32. package/dist/FormDialog.d.ts +38 -0
  33. package/dist/FormDialog.d.ts.map +1 -0
  34. package/dist/InlineText.d.ts.map +1 -1
  35. package/dist/MoveDialog.d.ts +61 -0
  36. package/dist/MoveDialog.d.ts.map +1 -0
  37. package/dist/NavItem.d.ts +9 -2
  38. package/dist/NavItem.d.ts.map +1 -1
  39. package/dist/NavTree.d.ts +16 -3
  40. package/dist/NavTree.d.ts.map +1 -1
  41. package/dist/PinnedComment.d.ts +3 -1
  42. package/dist/PinnedComment.d.ts.map +1 -1
  43. package/dist/ReactionHorizon.d.ts +5 -1
  44. package/dist/ReactionHorizon.d.ts.map +1 -1
  45. package/dist/ResolveDialog.d.ts +3 -1
  46. package/dist/ResolveDialog.d.ts.map +1 -1
  47. package/dist/SelectionToolbar.d.ts +2 -2
  48. package/dist/Thread.d.ts +6 -3
  49. package/dist/Thread.d.ts.map +1 -1
  50. package/dist/commentBoxFrame.d.ts.map +1 -1
  51. package/dist/conversation.examples.d.ts +4 -1
  52. package/dist/conversation.examples.d.ts.map +1 -1
  53. package/dist/conversationScroll.d.ts +80 -0
  54. package/dist/conversationScroll.d.ts.map +1 -0
  55. package/dist/editor.d.ts +1 -0
  56. package/dist/editor.d.ts.map +1 -1
  57. package/dist/editor.js +228 -69
  58. package/dist/editor.js.map +4 -4
  59. package/dist/eslint/index.js +2 -2
  60. package/dist/eslint/index.js.map +2 -2
  61. package/dist/eslint/no-field-outside-a-form.d.ts +2 -2
  62. package/dist/eslint/no-field-outside-a-form.d.ts.map +1 -1
  63. package/dist/eslint/no-native-title.d.ts +1 -1
  64. package/dist/eslint/no-native-title.d.ts.map +1 -1
  65. package/dist/formBusy.d.ts +5 -2
  66. package/dist/formBusy.d.ts.map +1 -1
  67. package/dist/index.d.ts +14 -6
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +2210 -1458
  70. package/dist/index.js.map +4 -4
  71. package/dist/looks.d.ts +8 -0
  72. package/dist/looks.d.ts.map +1 -1
  73. package/dist/seenOnScreen.d.ts +27 -0
  74. package/dist/seenOnScreen.d.ts.map +1 -0
  75. package/dist/showInConversation.d.ts +31 -0
  76. package/dist/showInConversation.d.ts.map +1 -0
  77. package/dist/threadCard.d.ts +13 -0
  78. package/dist/threadCard.d.ts.map +1 -1
  79. package/package.json +1 -1
  80. package/registry.json +904 -139
  81. package/src/AppProvider.mdx +4 -0
  82. package/src/AppProvider.test.tsx +34 -2
  83. package/src/AppProvider.tsx +17 -6
  84. package/src/ArchiveDialog.mdx +70 -0
  85. package/src/ArchiveDialog.stories.tsx +64 -0
  86. package/src/ArchiveDialog.test.tsx +90 -0
  87. package/src/ArchiveDialog.tsx +70 -0
  88. package/src/AttachedCard.mdx +6 -0
  89. package/src/AttachedCard.stories.tsx +9 -1
  90. package/src/AttachedCard.test.tsx +111 -2
  91. package/src/AttachedCard.tsx +77 -7
  92. package/src/Card.mdx +20 -1
  93. package/src/Card.stories.tsx +20 -0
  94. package/src/Card.test.tsx +87 -1
  95. package/src/Card.tsx +51 -3
  96. package/src/ChipInput.mdx +7 -1
  97. package/src/ChipInput.stories.tsx +9 -0
  98. package/src/ChipInput.test.tsx +42 -0
  99. package/src/ChipInput.tsx +7 -3
  100. package/src/CollapsibleSection.mdx +20 -1
  101. package/src/CollapsibleSection.stories.tsx +19 -1
  102. package/src/CollapsibleSection.test.tsx +85 -2
  103. package/src/CollapsibleSection.tsx +54 -15
  104. package/src/CommentBox.mdx +2 -1
  105. package/src/CommentBox.test.tsx +81 -1
  106. package/src/CommentBox.tsx +32 -11
  107. package/src/ConfirmDialog.mdx +25 -3
  108. package/src/ConfirmDialog.stories.tsx +27 -0
  109. package/src/ConfirmDialog.test.tsx +87 -1
  110. package/src/ConfirmDialog.tsx +39 -8
  111. package/src/ConversationCard.mdx +4 -0
  112. package/src/ConversationCard.stories.tsx +11 -1
  113. package/src/ConversationCard.test.tsx +116 -0
  114. package/src/ConversationCard.tsx +53 -36
  115. package/src/ConversationLayout.mdx +30 -4
  116. package/src/ConversationLayout.scroll.test.tsx +411 -0
  117. package/src/ConversationLayout.stories.tsx +79 -1
  118. package/src/ConversationLayout.test.tsx +79 -0
  119. package/src/ConversationLayout.tsx +136 -15
  120. package/src/ConversationPlace.mdx +53 -0
  121. package/src/ConversationPlace.stories.tsx +48 -0
  122. package/src/ConversationPlace.test.tsx +51 -0
  123. package/src/ConversationPlace.tsx +30 -0
  124. package/src/DocumentEditor.mdx +2 -1
  125. package/src/DocumentEditor.tsx +118 -64
  126. package/src/DocumentField.mdx +83 -0
  127. package/src/DocumentField.stories.tsx +110 -0
  128. package/src/DocumentField.test.tsx +281 -0
  129. package/src/DocumentField.tsx +199 -0
  130. package/src/EditableText.buttons.test.tsx +318 -0
  131. package/src/EditableText.mdx +50 -2
  132. package/src/EditableText.stories.tsx +96 -2
  133. package/src/EditableText.tsx +189 -5
  134. package/src/EmptyState.mdx +33 -8
  135. package/src/EmptyState.stories.tsx +26 -1
  136. package/src/EmptyState.test.tsx +63 -2
  137. package/src/EmptyState.tsx +28 -6
  138. package/src/Form.mdx +3 -1
  139. package/src/FormDialog.mdx +78 -0
  140. package/src/FormDialog.stories.tsx +90 -0
  141. package/src/FormDialog.test.tsx +183 -0
  142. package/src/FormDialog.tsx +93 -0
  143. package/src/InlineText.mdx +1 -0
  144. package/src/InlineText.tsx +2 -1
  145. package/src/MoveDialog.mdx +74 -0
  146. package/src/MoveDialog.stories.tsx +121 -0
  147. package/src/MoveDialog.test.tsx +203 -0
  148. package/src/MoveDialog.tsx +183 -0
  149. package/src/NavItem.mdx +15 -0
  150. package/src/NavItem.stories.tsx +15 -0
  151. package/src/NavItem.test.tsx +64 -1
  152. package/src/NavItem.tsx +10 -2
  153. package/src/NavTree.mdx +26 -4
  154. package/src/NavTree.stories.tsx +59 -0
  155. package/src/NavTree.test.tsx +232 -2
  156. package/src/NavTree.tsx +93 -43
  157. package/src/PinnedComment.mdx +6 -1
  158. package/src/PinnedComment.stories.tsx +11 -1
  159. package/src/PinnedComment.tsx +15 -2
  160. package/src/ReactionHorizon.mdx +3 -0
  161. package/src/ReactionHorizon.stories.tsx +3 -0
  162. package/src/ReactionHorizon.test.tsx +55 -0
  163. package/src/ReactionHorizon.tsx +30 -11
  164. package/src/ReplyCard.mdx +3 -0
  165. package/src/ReplyCard.stories.tsx +19 -1
  166. package/src/ResolveDialog.mdx +2 -0
  167. package/src/ResolveDialog.test.tsx +21 -0
  168. package/src/ResolveDialog.tsx +11 -39
  169. package/src/SelectionToolbar.tsx +2 -2
  170. package/src/Textarea.mdx +1 -0
  171. package/src/Thread.mdx +18 -1
  172. package/src/Thread.stories.tsx +55 -3
  173. package/src/Thread.test.tsx +11 -0
  174. package/src/Thread.tsx +53 -11
  175. package/src/commentBoxFrame.tsx +2 -2
  176. package/src/conversation.examples.tsx +10 -2
  177. package/src/conversationScroll.ts +155 -0
  178. package/src/editor.ts +1 -0
  179. package/src/editorSelection.test.tsx +53 -0
  180. package/src/eslint/no-field-outside-a-form.test.ts +4 -0
  181. package/src/eslint/no-field-outside-a-form.ts +2 -2
  182. package/src/eslint/no-native-title.ts +1 -1
  183. package/src/formBusy.ts +5 -2
  184. package/src/index.ts +16 -6
  185. package/src/looks.ts +10 -0
  186. package/src/registry/registry.test.ts +12 -6
  187. package/src/seenOnScreen.test.tsx +182 -0
  188. package/src/seenOnScreen.ts +146 -0
  189. package/src/showInConversation.test.tsx +168 -0
  190. package/src/showInConversation.ts +93 -0
  191. package/src/threadCard.ts +16 -0
  192. package/stories/Choosing.mdx +7 -2
  193. 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
- /** Its thread: a `Thread` with the same `place` as the layout's `threads`, drawn while it is the open one. Give every comment one, even with no replies yet: a card without one cannot be opened. */
21
- thread?: ReactNode
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
- /** Two columns: the comments' scrolling box, for an app that keeps its own place in it (where it was left, its "New" line, following what arrives). */
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="flex flex-col">
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.thread}</caretOnOpen.Provider>}
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={body} bodyClassName="flex flex-col gap-2 p-3" footer={box && <div className="p-3">{box}</div>}>
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)?.thread
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={bodyRef} onScroll={onBodyScroll} contentClassName="flex min-h-full flex-col">
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 && <div className="shrink-0 p-3">{box}</div>}
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
- {opened && (
305
- <div className="flex w-[384px] shrink-0 flex-col border-l border-border-subtle">
306
- <caretOnOpen.Provider value={caret}>{opened}</caretOnOpen.Provider>
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
+ }
@@ -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