@estiva-app/ui 0.95.0 → 0.97.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 (205) hide show
  1. package/dist/AppShell.d.ts +25 -7
  2. package/dist/AppShell.d.ts.map +1 -1
  3. package/dist/ArchivedNotice.d.ts +28 -0
  4. package/dist/ArchivedNotice.d.ts.map +1 -0
  5. package/dist/Avatar.d.ts +6 -1
  6. package/dist/Avatar.d.ts.map +1 -1
  7. package/dist/AvatarGroup.d.ts +2 -0
  8. package/dist/AvatarGroup.d.ts.map +1 -1
  9. package/dist/Button.d.ts +4 -3
  10. package/dist/Button.d.ts.map +1 -1
  11. package/dist/Card.d.ts.map +1 -1
  12. package/dist/CommentBox.d.ts.map +1 -1
  13. package/dist/ComposerTriggers.d.ts +2 -0
  14. package/dist/ComposerTriggers.d.ts.map +1 -1
  15. package/dist/ConversationActions.d.ts +24 -0
  16. package/dist/ConversationActions.d.ts.map +1 -0
  17. package/dist/ConversationCard.d.ts +90 -0
  18. package/dist/ConversationCard.d.ts.map +1 -0
  19. package/dist/ConversationLayout.d.ts +50 -0
  20. package/dist/ConversationLayout.d.ts.map +1 -0
  21. package/dist/ConversationMenu.d.ts +24 -0
  22. package/dist/ConversationMenu.d.ts.map +1 -0
  23. package/dist/Divider.d.ts +23 -4
  24. package/dist/Divider.d.ts.map +1 -1
  25. package/dist/EditedMarker.d.ts +11 -0
  26. package/dist/EditedMarker.d.ts.map +1 -0
  27. package/dist/IconButton.d.ts +3 -3
  28. package/dist/IconButton.d.ts.map +1 -1
  29. package/dist/LinkParts.d.ts +4 -1
  30. package/dist/LinkParts.d.ts.map +1 -1
  31. package/dist/ListColumn.d.ts +3 -1
  32. package/dist/ListColumn.d.ts.map +1 -1
  33. package/dist/MembersDialog.d.ts +4 -0
  34. package/dist/MembersDialog.d.ts.map +1 -1
  35. package/dist/MetaText.d.ts +22 -0
  36. package/dist/MetaText.d.ts.map +1 -0
  37. package/dist/NavItem.d.ts.map +1 -1
  38. package/dist/PageHeader.d.ts +50 -0
  39. package/dist/PageHeader.d.ts.map +1 -0
  40. package/dist/Panel.d.ts +6 -0
  41. package/dist/Panel.d.ts.map +1 -1
  42. package/dist/Person.d.ts +3 -1
  43. package/dist/Person.d.ts.map +1 -1
  44. package/dist/PersonTrigger.d.ts +1 -1
  45. package/dist/PersonTrigger.d.ts.map +1 -1
  46. package/dist/PinnedComment.d.ts +17 -0
  47. package/dist/PinnedComment.d.ts.map +1 -0
  48. package/dist/QuotedLine.d.ts +16 -0
  49. package/dist/QuotedLine.d.ts.map +1 -0
  50. package/dist/ReactionHorizon.d.ts +14 -0
  51. package/dist/ReactionHorizon.d.ts.map +1 -0
  52. package/dist/RepliesRow.d.ts +27 -0
  53. package/dist/RepliesRow.d.ts.map +1 -0
  54. package/dist/ResolveDialog.d.ts +13 -0
  55. package/dist/ResolveDialog.d.ts.map +1 -0
  56. package/dist/Select.d.ts +1 -1
  57. package/dist/Select.d.ts.map +1 -1
  58. package/dist/Skeleton.d.ts +8 -4
  59. package/dist/Skeleton.d.ts.map +1 -1
  60. package/dist/Thread.d.ts +38 -0
  61. package/dist/Thread.d.ts.map +1 -0
  62. package/dist/TopBar.d.ts +3 -2
  63. package/dist/TopBar.d.ts.map +1 -1
  64. package/dist/UrgentMark.d.ts +6 -0
  65. package/dist/UrgentMark.d.ts.map +1 -0
  66. package/dist/commentBoxFrame.d.ts +3 -1
  67. package/dist/commentBoxFrame.d.ts.map +1 -1
  68. package/dist/conversation.examples.d.ts +52 -0
  69. package/dist/conversation.examples.d.ts.map +1 -0
  70. package/dist/editor.js +33 -25
  71. package/dist/editor.js.map +2 -2
  72. package/dist/eslint/index.js +2 -1
  73. package/dist/eslint/index.js.map +2 -2
  74. package/dist/eslint/no-native-title.d.ts +1 -1
  75. package/dist/eslint/no-native-title.d.ts.map +1 -1
  76. package/dist/eslint/no-restyled-part.d.ts.map +1 -1
  77. package/dist/index.d.ts +18 -2
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +1412 -448
  80. package/dist/index.js.map +4 -4
  81. package/dist/linked.d.ts +4 -0
  82. package/dist/linked.d.ts.map +1 -1
  83. package/dist/linkedFrom.d.ts +2 -0
  84. package/dist/linkedFrom.d.ts.map +1 -1
  85. package/dist/looks.d.ts +13 -1
  86. package/dist/looks.d.ts.map +1 -1
  87. package/dist/threadCard.d.ts +46 -0
  88. package/dist/threadCard.d.ts.map +1 -0
  89. package/package.json +1 -1
  90. package/registry.json +1889 -544
  91. package/src/AppShell.mdx +24 -10
  92. package/src/AppShell.stories.tsx +65 -31
  93. package/src/AppShell.test.tsx +92 -10
  94. package/src/AppShell.tsx +108 -18
  95. package/src/ArchivedNotice.mdx +46 -0
  96. package/src/ArchivedNotice.stories.tsx +52 -0
  97. package/src/ArchivedNotice.test.tsx +42 -0
  98. package/src/ArchivedNotice.tsx +71 -0
  99. package/src/Avatar.agent.test.tsx +63 -0
  100. package/src/Avatar.mdx +25 -0
  101. package/src/Avatar.stories.tsx +13 -0
  102. package/src/Avatar.tsx +51 -3
  103. package/src/AvatarGroup.tsx +3 -1
  104. package/src/Button.mdx +2 -2
  105. package/src/Button.tsx +8 -6
  106. package/src/Card.test.tsx +4 -4
  107. package/src/Card.tsx +6 -2
  108. package/src/CommentBox.test.tsx +2 -1
  109. package/src/CommentBox.tsx +14 -7
  110. package/src/ComposerTriggers.stories.tsx +2 -0
  111. package/src/ComposerTriggers.tsx +3 -1
  112. package/src/ConfirmDialog.stories.tsx +12 -0
  113. package/src/ConversationActions.mdx +47 -0
  114. package/src/ConversationActions.stories.tsx +39 -0
  115. package/src/ConversationActions.tsx +96 -0
  116. package/src/ConversationCard.mdx +72 -0
  117. package/src/ConversationCard.states.test.tsx +330 -0
  118. package/src/ConversationCard.stories.tsx +135 -0
  119. package/src/ConversationCard.test.tsx +159 -0
  120. package/src/ConversationCard.tsx +524 -0
  121. package/src/ConversationLayout.mdx +61 -0
  122. package/src/ConversationLayout.stories.tsx +161 -0
  123. package/src/ConversationLayout.test.tsx +240 -0
  124. package/src/ConversationLayout.tsx +233 -0
  125. package/src/ConversationMenu.mdx +47 -0
  126. package/src/ConversationMenu.stories.tsx +42 -0
  127. package/src/ConversationMenu.test.tsx +47 -0
  128. package/src/ConversationMenu.tsx +57 -0
  129. package/src/Divider.mdx +36 -1
  130. package/src/Divider.stories.tsx +57 -0
  131. package/src/Divider.test.tsx +24 -1
  132. package/src/Divider.tsx +49 -9
  133. package/src/EditedMarker.mdx +36 -0
  134. package/src/EditedMarker.stories.tsx +24 -0
  135. package/src/EditedMarker.tsx +20 -0
  136. package/src/IconButton.mdx +2 -1
  137. package/src/IconButton.tsx +8 -5
  138. package/src/LinkCard.tsx +3 -3
  139. package/src/LinkChip.tsx +1 -1
  140. package/src/LinkParts.mdx +4 -0
  141. package/src/LinkParts.stories.tsx +10 -0
  142. package/src/LinkParts.tsx +9 -5
  143. package/src/LinkRow.tsx +1 -1
  144. package/src/ListColumn.tsx +9 -3
  145. package/src/MembersDialog.stories.tsx +11 -0
  146. package/src/MembersDialog.tsx +7 -3
  147. package/src/MetaText.mdx +41 -0
  148. package/src/MetaText.stories.tsx +29 -0
  149. package/src/MetaText.tsx +38 -0
  150. package/src/NavItem.tsx +2 -11
  151. package/src/PageHeader.mdx +123 -0
  152. package/src/PageHeader.stories.tsx +174 -0
  153. package/src/PageHeader.test.tsx +99 -0
  154. package/src/PageHeader.tsx +105 -0
  155. package/src/Panel.mdx +12 -0
  156. package/src/Panel.stories.tsx +47 -5
  157. package/src/Panel.test.tsx +40 -0
  158. package/src/Panel.tsx +8 -2
  159. package/src/Person.tsx +4 -2
  160. package/src/PersonTrigger.tsx +3 -3
  161. package/src/PinnedComment.mdx +40 -0
  162. package/src/PinnedComment.stories.tsx +21 -0
  163. package/src/PinnedComment.tsx +40 -0
  164. package/src/QuotedLine.mdx +44 -0
  165. package/src/QuotedLine.stories.tsx +30 -0
  166. package/src/QuotedLine.test.tsx +34 -0
  167. package/src/QuotedLine.tsx +33 -0
  168. package/src/ReactionHorizon.mdx +36 -0
  169. package/src/ReactionHorizon.stories.tsx +27 -0
  170. package/src/ReactionHorizon.tsx +27 -0
  171. package/src/RepliesRow.mdx +45 -0
  172. package/src/RepliesRow.stories.tsx +33 -0
  173. package/src/RepliesRow.test.tsx +47 -0
  174. package/src/RepliesRow.tsx +86 -0
  175. package/src/ReplyCard.mdx +50 -0
  176. package/src/ReplyCard.stories.tsx +68 -0
  177. package/src/ResolveDialog.mdx +44 -0
  178. package/src/ResolveDialog.stories.tsx +23 -0
  179. package/src/ResolveDialog.test.tsx +53 -0
  180. package/src/ResolveDialog.tsx +58 -0
  181. package/src/Select.tsx +12 -2
  182. package/src/Skeleton.stories.tsx +4 -1
  183. package/src/Skeleton.tsx +33 -4
  184. package/src/Thread.mdx +53 -0
  185. package/src/Thread.stories.tsx +167 -0
  186. package/src/Thread.test.tsx +83 -0
  187. package/src/Thread.tsx +113 -0
  188. package/src/TopBar.mdx +8 -6
  189. package/src/TopBar.stories.tsx +4 -3
  190. package/src/TopBar.tsx +8 -3
  191. package/src/UrgentMark.mdx +37 -0
  192. package/src/UrgentMark.stories.tsx +27 -0
  193. package/src/UrgentMark.tsx +15 -0
  194. package/src/commentBoxFrame.tsx +8 -4
  195. package/src/conversation.examples.tsx +135 -0
  196. package/src/eslint/no-native-title.ts +1 -1
  197. package/src/eslint/no-restyled-part.ts +1 -0
  198. package/src/index.ts +19 -2
  199. package/src/linked.ts +4 -0
  200. package/src/linkedFrom.ts +5 -3
  201. package/src/looks.ts +18 -2
  202. package/src/registry/registry.test.ts +9 -7
  203. package/src/threadCard.ts +84 -0
  204. package/stories/Choosing.mdx +21 -1
  205. package/tokens.css +14 -10
@@ -0,0 +1,524 @@
1
+ import { useContext, useRef, useState, type MouseEvent, type ReactNode } from 'react'
2
+ import { IconArrowNarrowRight, IconCircleCheck, IconDotsVertical } from '@tabler/icons-react'
3
+ import { Avatar } from './Avatar'
4
+ import { Card } from './Card'
5
+ import { cn } from './cn'
6
+ import { ConfirmDialog } from './ConfirmDialog'
7
+ import { ConversationActions } from './ConversationActions'
8
+ import { ConversationMenu } from './ConversationMenu'
9
+ import { EditedMarker } from './EditedMarker'
10
+ import { FieldLine } from './Field'
11
+ import { Link } from './Link'
12
+ import { MetaText } from './MetaText'
13
+ import { ReactionRow, type ReactionRowProps } from './ReactionRow'
14
+ import { RepliesRow, type RepliesRowProps } from './RepliesRow'
15
+ import { ResolveDialog } from './ResolveDialog'
16
+ import { InConversationItem, InThreadCard, useFaceLine } from './threadCard'
17
+ import { ToolbarButton } from './Toolbar'
18
+ import { WithTooltip } from './Tooltip'
19
+ import { UnreadDot } from './UnreadDot'
20
+ import { UrgentMark } from './UrgentMark'
21
+
22
+ /** Who wrote it: a name, and a picture when there is one (else the face draws initials). */
23
+ export interface ConversationPerson {
24
+ name: string
25
+ picture?: string
26
+ /** An agent: its face is a robot, as Avatar's `bot`. */
27
+ bot?: boolean
28
+ }
29
+
30
+ /** What a comment and a reply share. */
31
+ export interface ConversationEntryProps {
32
+ author: ConversationPerson
33
+ /** When it was written, in the app's words ("11:08 AM"). */
34
+ time: ReactNode
35
+ /** A link to it: the time is then the link, "Link to this", as a reply's is. */
36
+ timeHref?: string
37
+ /** When it was last edited, in the app's words for the tooltip ("Edited 11:20 AM"): draws "(edited)". */
38
+ edited?: string
39
+ /** The words, as the app draws them: text, mentions, links, attached cards, quoted blocks. */
40
+ children: ReactNode
41
+ /** What it is about, a `QuotedLine` for a comment on a part of the page: under the name, above the words. */
42
+ about?: ReactNode
43
+ /** Pictures and files: `AttachmentCard`s, laid out under the words. */
44
+ files?: ReactNode
45
+ /** Its reactions: the kit's `ReactionRow`. With `onToggle`, the strip offers React too. */
46
+ reactions?: ReactionRowProps
47
+ /** Why the last reaction was refused, in plain words: said under the reactions. */
48
+ reactionRefused?: string
49
+ /** Not read yet: the dot, or the urgent mark with `urgent`, and the card's edge in the theme's colour. */
50
+ isNew?: boolean
51
+ urgent?: boolean
52
+ /** It is yours: the menu offers Edit (with `editor`) and Delete (with `onDelete`). */
53
+ own?: boolean
54
+ /** Nothing can be changed (an archived page): no strip, reactions only shown. */
55
+ readOnly?: boolean
56
+ /** The box it is edited in, the app's `CommentBox` edit form; call `done` when it saves or cancels. */
57
+ editor?: (done: () => void) => ReactNode
58
+ /** Being edited, when the app holds it (an edit that was refused opens again). Absent: the card holds it. */
59
+ editing?: boolean
60
+ onEditingChange?: (editing: boolean) => void
61
+ /** Delete, after the card has asked. */
62
+ onDelete?: () => Promise<boolean | void> | boolean | void
63
+ /** The app's sentence in the delete question, what deleting does there. Absent: "It is deleted for everyone." */
64
+ deleteNote?: ReactNode
65
+ /** The app's own rows in the ⋯ menu: `MenuItem`s. */
66
+ menu?: ReactNode
67
+ /** Placement only. */
68
+ className?: string
69
+ }
70
+
71
+ export interface ConversationCardProps extends ConversationEntryProps {
72
+ /** Deleted: "This comment was deleted.", and its replies stay. */
73
+ deleted?: boolean
74
+ /** Its thread: how many replied, their faces, the last time, and whether one is new. Opening it is `onReply` or `onClick`. */
75
+ replies?: Omit<RepliesRowProps, 'urgent'>
76
+ /** Reply: offered on the strip. */
77
+ onReply?: () => void
78
+ /**
79
+ * Resolved, by whom, with what note and when (`at`, in the app's words). Folded (Katerina, 1 November): "✓ Resolved"
80
+ * by the time, who and the note on hover; "Person two → the note · time" above the replies row. While its thread is
81
+ * closed, the words fold to their first line, without files or reactions; open, it is whole.
82
+ */
83
+ resolved?: { by: string; note?: string; at?: string }
84
+ /** Resolve, with the note written in the dialog the card opens. Offered on the strip and in the menu. */
85
+ onResolve?: (note: string) => Promise<boolean | void> | boolean | void
86
+ /** Why the last resolve was refused, in plain words: said under the note, while the dialog stays open (`onResolve` answered `false`). */
87
+ resolveRefused?: string
88
+ onReopen?: () => void
89
+ /** The one open beside its thread. */
90
+ selected?: boolean
91
+ /** A press on the card: its thread opens. */
92
+ onClick?: () => void
93
+ }
94
+
95
+ export type ReplyCardProps = ConversationEntryProps
96
+
97
+ /** The face, the name, the time and "(edited)", with the new mark at the far right. `meta`: after "(edited)". */
98
+ function Head({ author, time, timeHref, edited, isNew, urgent, meta }: Pick<ConversationEntryProps, 'author' | 'time' | 'timeHref' | 'edited' | 'isNew' | 'urgent'> & { meta?: ReactNode }) {
99
+ return (
100
+ <div className="flex w-full items-center gap-2">
101
+ <div className="flex min-w-0 flex-1 items-center gap-2">
102
+ <span data-face className="relative flex shrink-0">
103
+ <Avatar size={24} src={author.picture} alt={author.name} bot={author.bot} />
104
+ </span>
105
+ <span className="min-w-0 truncate text-body-2-strong text-text-primary">{author.name}</span>
106
+ {timeHref ? (
107
+ <WithTooltip label="Link to this" wrapperClassName="shrink-0">
108
+ <MetaText className="contents">
109
+ <Link href={timeHref} variant="quiet" data-interactive>
110
+ {time}
111
+ </Link>
112
+ </MetaText>
113
+ </WithTooltip>
114
+ ) : (
115
+ <MetaText className="shrink-0">{time}</MetaText>
116
+ )}
117
+ <EditedMarker edited={edited} />
118
+ {meta}
119
+ </div>
120
+ {isNew && (urgent ? <UrgentMark /> : <UnreadDot />)}
121
+ </div>
122
+ )
123
+ }
124
+
125
+ /** New or urgent: the card's edge in the theme's accent or warning outline. Inside a thread card, the outer card is the edge, and the dot alone says it. */
126
+ function attentionOf(fresh: boolean, urgent: boolean, inThreadCard: boolean) {
127
+ if (!fresh || inThreadCard) return undefined
128
+ return urgent ? ('warning' as const) : ('accent' as const)
129
+ }
130
+
131
+ /**
132
+ * Folded (Katerina, 1 November): who resolved it and the note, "Person two → Keeping the first one. · 12:30 PM", in the
133
+ * thread's own line (the dot in the faces' column). No "resolved": the check by the time says it.
134
+ */
135
+ function EndedLine({ by, note, at }: { by: string; note: string; at?: string }) {
136
+ return (
137
+ <div data-resolved="line" className="relative flex items-start py-1">
138
+ <span className="flex h-[17px] w-10 shrink-0 items-center justify-center">
139
+ {/* Above the face's line, which ends at its centre: the disc masks it. */}
140
+ <span data-dot className="relative z-10 flex size-2 items-center justify-center rounded-full bg-bg-surface">
141
+ <span className="size-1 rounded-full bg-success-default" />
142
+ </span>
143
+ </span>
144
+ <p className="min-w-0 text-h5 leading-snug">
145
+ {/* Who in the name's colour, the note in the words' (Katerina, 1 November). */}
146
+ <span className="whitespace-nowrap text-text-primary">{by}</span>
147
+ <IconArrowNarrowRight size={12} stroke={1.5} className="mx-1.5 -mt-px inline shrink-0 text-text-primary" />
148
+ <span className="text-text-secondary">{note}</span>
149
+ {at && <MetaText size="chip"> · {at}</MetaText>}
150
+ </p>
151
+ </div>
152
+ )
153
+ }
154
+
155
+ /** After the time: a green check and "Resolved"; who, when and the note on hover. */
156
+ function ResolvedCheck({ by, note, at }: { by: string; note?: string; at?: string }) {
157
+ const said = `Resolved by ${by}${at ? `, ${at}` : ''}${note ? `: ${note}` : ''}`
158
+ return (
159
+ <WithTooltip label={said} wrapperClassName="flex shrink-0">
160
+ <span className="flex items-center gap-1 text-caption text-success-default">
161
+ <IconCircleCheck size={14} stroke={1.5} />
162
+ Resolved
163
+ </span>
164
+ </WithTooltip>
165
+ )
166
+ }
167
+
168
+ /**
169
+ * Folded, the words' first line, whatever the app wraps them in (Peek's and Leaf's words come in a box of their own):
170
+ * the cards and pictures among them held back, at either level, then one line, cut with … where the text allows.
171
+ * Text blocks stay: paragraphs, lists, quotes, code.
172
+ */
173
+ const FOLDED_WORDS_CLASSES =
174
+ '[&>div]:line-clamp-1 [&>div]:max-h-[1lh] [&>div>*:not(p):not(ul):not(ol):not(blockquote):not(pre):not(div:only-child)]:hidden [&>div>div:only-child>*:not(p):not(ul):not(ol):not(blockquote):not(pre)]:hidden'
175
+
176
+ /** The words' own look: Peek's message body, 14px secondary, blocks 8px apart. `oneLine`: folded, the first line only. */
177
+ function Words({ children, oneLine = false }: { children: ReactNode; oneLine?: boolean }) {
178
+ return (
179
+ <div className={cn('relative w-full break-words pb-2 pl-8 pr-2 pt-1', oneLine && FOLDED_WORDS_CLASSES)}>
180
+ <div className="flex flex-col gap-2 text-body-2 text-text-secondary">{children}</div>
181
+ </div>
182
+ )
183
+ }
184
+
185
+ function Reactions({ reactions, refused, readOnly }: { reactions?: ReactionRowProps; refused?: string; readOnly: boolean }) {
186
+ if ((!reactions || reactions.reactions.length === 0) && !refused) return null
187
+ return (
188
+ <div className="relative flex w-full flex-col gap-1 pb-2 pl-8 pt-1">
189
+ {reactions && <ReactionRow {...reactions} onToggle={readOnly ? undefined : reactions.onToggle} />}
190
+ {refused && <FieldLine tone="error">Not reacted: {refused}.</FieldLine>}
191
+ </div>
192
+ )
193
+ }
194
+
195
+ /** Being edited: the face beside the app's box, which holds the words, the files and the cards. */
196
+ function Editing({ author, children }: { author: ConversationPerson; children: ReactNode }) {
197
+ return (
198
+ <div className="p-2">
199
+ <div className="flex items-start gap-2">
200
+ <Avatar size={24} src={author.picture} alt={author.name} bot={author.bot} className="mt-1 shrink-0" />
201
+ <div className="min-w-0 flex-1">{children}</div>
202
+ </div>
203
+ </div>
204
+ )
205
+ }
206
+
207
+ /**
208
+ * A press on the card opens its thread, wherever it lands on the card, but for what acts by itself: a button, a
209
+ * link, the strip, a field. A press in a picker or a menu the card opened lands here too, through React's tree, from
210
+ * outside the card: that is not a press on it. (Before, the whole reactions row and the strip stopped every press,
211
+ * so a press beside the reactions did nothing: Katerina, 31 October.)
212
+ */
213
+ function pressed(e: MouseEvent<HTMLDivElement>, press: () => void) {
214
+ const target = e.target as HTMLElement
215
+ if (!e.currentTarget.contains(target)) return
216
+ // 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.
217
+ if (e.detail > 1) return
218
+ const picked = typeof window === 'undefined' ? null : window.getSelection()
219
+ if (picked && !picked.isCollapsed && picked.anchorNode && e.currentTarget.contains(picked.anchorNode)) return
220
+ if (target.closest('button, a, input, textarea, [contenteditable="true"], [role="button"], [role="toolbar"], [data-interactive]')) return
221
+ press()
222
+ }
223
+
224
+ /**
225
+ * After its picker or its menu closes, a card keeps its strip only while it is still pointed at, or reached by the
226
+ * keyboard. A pointer that left while they were open sent the card no leave, and the strip stayed (the review, 1 November).
227
+ */
228
+ function stillHere(root: HTMLElement | null) {
229
+ if (!root) return false
230
+ try {
231
+ return root.matches(':hover') || root.querySelector(':focus-visible') !== null
232
+ } catch {
233
+ return root.matches(':hover')
234
+ }
235
+ }
236
+
237
+ /** The editing state, held by the card or by the app. */
238
+ function useEditing(editing: boolean | undefined, onEditingChange: ((editing: boolean) => void) | undefined) {
239
+ const [own, setOwn] = useState(false)
240
+ const now = editing ?? own
241
+ const set = (next: boolean) => {
242
+ if (editing === undefined) setOwn(next)
243
+ onEditingChange?.(next)
244
+ }
245
+ return [now, set] as const
246
+ }
247
+
248
+ /**
249
+ * One comment: who, when, the words, files, cards, reactions, and the way into its replies, with the strip on hover
250
+ * and the ⋯ menu. Resolved, it folds while its thread is closed and says who resolved it and the note.
251
+ * The same card in every app, each in its own colours (the record that makes one conversation). Peek's, moved.
252
+ */
253
+ export function ConversationCard(props: ConversationCardProps) {
254
+ const { author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, deleted = false, replies, onReply, resolved, onResolve, resolveRefused, onReopen, selected, onClick, onDelete, deleteNote, menu, className, children } = props
255
+ const readOnly = (props.readOnly ?? false) || deleted
256
+ const inThreadCard = useContext(InThreadCard)
257
+
258
+ // In a ConversationLayout: a press opens its thread (in one column, a second closes it), Reply opens it, its replies
259
+ // row says it is open, and beside it is marked. What the app passes wins.
260
+ const item = useContext(InConversationItem)
261
+ const [hovered, setHovered] = useState(false)
262
+ const [menuOpen, setMenuOpen] = useState(false)
263
+ const [picking, setPicking] = useState(false)
264
+ const [resolving, setResolving] = useState(false)
265
+ const [deleting, setDeleting] = useState(false)
266
+ const [editing, setEditing] = useEditing(props.editing, props.onEditingChange)
267
+ const isEditing = editing && !readOnly && !!editor
268
+ const overlay = menuOpen || picking || resolving || deleting
269
+ const resolves = resolved ? onReopen : onResolve
270
+ // Open under in one column, the face's line runs down to its thread, with replies or with only the box (Katerina, 1 November).
271
+ const lined = inThreadCard
272
+ // Resolved with a note: the face's line runs down to the resolved line's dot, closed too (Katerina, 1 November), one
273
+ // bar measured from the face to the dot. Open in a ConversationLayout, the layout draws the whole line, face to the
274
+ // thread's last reply, so the card draws no pieces of it; elsewhere (a card on its own) the pieces stay.
275
+ const toDot = !lined && !!resolved?.note && !isEditing
276
+ const root = useRef<HTMLDivElement>(null)
277
+ const dotLine = useFaceLine(root, toDot, true)
278
+ // Once its picker or menu has closed: the strip only if the card is still pointed at.
279
+ const settle = () => requestAnimationFrame(() => setHovered(stillHere(root.current)))
280
+ // The ⋯ menu only when it has a row to show: Resolve or Reopen, the app's rows, or Edit and Delete on your own.
281
+ const offersMenu = !!resolves || !!menu || (own && (!!editor || !!onDelete))
282
+ const showStrip = hovered && !isEditing && !readOnly
283
+ const react = reactions?.onToggle
284
+ // Read-only with no replies, there is nothing to open: no box to write in, no thread to read (Peek's way, Katerina, 1 November).
285
+ const press = onClick ?? (readOnly && !replies?.count ? undefined : item?.toggle)
286
+ const reply = onReply ?? item?.show
287
+ const marked = selected ?? (item && !item.under ? item.open : undefined)
288
+ const under = !!item?.under
289
+ // Closed: its thread is not open, under it or beside it (the layout's, or the app's own `selected`).
290
+ const closed = !inThreadCard && !marked
291
+ // Folded: resolved, its thread closed, the words' first line only (Katerina, 1 November).
292
+ const folded = !!resolved && closed
293
+ const repliesRow = replies && replies.count > 0 && (
294
+ <RepliesRow {...replies} onOpen={replies.onOpen ?? (under ? item?.toggle : undefined)} open={replies.open ?? (under && !!item?.open)} urgent={urgent} />
295
+ )
296
+ const aboutShown = !!about && !deleted
297
+ return (
298
+ <>
299
+ <Card
300
+ ref={root}
301
+ // No fill of its own at rest, in any theme: it sits on its column's colour and lights up on hover. Peek's and
302
+ // Leaf's columns are their surface, so nothing changes there; Ship's is its page base, where the surface fill
303
+ // showed as a box round every comment (Katerina, 1 November: no background in Ship).
304
+ fill="none"
305
+ // Read-only with nothing to open: nothing on hover.
306
+ hover={readOnly && !press ? 'none' : 'fill'}
307
+ quietUntilHover
308
+ hovered={hovered}
309
+ selected={marked}
310
+ active={isEditing}
311
+ attention={attentionOf(isNew || !!replies?.isNew, urgent, inThreadCard)}
312
+ className={cn('relative', className)}
313
+ onClick={press && !isEditing && !overlay ? (e) => pressed(e, press) : undefined}
314
+ onMouseEnter={() => setHovered(true)}
315
+ onMouseLeave={() => {
316
+ if (picking || menuOpen) return
317
+ setHovered(false)
318
+ }}
319
+ onFocus={() => setHovered(true)}
320
+ onBlur={(e) => {
321
+ if (picking || menuOpen || e.currentTarget.contains(e.relatedTarget as Node | null)) return
322
+ setHovered(false)
323
+ }}
324
+ >
325
+ {isEditing ? (
326
+ <Editing author={author}>{editor(() => setEditing(false))}</Editing>
327
+ ) : (
328
+ <div data-comment-body className="flex flex-col items-start px-2 pt-2">
329
+ {deleted ? (
330
+ <p className="w-full pb-2 pl-8 pr-2 text-caption italic text-text-muted">This comment was deleted.</p>
331
+ ) : (
332
+ <>
333
+ <Head
334
+ author={author}
335
+ time={props.time}
336
+ timeHref={props.timeHref}
337
+ edited={props.edited}
338
+ isNew={isNew}
339
+ urgent={urgent}
340
+ meta={resolved && <ResolvedCheck by={resolved.by} note={resolved.note} at={resolved.at} />}
341
+ />
342
+ {aboutShown && (
343
+ // Under the name, above the words (Katerina, 1 November).
344
+ <div className="relative w-full pl-8 pr-2 pt-0.5">{about}</div>
345
+ )}
346
+ <Words oneLine={folded}>
347
+ {children}
348
+ </Words>
349
+ </>
350
+ )}
351
+ {!deleted && files && !folded && (
352
+ <div className="relative flex w-full flex-wrap items-start gap-2 pb-2 pl-8 pr-2">{files}</div>
353
+ )}
354
+ {!folded && <Reactions reactions={reactions} refused={reactionRefused} readOnly={readOnly} />}
355
+ {resolved?.note && (
356
+ // Who resolved it and the note, above the way into the replies; the check by the time says "Resolved" (Katerina, 1 November).
357
+ <div className="relative w-full pb-1">
358
+ <div className="-ml-2 w-[calc(100%+8px)]">
359
+ <EndedLine by={resolved.by} note={resolved.note} at={resolved.at} />
360
+ </div>
361
+ </div>
362
+ )}
363
+ {repliesRow && <div className="relative w-full">{repliesRow}</div>}
364
+ </div>
365
+ )}
366
+ {dotLine && (
367
+ // One bar from the face to the dot, measured (useFaceLine): 2px, centred under the 24px face, 8px in.
368
+ // Its top and height come from the measure: where the face ends and the dot stands are not known ahead.
369
+ <span aria-hidden className="pointer-events-none absolute left-[19px] w-0.5 bg-border-default" style={{ top: dotLine.top, height: dotLine.height }} />
370
+ )}
371
+ {showStrip && (
372
+ <div className="absolute right-1 top-1 z-10">
373
+ <ConversationActions
374
+ options={reactions?.options}
375
+ onReact={react}
376
+ onPickerOpenChange={(open) => {
377
+ setPicking(open)
378
+ if (!open) settle()
379
+ }}
380
+ onReply={reply}
381
+ resolved={!!resolved}
382
+ onResolve={onResolve && (() => setResolving(true))}
383
+ onReopen={onReopen}
384
+ more={
385
+ offersMenu && (
386
+ <ConversationMenu
387
+ trigger={
388
+ <ToolbarButton tooltip="More actions" aria-label="More actions">
389
+ <IconDotsVertical size={16} stroke={1.5} />
390
+ </ToolbarButton>
391
+ }
392
+ open={menuOpen}
393
+ onOpenChange={(open) => {
394
+ setMenuOpen(open)
395
+ if (!open) settle()
396
+ }}
397
+ resolved={!!resolved}
398
+ onResolve={onResolve && (() => setResolving(true))}
399
+ onReopen={onReopen}
400
+ onEdit={own && editor ? () => setEditing(true) : undefined}
401
+ onDelete={own && onDelete ? () => setDeleting(true) : undefined}
402
+ >
403
+ {menu}
404
+ </ConversationMenu>
405
+ )
406
+ }
407
+ />
408
+ </div>
409
+ )}
410
+ </Card>
411
+ {deleting && onDelete && (
412
+ <ConfirmDialog title="Delete this comment?" confirmLabel="Delete comment" destructive onConfirm={onDelete} onClose={() => setDeleting(false)}>
413
+ <p>{deleteNote ?? 'It is deleted for everyone.'}</p>
414
+ {replies && replies.count > 0 && <p>Its {replies.count === 1 ? 'reply stays' : `${replies.count} replies stay`}.</p>}
415
+ </ConfirmDialog>
416
+ )}
417
+ {resolving && onResolve && (
418
+ <ResolveDialog
419
+ refused={resolveRefused}
420
+ onCancel={() => setResolving(false)}
421
+ onResolve={async (note) => {
422
+ const ok = await onResolve(note)
423
+ if (ok !== false) setResolving(false)
424
+ return ok
425
+ }}
426
+ />
427
+ )}
428
+ </>
429
+ )
430
+ }
431
+
432
+ /**
433
+ * One reply in a thread: the same pieces as a comment, without replies of its own or Resolve. Its time is its link
434
+ * when it has one. Peek's, moved with the conversation.
435
+ */
436
+ export function ReplyCard(props: ReplyCardProps) {
437
+ const { author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, onDelete, deleteNote, menu, className, children } = props
438
+ const readOnly = props.readOnly ?? false
439
+ const [hovered, setHovered] = useState(false)
440
+ const [menuOpen, setMenuOpen] = useState(false)
441
+ const [picking, setPicking] = useState(false)
442
+ const [deleting, setDeleting] = useState(false)
443
+ const [editing, setEditing] = useEditing(props.editing, props.onEditingChange)
444
+ const isEditing = editing && !readOnly && !!editor
445
+ const offersMenu = !!menu || (own && (!!editor || !!onDelete))
446
+ const showStrip = hovered && !isEditing && !readOnly && (offersMenu || !!reactions?.onToggle)
447
+ const root = useRef<HTMLDivElement>(null)
448
+ const settle = () => requestAnimationFrame(() => setHovered(stillHere(root.current)))
449
+ return (
450
+ <>
451
+ <Card
452
+ ref={root}
453
+ // As a comment: no fill of its own at rest (Katerina, 1 November).
454
+ fill="none"
455
+ hover={readOnly ? 'none' : 'fill'}
456
+ quietUntilHover
457
+ hovered={hovered}
458
+ active={isEditing}
459
+ // A reply is marked inside its thread card too.
460
+ attention={attentionOf(isNew, urgent, false)}
461
+ className={cn('relative', className)}
462
+ onMouseEnter={() => setHovered(true)}
463
+ onMouseLeave={() => {
464
+ if (picking || menuOpen) return
465
+ setHovered(false)
466
+ }}
467
+ onFocus={() => setHovered(true)}
468
+ onBlur={(e) => {
469
+ if (picking || menuOpen || e.currentTarget.contains(e.relatedTarget as Node | null)) return
470
+ setHovered(false)
471
+ }}
472
+ >
473
+ {isEditing ? (
474
+ <Editing author={author}>{editor(() => setEditing(false))}</Editing>
475
+ ) : (
476
+ <div className="flex flex-col items-start px-2 pt-2">
477
+ <Head author={author} time={props.time} timeHref={props.timeHref} edited={props.edited} isNew={isNew} urgent={urgent} />
478
+ {/* As on a comment: under the name, above the words. */}
479
+ {about && <div className="w-full pl-8 pr-2 pt-0.5">{about}</div>}
480
+ <Words>{children}</Words>
481
+ {files && <div className="flex w-full flex-wrap items-start gap-2 pb-2 pl-8 pr-2">{files}</div>}
482
+ <Reactions reactions={reactions} refused={reactionRefused} readOnly={readOnly} />
483
+ </div>
484
+ )}
485
+ {showStrip && (
486
+ <ConversationActions
487
+ className="absolute right-1 top-1 z-10"
488
+ options={reactions?.options}
489
+ onReact={reactions?.onToggle}
490
+ onPickerOpenChange={(open) => {
491
+ setPicking(open)
492
+ if (!open) settle()
493
+ }}
494
+ more={
495
+ offersMenu && (
496
+ <ConversationMenu
497
+ trigger={
498
+ <ToolbarButton tooltip="More actions" aria-label="More actions">
499
+ <IconDotsVertical size={16} stroke={1.5} />
500
+ </ToolbarButton>
501
+ }
502
+ open={menuOpen}
503
+ onOpenChange={(next) => {
504
+ setMenuOpen(next)
505
+ if (!next) settle()
506
+ }}
507
+ onEdit={own && editor ? () => setEditing(true) : undefined}
508
+ onDelete={own && onDelete ? () => setDeleting(true) : undefined}
509
+ >
510
+ {menu}
511
+ </ConversationMenu>
512
+ )
513
+ }
514
+ />
515
+ )}
516
+ </Card>
517
+ {deleting && onDelete && (
518
+ <ConfirmDialog title="Delete this reply?" confirmLabel="Delete reply" destructive onConfirm={onDelete} onClose={() => setDeleting(false)}>
519
+ <p>{deleteNote ?? 'It is deleted for everyone.'}</p>
520
+ </ConfirmDialog>
521
+ )}
522
+ </>
523
+ )
524
+ }
@@ -0,0 +1,61 @@
1
+ import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
+ import * as Stories from './ConversationLayout.stories'
3
+
4
+ <Meta of={Stories} />
5
+
6
+ # ConversationLayout
7
+
8
+ Where a conversation's cards sit: two columns, or one 384px column beside the page.
9
+
10
+ <Canvas of={Stories.TwoColumns} />
11
+
12
+ ## When
13
+
14
+ - `threads="beside"`, two columns: the comments fill the page; an open thread stands beside them, 384px.
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
+ - 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 one column, an item that is `resolved` waits closed under "Resolved" at the end, and one whose part was deleted (`gone`) under "On deleted blocks" before it, each with how many. A group opens by itself for the thread open in it. With two columns they stay in their place.
18
+
19
+ <Canvas of={Stories.OneColumn} />
20
+
21
+ <Canvas of={Stories.Apart} />
22
+
23
+ ## When not
24
+
25
+ - One thread on its own → **Thread**.
26
+ - A list of places → **ListColumn**.
27
+
28
+ ## How
29
+
30
+ ```tsx
31
+ import { ConversationLayout } from '@estiva-app/ui'
32
+
33
+ <ConversationLayout threads="under" items={items} open={openId} onOpenChange={setOpenId} box={commentBox} />
34
+ ```
35
+
36
+ - Which layout is the app's: where a conversation sits is its own.
37
+ - The right column is 384px in every app.
38
+ - The app keeps `open`; the layout says when it changes, with `onOpenChange`. Give every comment a `thread`, a
39
+ **Thread** with its box, even one with no replies yet: pressing it opens it to its box.
40
+ - Write nothing on the cards for opening: no `onClick`, `selected`, `onReply`, or the replies row's `onOpen` and
41
+ `open`. The layout gives each **ConversationCard** its place, and the card opens its thread from it. What a card is
42
+ given still wins.
43
+ - The box at the foot of a thread that opens takes the caret, at its end, without scrolling: the layout tells it with
44
+ `caretOnOpen`, which **CommentBox** reads. Nothing to pass; a box outside a layout never takes it this way.
45
+
46
+ ## What it owns
47
+
48
+ | It does | So you never write | Refused when written by hand |
49
+ |---|---|---|
50
+ | Opens the thread beside the comments, or under its comment | the column and where it goes | |
51
+ | A press anywhere on a card, its replies row or Reply opens its thread; in one column a second press closes it | an `onClick` on each card | |
52
+ | Marks the open comment: beside, its card selected; under, its replies row turned open | `selected`, the row's `open` | |
53
+ | Opens and closes in place: the comment is never redrawn and does not move, open or closed | a wrapper that changes when it opens | |
54
+ | 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 | |
55
+ | Puts the caret in the box of a thread that opens, without scrolling | a focus call | |
56
+ | Placeholders while reading, and a line when there are none | a loading and an empty state | |
57
+ | The right column at 384px, in every app | a width | |
58
+
59
+ ## Props
60
+
61
+ <Controls />