@estiva-app/ui 0.98.1 → 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 +3 -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 +2207 -1463
  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 +784 -25
  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 +3 -0
  112. package/src/ConversationCard.stories.tsx +11 -1
  113. package/src/ConversationCard.test.tsx +76 -0
  114. package/src/ConversationCard.tsx +52 -48
  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 +2 -0
  161. package/src/ReactionHorizon.stories.tsx +3 -0
  162. package/src/ReactionHorizon.test.tsx +32 -0
  163. package/src/ReactionHorizon.tsx +28 -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,9 +1,9 @@
1
- import { useState, type ReactNode } from 'react'
2
- import { Button } from './Button'
1
+ import { useRef, useState, type ReactNode } from 'react'
2
+ import { Button, type ButtonAction } from './Button'
3
3
  import { DialogShell } from './DialogShell'
4
4
 
5
5
  /**
6
- * A question with two answers, before something a person would want back —
6
+ * A question with two answers — three, with a safer `alternative` — before something a person would want back —
7
7
  * Ship's ConfirmDialog (2026-09-01), verbatim. Its own comment always called
8
8
  * it a package candidate: nothing here knows what is being confirmed.
9
9
  *
@@ -17,6 +17,12 @@ import { DialogShell } from './DialogShell'
17
17
  * closes it** (Katerina, D20): a destructive question is answered, not
18
18
  * clicked away. Escape and the close button still cancel, as they did.
19
19
  */
20
+ /** A third answer: the safer one, with the sentence that says why. */
21
+ export interface ConfirmDialogAlternative extends ButtonAction {
22
+ /** The sentence above the button — "To take it out of every list and keep it readable, archive it instead." */
23
+ sentence: string
24
+ }
25
+
20
26
  export interface ConfirmDialogProps {
21
27
  title: string
22
28
  /** The body — plain sentences, body-2. */
@@ -24,16 +30,30 @@ export interface ConfirmDialogProps {
24
30
  confirmLabel: string
25
31
  destructive?: boolean
26
32
  onConfirm: () => Promise<boolean | void> | boolean | void
33
+ /** Cancel, Escape, the ✕, and an action that went through: once, when it was closed while the action ran. */
27
34
  onClose: () => void
35
+ /**
36
+ * A third, safer answer — "Archive instead" — drawn after the words, under
37
+ * its sentence, and switched off while the confirm runs (Peek's, 2 November).
38
+ * It closes nothing: what it opens takes this question's place.
39
+ */
40
+ alternative?: ConfirmDialogAlternative
28
41
  }
29
42
 
30
- export function ConfirmDialog({ title, children, confirmLabel, destructive = false, onConfirm, onClose }: ConfirmDialogProps) {
43
+ export function ConfirmDialog({ title, children, confirmLabel, destructive = false, onConfirm, onClose, alternative }: ConfirmDialogProps) {
31
44
  const [busy, setBusy] = useState(false)
45
+ // Closed while the action ran (Escape, the ✕): the action that then goes through does not close it a second time.
46
+ const closed = useRef(false)
47
+ const close = () => {
48
+ closed.current = true
49
+ onClose()
50
+ }
32
51
  const confirm = async () => {
52
+ closed.current = false
33
53
  setBusy(true)
34
54
  try {
35
55
  const ok = await onConfirm()
36
- if (ok !== false) onClose()
56
+ if (ok !== false && !closed.current) close()
37
57
  } finally {
38
58
  setBusy(false)
39
59
  }
@@ -42,10 +62,10 @@ export function ConfirmDialog({ title, children, confirmLabel, destructive = fal
42
62
  <DialogShell
43
63
  alert
44
64
  title={title}
45
- onClose={onClose}
65
+ onClose={close}
46
66
  footer={
47
67
  <>
48
- <Button variant="muted" onClick={onClose} disabled={busy}>
68
+ <Button variant="muted" onClick={close} disabled={busy}>
49
69
  Cancel
50
70
  </Button>
51
71
  <Button variant={destructive ? 'destructive' : 'primary'} onClick={() => void confirm()} disabled={busy}>
@@ -55,7 +75,18 @@ export function ConfirmDialog({ title, children, confirmLabel, destructive = fal
55
75
  }
56
76
  >
57
77
  {/* The words' look on a box of the dialog's own, not pushed into DialogShell's body (UIG-9). */}
58
- <div className="flex flex-col gap-3 text-body-2 text-text-primary">{children}</div>
78
+ <div className="flex flex-col gap-3 text-body-2 text-text-primary">
79
+ {children}
80
+ {/* Its sentence and its button one block, 8px apart, as Peek's delete question drew them. */}
81
+ {alternative && (
82
+ <div className="flex flex-col items-start gap-2">
83
+ <p>{alternative.sentence}</p>
84
+ <Button variant="outlined" size="small" onClick={alternative.onClick} disabled={busy}>
85
+ {alternative.label}
86
+ </Button>
87
+ </div>
88
+ )}
89
+ </div>
59
90
  </DialogShell>
60
91
  )
61
92
  }
@@ -17,6 +17,7 @@ One comment, the same in every app: who, when, the words, files, cards, reaction
17
17
  - `noun`: what the delete question calls it, "Delete this comment?" by default; a direct message says `message`.
18
18
  - `about` on a comment on a part of the page: a **QuotedLine** under the name, above the words.
19
19
  - `isNew`, `urgent`: the dot or the urgent mark, and a hairline, until it is read.
20
+ - `at`, its moment: the time says the exact date and time under the pointer, in the reader's own way. Give it on every comment.
20
21
 
21
22
  <Canvas of={Stories.Replies} />
22
23
 
@@ -56,6 +57,7 @@ import { ConversationCard } from '@estiva-app/ui'
56
57
  - **The words are yours to draw**: text, people named, links, attached cards and quoted blocks, with **RichText** and the link parts. The card gives them their size and colour.
57
58
  - **Edit opens your box**: `editor` draws your **CommentBox** edit form; call `done` when it saves or cancels. To open it again after a refused save, hold `editing` yourself.
58
59
  - **Resolve opens the dialog**: **ResolveDialog**, then `onResolve(note)`. Answer `false` when it was refused; the dialog stays.
60
+ - `time` is your words for it ("11:08 AM"); `at` is the moment (ms), from which the card says the exact date and time on hover. Never a tooltip of your own round `time`.
59
61
  - A press on the card is `onClick` (its thread opens); a press on a button, a link or anything marked `data-interactive` inside it is not.
60
62
  - The strip shows while the card is pointed at or has focus, and holds while its reactions or its menu are open.
61
63
 
@@ -66,6 +68,7 @@ import { ConversationCard } from '@estiva-app/ui'
66
68
  | Shows its actions while pointed at, and holds them while a menu is open | hover state and an outside-click check | |
67
69
  | A card that opens on a press is a Tab stop: reaching it shows its actions, Enter or Space opens it | a `tabIndex` and a key handler | |
68
70
  | Asks before it deletes | a confirm dialog | |
71
+ | Says the exact date and time under the pointer, from `at` | a tooltip round the time | |
69
72
  | Opens the Resolve dialog, and closes it once resolved | a dialog and its open state | |
70
73
  | Says it is resolved, with who and the note, and hides nothing of it | a resolved line or chip of your own | |
71
74
 
@@ -1,7 +1,8 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
2
  import { useState } from 'react'
3
+ import { userEvent, within } from 'storybook/test'
3
4
  import { ConversationCard, type ConversationCardProps } from './ConversationCard'
4
- import { Column, EditBox, Files, LONG, Mentions, ONE, SOME, THREE, TWO, WithBlock, WithCard, WORDS, YOU, useReactions } from './conversation.examples'
5
+ import { AT, Column, EditBox, Files, LONG, Mentions, ONE, SOME, THREE, TWO, WithBlock, WithCard, WORDS, YOU, useReactions } from './conversation.examples'
5
6
  import { RichText } from './RichText'
6
7
  import { MenuItem } from './Menu'
7
8
  import type { ReactionCount } from './ReactionRow'
@@ -49,6 +50,15 @@ function Live({ start, resolvedAt, deletable = true, ...props }: ConversationCar
49
50
  /** Someone's comment. */
50
51
  export const Comment: Story = { render: (args) => <Live {...args} /> }
51
52
 
53
+ /** With its moment, `at`: the time says the exact date and time under the pointer. The story points at it. */
54
+ export const ExactTime: Story = {
55
+ name: 'Exact time',
56
+ render: (args) => <Live {...args} at={AT} />,
57
+ play: async ({ canvasElement }) => {
58
+ await userEvent.hover(within(canvasElement).getByText('11:08 AM'))
59
+ },
60
+ }
61
+
52
62
  /** Yours: Edit and Delete in its ⋯ menu. */
53
63
  export const Yours: Story = { render: (args) => <Live {...args} author={YOU} own /> }
54
64
 
@@ -3,6 +3,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
3
3
  import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'
4
4
  import userEvent from '@testing-library/user-event'
5
5
  import { ConversationCard, ReplyCard } from './ConversationCard'
6
+ import { PinnedComment } from './PinnedComment'
6
7
 
7
8
  afterEach(cleanup)
8
9
 
@@ -197,3 +198,78 @@ describe('ConversationCard, by the keyboard (Peek’s review, 1 November)', () =
197
198
  expect(container.querySelector('[tabindex="0"]')).toBeNull()
198
199
  })
199
200
  })
201
+
202
+ /**
203
+ * The exact time on hover (B10, the audit of 2 November): Peek's words for it, the whole date and the time
204
+ * (`toLocaleString`, `dateStyle: 'long'`, `timeStyle: 'short'`), on every comment and reply, as Peek's rows of another
205
+ * app's comments always said it and as PageHeader's time does. Before, only those rows did, by hand.
206
+ */
207
+ describe('ConversationCard and ReplyCard, the exact time', () => {
208
+ const AT = Date.UTC(2026, 10, 2, 11, 8)
209
+ const exact = new Date(AT).toLocaleString(undefined, { dateStyle: 'long', timeStyle: 'short' })
210
+
211
+ it('a comment’s time says the exact date and time under the pointer, and is a time the page can read', async () => {
212
+ const user = userEvent.setup()
213
+ render(
214
+ <ConversationCard author={ONE} time="11:08 AM" at={AT}>
215
+ Words
216
+ </ConversationCard>,
217
+ )
218
+ const time = screen.getByText('11:08 AM')
219
+ expect(time.tagName).toBe('TIME')
220
+ expect(time.getAttribute('datetime')).toBe(new Date(AT).toISOString())
221
+ await user.hover(time)
222
+ expect((await screen.findByRole('tooltip')).textContent).toBe(exact)
223
+ })
224
+
225
+ it('a reply’s too', async () => {
226
+ const user = userEvent.setup()
227
+ render(
228
+ <ReplyCard author={ONE} time="11:08 AM" at={AT}>
229
+ Words
230
+ </ReplyCard>,
231
+ )
232
+ await user.hover(screen.getByText('11:08 AM'))
233
+ expect((await screen.findByRole('tooltip')).textContent).toBe(exact)
234
+ })
235
+
236
+ it('a time that is a link says the exact time, then where the link goes', async () => {
237
+ const user = userEvent.setup()
238
+ render(
239
+ <ReplyCard author={ONE} time="11:08 AM" at={AT} timeHref="#reply" timeLabel="Link to this one">
240
+ Words
241
+ </ReplyCard>,
242
+ )
243
+ await user.hover(screen.getByRole('link', { name: '11:08 AM' }))
244
+ expect((await screen.findByRole('tooltip')).textContent).toBe(`${exact} · Link to this one`)
245
+ })
246
+
247
+ it('a moment that is not one (not a number, endless) draws the time as with none, and breaks nothing', () => {
248
+ for (const at of [NaN, Infinity]) {
249
+ render(
250
+ <>
251
+ <ConversationCard author={ONE} time="11:08 AM" at={at}>
252
+ A comment
253
+ </ConversationCard>
254
+ <ReplyCard author={ONE} time="11:30 AM" at={at}>
255
+ A reply
256
+ </ReplyCard>
257
+ <PinnedComment author={ONE} time="Today at 11:08 AM" at={at} words="The comment" />
258
+ </>,
259
+ )
260
+ for (const time of ['11:08 AM', '11:30 AM', 'Today at 11:08 AM']) expect(screen.getByText(time).tagName).not.toBe('TIME')
261
+ cleanup()
262
+ }
263
+ })
264
+
265
+ it('with no moment, the time is the app’s words alone, as before', async () => {
266
+ const user = userEvent.setup()
267
+ render(
268
+ <ConversationCard author={ONE} time="11:08 AM">
269
+ Words
270
+ </ConversationCard>,
271
+ )
272
+ await user.hover(screen.getByText('11:08 AM'))
273
+ expect(screen.queryByRole('tooltip')).toBeNull()
274
+ })
275
+ })
@@ -1,4 +1,4 @@
1
- import { useContext, useRef, useState, type MouseEvent, type ReactNode } from 'react'
1
+ import { useContext, useLayoutEffect, useRef, useState, type ReactNode } from 'react'
2
2
  import { IconArrowNarrowRight, IconCircleCheck, IconDotsVertical } from '@tabler/icons-react'
3
3
  import { Avatar } from './Avatar'
4
4
  import { Card } from './Card'
@@ -6,6 +6,7 @@ import { cn } from './cn'
6
6
  import { ConfirmDialog } from './ConfirmDialog'
7
7
  import { ConversationActions } from './ConversationActions'
8
8
  import { ConversationMenu } from './ConversationMenu'
9
+ import { repliesDrawn } from './conversationScroll'
9
10
  import { EditedMarker } from './EditedMarker'
10
11
  import { FieldLine } from './Field'
11
12
  import { Link } from './Link'
@@ -13,7 +14,7 @@ import { MetaText } from './MetaText'
13
14
  import { ReactionRow, type ReactionRowProps } from './ReactionRow'
14
15
  import { RepliesRow, type RepliesRowProps } from './RepliesRow'
15
16
  import { ResolveDialog } from './ResolveDialog'
16
- import { InConversationItem, InThreadCard, useFaceLine } from './threadCard'
17
+ import { exactTime, InConversationItem, InThreadCard, momentOf, SHOWN_CLASSES, useFaceLine } from './threadCard'
17
18
  import { ToolbarButton } from './Toolbar'
18
19
  import { WithTooltip } from './Tooltip'
19
20
  import { UnreadDot } from './UnreadDot'
@@ -32,6 +33,8 @@ export interface ConversationEntryProps {
32
33
  author: ConversationPerson
33
34
  /** When it was written, in the app's words ("11:08 AM"). */
34
35
  time: ReactNode
36
+ /** When it was written, as a moment (ms since 1970): the time then says the exact date and time under the pointer. */
37
+ at?: number
35
38
  /** A link to it: the time is then the link, "Link to this", as a reply's is. */
36
39
  timeHref?: string
37
40
  /** The time's tooltip when it is a link, in the app's words: "Link to this" by default; Peek's "Link to this message". */
@@ -110,10 +113,37 @@ export interface ConversationCardProps extends ConversationEntryProps {
110
113
  onClick?: () => void
111
114
  }
112
115
 
113
- export type ReplyCardProps = ConversationEntryProps
116
+ export interface ReplyCardProps extends ConversationEntryProps {
117
+ /** Its id, on the card as `data-reply-id`: what a link to it shows (`showInConversation`), and what `Thread` watches to say it was seen. */
118
+ id?: string
119
+ }
120
+
121
+ /**
122
+ * When it was written: the app's words, and with its moment the exact date and time under the pointer (B10: as Peek's
123
+ * rows of another app's comments always said it, now on every comment and reply). A time that is a link says the exact
124
+ * time, then where the link goes.
125
+ */
126
+ function When({ time, at: given, timeHref, timeLabel = 'Link to this' }: Pick<ConversationEntryProps, 'time' | 'at' | 'timeHref' | 'timeLabel'>) {
127
+ const at = momentOf(given)
128
+ const exact = at === undefined ? undefined : exactTime(at)
129
+ const said = at === undefined ? time : <time dateTime={new Date(at).toISOString()}>{time}</time>
130
+ if (timeHref) {
131
+ return (
132
+ <WithTooltip label={exact ? `${exact} · ${timeLabel}` : timeLabel} wrapperClassName="shrink-0">
133
+ <MetaText className="contents">
134
+ <Link href={timeHref} variant="quiet" data-interactive>
135
+ {said}
136
+ </Link>
137
+ </MetaText>
138
+ </WithTooltip>
139
+ )
140
+ }
141
+ // Drawn as Peek's rows of another app's comments drew it: the tooltip's own box round the time, inside its words' look.
142
+ return <MetaText className="shrink-0">{exact ? <WithTooltip label={exact}>{said}</WithTooltip> : time}</MetaText>
143
+ }
114
144
 
115
145
  /** The face, the name, the time and "(edited)", with the new mark at the far right. `meta`: after "(edited)". */
116
- function Head({ author, time, timeHref, timeLabel = 'Link to this', edited, isNew, urgent, meta }: Pick<ConversationEntryProps, 'author' | 'time' | 'timeHref' | 'timeLabel' | 'edited' | 'isNew' | 'urgent'> & { meta?: ReactNode }) {
146
+ function Head({ author, time, at, timeHref, timeLabel, edited, isNew, urgent, meta }: Pick<ConversationEntryProps, 'author' | 'time' | 'at' | 'timeHref' | 'timeLabel' | 'edited' | 'isNew' | 'urgent'> & { meta?: ReactNode }) {
117
147
  return (
118
148
  <div className="flex w-full items-center gap-2">
119
149
  <div className="flex min-w-0 flex-1 items-center gap-2">
@@ -121,17 +151,7 @@ function Head({ author, time, timeHref, timeLabel = 'Link to this', edited, isNe
121
151
  <Avatar size={24} src={author.picture} alt={author.name} bot={author.bot} />
122
152
  </span>
123
153
  <span className="min-w-0 truncate text-body-2-strong text-text-primary">{author.name}</span>
124
- {timeHref ? (
125
- <WithTooltip label={timeLabel} wrapperClassName="shrink-0">
126
- <MetaText className="contents">
127
- <Link href={timeHref} variant="quiet" data-interactive>
128
- {time}
129
- </Link>
130
- </MetaText>
131
- </WithTooltip>
132
- ) : (
133
- <MetaText className="shrink-0">{time}</MetaText>
134
- )}
154
+ <When time={time} at={at} timeHref={timeHref} timeLabel={timeLabel} />
135
155
  <EditedMarker edited={edited} />
136
156
  {meta}
137
157
  </div>
@@ -214,23 +234,6 @@ function Editing({ author, children }: { author: ConversationPerson; children: R
214
234
  )
215
235
  }
216
236
 
217
- /**
218
- * A press on the card opens its thread, wherever it lands on the card, but for what acts by itself: a button, a
219
- * link, the strip, a field. A press in a picker or a menu the card opened lands here too, through React's tree, from
220
- * outside the card: that is not a press on it. (Before, the whole reactions row and the strip stopped every press,
221
- * so a press beside the reactions did nothing: Katerina, 31 October.)
222
- */
223
- function pressed(e: MouseEvent<HTMLDivElement>, press: () => void) {
224
- const target = e.target as HTMLElement
225
- if (!e.currentTarget.contains(target)) return
226
- // A double click picks a word and a drag picks words: neither is a press, or the thread would open and close under the reader.
227
- if (e.detail > 1) return
228
- const picked = typeof window === 'undefined' ? null : window.getSelection()
229
- if (picked && !picked.isCollapsed && picked.anchorNode && e.currentTarget.contains(picked.anchorNode)) return
230
- if (target.closest('button, a, input, textarea, [contenteditable="true"], [role="button"], [role="toolbar"], [data-interactive]')) return
231
- press()
232
- }
233
-
234
237
  /**
235
238
  * After its picker or its menu closes, a card keeps its strip only while it is still pointed at, or reached by the
236
239
  * keyboard. A pointer that left while they were open sent the card no leave, and the strip stayed (the review, 1 November).
@@ -316,20 +319,14 @@ export function ConversationCard(props: ConversationCardProps) {
316
319
  active={isEditing}
317
320
  attention={attentionOf(isNew || !!replies?.isNew, urgent, inThreadCard)}
318
321
  className={cn('relative', className)}
319
- onClick={press && !isEditing && !overlay ? (e) => pressed(e, press) : undefined}
320
- // A card that opens on a press is reached by the keyboard too: Tab stops on it, which shows its strip, and Enter or
321
- // Space opens it. Only the card's own focus: a key in a link, a button or a field inside it is theirs. Before, a
322
- // comment with nothing focusable in it (no replies, no link) could not be opened without a pointer.
322
+ // A press opens its thread, wherever it lands on the card but for what acts by itself (Card's `onPress`). Before,
323
+ // the whole reactions row and the strip stopped every press, so a press beside the reactions did nothing
324
+ // (Katerina, 31 October). Not while its menu or picker is open: a press there is theirs.
325
+ onPress={press && !isEditing && !overlay ? press : undefined}
326
+ // Tab stops on it, which shows its strip, and Enter or Space opens it — and it stays a Tab stop while its menu is
327
+ // open, so focus has somewhere to come back to. Before, a comment with nothing focusable in it (no replies, no
328
+ // link) could not be opened without a pointer.
323
329
  tabIndex={press && !isEditing ? 0 : undefined}
324
- onKeyDown={
325
- press && !isEditing && !overlay
326
- ? (e) => {
327
- if (e.target !== e.currentTarget || (e.key !== 'Enter' && e.key !== ' ')) return
328
- e.preventDefault()
329
- press()
330
- }
331
- : undefined
332
- }
333
330
  onMouseEnter={() => setHovered(true)}
334
331
  onMouseLeave={() => {
335
332
  if (picking || menuOpen) return
@@ -352,6 +349,7 @@ export function ConversationCard(props: ConversationCardProps) {
352
349
  <Head
353
350
  author={author}
354
351
  time={props.time}
352
+ at={props.at}
355
353
  timeHref={props.timeHref}
356
354
  timeLabel={props.timeLabel}
357
355
  edited={props.edited}
@@ -464,7 +462,7 @@ export function ConversationCard(props: ConversationCardProps) {
464
462
  * when it has one. Peek's, moved with the conversation.
465
463
  */
466
464
  export function ReplyCard(props: ReplyCardProps) {
467
- const { author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, onDelete, deleteNote, menu, menuAfter, menuLabel, editLabel, className, children } = props
465
+ const { id, author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, onDelete, deleteNote, menu, menuAfter, menuLabel, editLabel, className, children } = props
468
466
  const readOnly = props.readOnly ?? false
469
467
  const [hovered, setHovered] = useState(false)
470
468
  const [menuOpen, setMenuOpen] = useState(false)
@@ -476,6 +474,11 @@ export function ReplyCard(props: ReplyCardProps) {
476
474
  const showStrip = hovered && !isEditing && !readOnly && (offersMenu || !!reactions?.onToggle)
477
475
  const root = useRef<HTMLDivElement>(null)
478
476
  const settle = () => requestAnimationFrame(() => setHovered(stillHere(root.current)))
477
+ // In a Thread beside, a reply counts itself as it is first drawn: a new one takes the thread to its newest.
478
+ const drawn = useContext(repliesDrawn)
479
+ useLayoutEffect(() => {
480
+ if (drawn) drawn.added += 1
481
+ }, [drawn])
479
482
  return (
480
483
  <>
481
484
  <Card
@@ -488,7 +491,8 @@ export function ReplyCard(props: ReplyCardProps) {
488
491
  active={isEditing}
489
492
  // A reply is marked inside its thread card too.
490
493
  attention={attentionOf(isNew, urgent, false)}
491
- className={cn('relative', className)}
494
+ data-reply-id={id}
495
+ className={cn('relative', SHOWN_CLASSES, className)}
492
496
  onMouseEnter={() => setHovered(true)}
493
497
  onMouseLeave={() => {
494
498
  if (picking || menuOpen) return
@@ -504,7 +508,7 @@ export function ReplyCard(props: ReplyCardProps) {
504
508
  <Editing author={author}>{editor(() => setEditing(false))}</Editing>
505
509
  ) : (
506
510
  <div className="flex flex-col items-start px-2 pt-2">
507
- <Head author={author} time={props.time} timeHref={props.timeHref} timeLabel={props.timeLabel} edited={props.edited} isNew={isNew} urgent={urgent} />
511
+ <Head author={author} time={props.time} at={props.at} timeHref={props.timeHref} timeLabel={props.timeLabel} edited={props.edited} isNew={isNew} urgent={urgent} />
508
512
  {/* As on a comment: under the name, above the words. */}
509
513
  {about && <div className="w-full pl-8 pr-2 pt-0.5">{about}</div>}
510
514
  <Words>{children}</Words>
@@ -14,6 +14,9 @@ Where a conversation's cards sit: two columns, or one 384px column beside the pa
14
14
  - `threads="beside"`, two columns: the comments fill the page; an open thread stands beside them, 384px.
15
15
  - `threads="under"`, one column: the comments are the 384px column beside the page; a thread opens under its comment, and the two become one card.
16
16
  - With two columns, `header` puts the comments' own **PageHeader** over their column only, and the thread runs the page's full height beside it.
17
+ - With two columns, `aside` is what the 384px column holds while no thread is open: the page's own **Panel** beside its comments (an overview). A thread opened takes its place.
18
+
19
+ <Canvas of={Stories.TwoColumnsAside} />
17
20
  - With two columns, each comment's `day` names its stretch with a line that stays at the top while the stretch scrolls (Peek's day lines).
18
21
 
19
22
  <Canvas of={Stories.TwoColumnsDays} />
@@ -42,16 +45,37 @@ import { ConversationLayout } from '@estiva-app/ui'
42
45
  - Which layout is the app's: where a conversation sits is its own.
43
46
  - The right column is 384px in every app.
44
47
  - The app keeps `open`; the layout says when it changes, with `onOpenChange`. Give every comment a `thread`, a
45
- **Thread** with its box, even one with no replies yet: pressing it opens it to its box.
48
+ **Thread** with its box, even one with no replies yet: pressing it opens it to its box. An app that builds only the
49
+ open thread gives a function, `thread: () => threadOf(comment)`: it is called only while that one is open.
50
+ - Draw no column of your own for the thread or for the panel beside the comments: `aside`. The column catches what
51
+ throws in it, and says so in its place; the comments stay.
46
52
  - Write nothing on the cards for opening: no `onClick`, `selected`, `onReply`, or the replies row's `onOpen` and
47
53
  `open`. The layout gives each **ConversationCard** its place, and the card opens its thread from it. What a card is
48
54
  given still wins.
49
- - Two columns, an app that keeps its own place in the comments (where they were left, a "New" line, following what
50
- arrives) has their scrolling box with `bodyRef` and `onBodyScroll`. Each comment's `day` draws the app's day lines,
55
+ - Two columns, where the comments scroll is the layout's, the same in every app: they open at the newest; they
56
+ follow what arrives only while the reader is at the bottom (within 80px); the reader's own comment, sent from `box`,
57
+ brings them down to it as it is drawn, and a refusal leaves them where they are; and they hold still while cards and
58
+ pictures fill in. Give the conversation its name, `rememberAs` (its address), and going back to it lands where it was
59
+ left, in this tab. `useLeftAt(name)` says when the reader left it away from the newest, for your "New" line in
60
+ `before` over the first comment written since. Keep no place of your own: `bodyRef` and `onBodyScroll` only read the box.
61
+
62
+ <Canvas of={Stories.TwoColumnsLong} />
63
+
64
+ - Each comment's `day` draws the app's day lines,
51
65
  each staying at the top while its own day scrolls under it; `before` is a line just above one comment (a "New"
52
66
  line); `below` is under the comments (a **ReactionHorizon**); `top` stands at the top however few the comments are
53
67
  (an **ArchivedNotice**). Few comments sit on the box, as a chat does. `empty` may be the app's own **EmptyState**,
54
68
  or `null` for nothing.
69
+ - A comment is read by being seen: `useSeenOnScreen(key)` for the conversation, handed to `seen`, holds the ids of the
70
+ comments that have been on screen a moment (half of the card, or 120px of a taller one, for 1.5 seconds, in a tab
71
+ that is not hidden). Draw `isNew` from it; mark the conversation read from it. `key` `null` watches nothing, until you
72
+ have judged what is new. Never an observer of your own.
73
+
74
+ <Canvas of={Stories.TwoColumnsSeen} />
75
+
76
+ - A link to a comment shows it: `showInConversation(id, { comments: true })` scrolls it to the middle and flashes it
77
+ (the open thread's pinned comment first, when it is that one's); `false` when it is not drawn. Each comment carries
78
+ its `id` as `data-conversation-item`. See **Thread** for replies.
55
79
  - The box at the foot of a thread that opens takes the caret, at its end, without scrolling: the layout tells it with
56
80
  `caretOnOpen`, which **CommentBox** reads. Nothing to pass; a box outside a layout never takes it this way.
57
81
 
@@ -65,8 +89,10 @@ import { ConversationLayout } from '@estiva-app/ui'
65
89
  | Opens and closes in place: the comment is never redrawn and does not move, open or closed | a wrapper that changes when it opens | |
66
90
  | One column: resolved comments and comments on deleted blocks closed under their names at the end, opened for the thread open in them | the groups, their counts, opening one | |
67
91
  | Puts the caret in the box of a thread that opens, without scrolling | a focus call | |
92
+ | Two columns: opens at the newest, comes back to where it was left, follows only a reader at the bottom, goes down to the reader's own comment, holds still while cards load | a scroll policy, a place per conversation, a ResizeObserver | |
68
93
  | Placeholders while reading, and a line when there are none | a loading and an empty state | |
69
- | The right column at 384px, in every app | a width | |
94
+ | Says which comments have been on screen a moment, with `seen` | an IntersectionObserver and a timer per card | |
95
+ | The right column at 384px, in every app: the open thread, or the page's `aside` | a width, a column, its error boundary | |
70
96
 
71
97
  ## Props
72
98