@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
@@ -187,6 +187,41 @@ export const AppDrawnGroups: Story = {
187
187
  },
188
188
  }
189
189
 
190
+ /** A group the app draws, its rows read when it opens: pending while the read is out, and once it has taken `NAV_TREE_PENDING_MS` the skeleton. */
191
+ function ReadOnOpen({ title, ms }: { title: string; ms: number }) {
192
+ const [open, setOpen] = useState(false)
193
+ const [rows, setRows] = useState<'out' | 'reading' | 'in'>('out')
194
+ const toggle = (next: boolean) => {
195
+ setOpen(next)
196
+ if (!next || rows !== 'out') return
197
+ setRows('reading')
198
+ setTimeout(() => setRows('in'), ms)
199
+ }
200
+ return (
201
+ <NavTreeSection title={title} icon={folder} open={open} onOpenChange={toggle} pending={open && rows === 'reading'}>
202
+ <NavItem href="#" label="Item one" icon={placeholder} />
203
+ <NavItem href="#" label="Item two" icon={placeholder} />
204
+ </NavTreeSection>
205
+ )
206
+ }
207
+
208
+ /** Open each group: the first's rows take 0.8s, and it opens once with them; the second's take 5s, and after 2s it opens on the skeleton until they are in. Reload to read again. */
209
+ export const PendingThenLoading: Story = {
210
+ args: { groups: undefined },
211
+ render: function Render(args) {
212
+ return (
213
+ <div className="flex h-screen bg-bg-base">
214
+ <Sidebar>
215
+ <NavTree title={args.title}>
216
+ <ReadOnOpen title="A quick read" ms={800} />
217
+ <ReadOnOpen title="A slow read" ms={5000} />
218
+ </NavTree>
219
+ </Sidebar>
220
+ </div>
221
+ )
222
+ },
223
+ }
224
+
190
225
  /*
191
226
  Opening a row shows where it lives (Katerina, 30 October): its group and the
192
227
  rows above it open, the row is marked, and the column scrolls to it.
@@ -237,6 +272,30 @@ export const OpensOntoTheCurrentRow: Story = {
237
272
  },
238
273
  }
239
274
 
275
+ /** A link to a group — a folder's own: it opens, closed by hand too, and the column scrolls to it at once. Close it: it stays closed until a link leads to it again. Nothing is marked. */
276
+ export const OpensOntoAGroup: Story = {
277
+ args: { groups: SHUT_GROUPS, selected: undefined },
278
+ render: function Render(args) {
279
+ const [group, setGroup] = useState<string | undefined>(undefined)
280
+ // Each press is a new arrival, as a link followed again is.
281
+ const follow = (id: string) => {
282
+ setGroup(undefined)
283
+ setTimeout(() => setGroup(id))
284
+ }
285
+ return (
286
+ <div className="flex h-screen bg-bg-base">
287
+ <Sidebar>
288
+ <NavTree {...args} selectedGroup={group} />
289
+ </Sidebar>
290
+ <Page>
291
+ <Button variant="outlined" size="small" onClick={() => follow('s8')}>Follow a link to Group eight</Button>
292
+ <Button variant="outlined" size="small" onClick={() => follow('s2')}>Follow a link to Group two</Button>
293
+ </Page>
294
+ </div>
295
+ )
296
+ },
297
+ }
298
+
240
299
  /** A new tab, where nothing is open yet: each button starts the column again, every group shut, and opens onto its row. */
241
300
  export const InANewTab: Story = {
242
301
  args: { groups: SHUT_GROUPS, selected: undefined },
@@ -5,10 +5,10 @@
5
5
  * a click reaches onSelect with its node; loading and empty say so.
6
6
  */
7
7
  import { afterEach, describe, expect, it, vi } from 'vitest'
8
- import { cleanup, render, screen } from '@testing-library/react'
8
+ import { act, cleanup, render, screen } from '@testing-library/react'
9
9
  import userEvent from '@testing-library/user-event'
10
10
  import { MenuItem } from './Menu'
11
- import { NavTree, NavTreeSection, type NavTreeGroup } from './NavTree'
11
+ import { NAV_TREE_PENDING_MS, NavTree, NavTreeSection, type NavTreeGroup } from './NavTree'
12
12
 
13
13
  afterEach(cleanup)
14
14
 
@@ -242,3 +242,233 @@ describe('NavTree opens onto the current row (Katerina, 30 October)', () => {
242
242
  expect(hidden('Item a')).toBe(false)
243
243
  })
244
244
  })
245
+
246
+ /**
247
+ * A group opened while its rows are read waits shut, its arrow turned, and
248
+ * opens once with every row; a read still out after `NAV_TREE_PENDING_MS`
249
+ * opens it on the skeleton after all — a rate-limit retry can take seconds
250
+ * (Peek's Folders, OPT-11: its own timer, moved in, with its tests' cases).
251
+ */
252
+ describe('NavTreeSection pending, then loading', () => {
253
+ const skeleton = (container: HTMLElement) => container.querySelector('.animate-skeleton-in')
254
+ const heading = () => screen.getByRole('button', { name: 'Group a' })
255
+ const rows = <a href="#a">Item a</a>
256
+
257
+ it('a read still out after NAV_TREE_PENDING_MS opens on the skeleton', () => {
258
+ vi.useFakeTimers()
259
+ try {
260
+ const { container } = render(<NavTreeSection title="Group a" open pending>{rows}</NavTreeSection>)
261
+ expect(heading().getAttribute('aria-busy')).toBe('true')
262
+ act(() => vi.advanceTimersByTime(NAV_TREE_PENDING_MS))
263
+ expect(NAV_TREE_PENDING_MS).toBe(2000)
264
+ expect(heading().getAttribute('aria-expanded')).toBe('true')
265
+ expect(heading().getAttribute('aria-busy')).toBeNull()
266
+ expect(skeleton(container)).not.toBeNull()
267
+ expect(skeleton(container)!.closest('[hidden]')).toBeNull()
268
+ expect(screen.queryByText('Item a')).toBeNull()
269
+ } finally {
270
+ vi.useRealTimers()
271
+ }
272
+ })
273
+
274
+ it('a moment short of it, the group is still shut and busy, with no skeleton', () => {
275
+ vi.useFakeTimers()
276
+ try {
277
+ const { container } = render(<NavTreeSection title="Group a" open pending>{rows}</NavTreeSection>)
278
+ act(() => vi.advanceTimersByTime(NAV_TREE_PENDING_MS - 1))
279
+ expect(heading().getAttribute('aria-busy')).toBe('true')
280
+ expect(screen.getByText('Item a').closest('[hidden]')).not.toBeNull()
281
+ expect(skeleton(container)).toBeNull()
282
+ } finally {
283
+ vi.useRealTimers()
284
+ }
285
+ })
286
+
287
+ it('rows that land in time open it on the rows; pending again waits the whole time again', () => {
288
+ vi.useFakeTimers()
289
+ try {
290
+ const { container, rerender } = render(<NavTreeSection title="Group a" open pending>{rows}</NavTreeSection>)
291
+ act(() => vi.advanceTimersByTime(NAV_TREE_PENDING_MS / 2))
292
+ rerender(<NavTreeSection title="Group a" open>{rows}</NavTreeSection>)
293
+ expect(screen.getByText('Item a').closest('[hidden]')).toBeNull()
294
+ rerender(<NavTreeSection title="Group a" open pending>{rows}</NavTreeSection>)
295
+ act(() => vi.advanceTimersByTime(NAV_TREE_PENDING_MS - 1))
296
+ expect(heading().getAttribute('aria-busy')).toBe('true')
297
+ expect(skeleton(container)).toBeNull()
298
+ } finally {
299
+ vi.useRealTimers()
300
+ }
301
+ })
302
+
303
+ it('rows that land after the skeleton replace it', () => {
304
+ vi.useFakeTimers()
305
+ try {
306
+ const { container, rerender } = render(<NavTreeSection title="Group a" open pending>{rows}</NavTreeSection>)
307
+ act(() => vi.advanceTimersByTime(NAV_TREE_PENDING_MS))
308
+ rerender(<NavTreeSection title="Group a" open>{rows}</NavTreeSection>)
309
+ expect(skeleton(container)).toBeNull()
310
+ expect(screen.getByText('Item a').closest('[hidden]')).toBeNull()
311
+ } finally {
312
+ vi.useRealTimers()
313
+ }
314
+ })
315
+
316
+ it('a group whose rows are in opens at once, never busy', () => {
317
+ render(<NavTreeSection title="Group a" open>{rows}</NavTreeSection>)
318
+ expect(heading().getAttribute('aria-busy')).toBeNull()
319
+ expect(screen.getByText('Item a').closest('[hidden]')).toBeNull()
320
+ })
321
+ })
322
+
323
+ /**
324
+ * A link to a group — a folder's own link — lands on it open and in sight
325
+ * (Katerina, 5 October, Peek's Folders: a notification leading to a shut
326
+ * heading among 160 showed nothing at all). Once per arrival: closed again,
327
+ * it stays closed until a link leads to it again. Peek's own effect, moved in.
328
+ */
329
+ describe('NavTree opens onto the group a link led to', () => {
330
+ it('selectedGroup opens its shut group, once per arrival', async () => {
331
+ const { rerender } = render(<NavTree groups={SHUT} />)
332
+ expect(hidden('Item e')).toBe(true)
333
+ rerender(<NavTree groups={SHUT} selectedGroup="g2" />)
334
+ expect(hidden('Item e')).toBe(false)
335
+ await userEvent.click(screen.getByRole('button', { name: 'Group two' }))
336
+ rerender(<NavTree groups={SHUT} selectedGroup="g2" />)
337
+ expect(hidden('Item e')).toBe(true)
338
+ rerender(<NavTree groups={SHUT} />)
339
+ rerender(<NavTree groups={SHUT} selectedGroup="g2" />)
340
+ expect(hidden('Item e')).toBe(false)
341
+ })
342
+
343
+ it('a group this browser remembers closed opens for it, and is remembered open, as a click would', () => {
344
+ window.localStorage.setItem('test.tree.g2', 'closed')
345
+ render(<NavTree groups={SHUT} selectedGroup="g2" storageKey="test.tree" />)
346
+ expect(hidden('Item e')).toBe(false)
347
+ expect(window.localStorage.getItem('test.tree.g2')).toBe('open')
348
+ window.localStorage.removeItem('test.tree.g2')
349
+ })
350
+
351
+ it('a group a link led to that was open already is remembered open too, as a click would: it stays open when the reader goes on to a row in another group', () => {
352
+ try {
353
+ const OPEN_G2 = [SHUT[0], { ...SHUT[1], defaultOpen: true }]
354
+ const link = render(<NavTree groups={OPEN_G2} selectedGroup="g2" storageKey="test.linked" />)
355
+ expect(hidden('Item e')).toBe(false)
356
+ expect(window.localStorage.getItem('test.linked.g2')).toBe('open')
357
+ link.unmount()
358
+ render(<NavTree groups={SHUT} selected="a" storageKey="test.linked" />)
359
+ expect(hidden('Item e')).toBe(false)
360
+ } finally {
361
+ window.localStorage.removeItem('test.linked.g2')
362
+ }
363
+ })
364
+
365
+ it('a group the app draws and holds, open already, is told to open by the link, so the app remembers it as a click', () => {
366
+ const onOpenChange = vi.fn()
367
+ render(
368
+ <NavTree selectedGroup="mine">
369
+ <NavTreeSection id="mine" title="Mine" open onOpenChange={onOpenChange}>
370
+ <a href="#m">Item m</a>
371
+ </NavTreeSection>
372
+ <NavTreeSection id="other" title="Other" open onOpenChange={onOpenChange}>
373
+ <a href="#o">Item o</a>
374
+ </NavTreeSection>
375
+ </NavTree>,
376
+ )
377
+ expect(onOpenChange.mock.calls).toEqual([[true]])
378
+ })
379
+
380
+ it('a group open only because its current row is in it is not written down: it closes again once the row goes', () => {
381
+ try {
382
+ const first = render(<NavTree groups={SHUT} selected="e" storageKey="test.passing" />)
383
+ expect(hidden('Item e')).toBe(false)
384
+ expect(window.localStorage.getItem('test.passing.g2')).toBeNull()
385
+ first.unmount()
386
+ render(<NavTree groups={SHUT} selected="a" storageKey="test.passing" />)
387
+ expect(hidden('Item e')).toBe(true)
388
+ } finally {
389
+ window.localStorage.removeItem('test.passing.g2')
390
+ }
391
+ })
392
+
393
+ it('marks nothing, and opens no other group', () => {
394
+ render(<NavTree groups={SHUT} selectedGroup="g2" />)
395
+ expect(document.querySelector('[aria-current]')).toBeNull()
396
+ expect(hidden('Item a')).toBe(true)
397
+ })
398
+
399
+ describe('and scrolls the column to it', () => {
400
+ /** A 100px column scrolled to its top, and the group's heading 300px down it. */
401
+ function lay(column: HTMLElement, at: number) {
402
+ let top = 0
403
+ Object.defineProperty(column, 'scrollHeight', { configurable: true, get: () => 1000 })
404
+ Object.defineProperty(column, 'clientHeight', { configurable: true, get: () => 100 })
405
+ Object.defineProperty(column, 'scrollTop', { configurable: true, get: () => top, set: (next: number) => (top = next) })
406
+ const rect = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (this: HTMLElement) {
407
+ const box = (y: number, height: number) => ({ top: y, bottom: y + height, height, left: 0, right: 0, width: 0, x: 0, y, toJSON: () => ({}) }) as DOMRect
408
+ if (this === column) return box(0, 100)
409
+ if (this.dataset.navGroup === 'far') return box(at - top, 34)
410
+ return box(0, 32)
411
+ })
412
+ return { scrolled: () => top, restore: () => rect.mockRestore() }
413
+ }
414
+
415
+ function Column({ group }: { group?: string }) {
416
+ return (
417
+ <div data-testid="column" style={{ overflowY: 'auto' }}>
418
+ <NavTree selectedGroup={group}>
419
+ <NavTreeSection id="near" title="Near"><a href="#n">Item n</a></NavTreeSection>
420
+ <NavTreeSection id="far" title="Far" defaultOpen={false} openFor={group === 'far' ? 'far' : undefined}><a href="#f">Item f</a></NavTreeSection>
421
+ </NavTree>
422
+ </div>
423
+ )
424
+ }
425
+
426
+ it('brings the group a link led to into the column, at once', () => {
427
+ const { rerender } = render(<Column />)
428
+ const layout = lay(screen.getByTestId('column'), 300)
429
+ try {
430
+ rerender(<Column group="far" />)
431
+ // Its bottom edge at the column's: 300 + 34 − 100.
432
+ expect(layout.scrolled()).toBe(234)
433
+ expect(hidden('Item f')).toBe(false)
434
+ } finally {
435
+ layout.restore()
436
+ }
437
+ })
438
+
439
+ it('a group in sight stays put, and the column is not pulled back to it on a later draw', () => {
440
+ const { rerender } = render(<Column />)
441
+ const layout = lay(screen.getByTestId('column'), 40)
442
+ try {
443
+ rerender(<Column group="far" />)
444
+ expect(layout.scrolled()).toBe(0)
445
+ const column = screen.getByTestId('column')
446
+ column.scrollTop = 500
447
+ rerender(<Column group="far" />)
448
+ expect(layout.scrolled()).toBe(500)
449
+ } finally {
450
+ layout.restore()
451
+ }
452
+ })
453
+ })
454
+ })
455
+
456
+ /** The tree's three lines are the one `EmptyState scope="rows"` an app draws in place of its own rows: the same box, to the class. */
457
+ describe('NavTree says its lines as an app does', () => {
458
+ const box = (message: string) => `<div class="px-2 py-1"><p class="text-caption text-text-muted">${message}</p></div>`
459
+
460
+ it('a group’s message, a row’s childrenMessage and emptyMessage', () => {
461
+ const { container } = render(
462
+ <NavTree
463
+ groups={[
464
+ { id: 'a', title: 'Group a', nodes: [], message: 'Nothing in this yet.' },
465
+ { id: 'b', title: 'Group b', nodes: [{ id: 'x', label: 'Item x', href: '#x', hasChildren: true, childrenMessage: 'This could not be read.' }] },
466
+ ]}
467
+ />,
468
+ )
469
+ expect(container.innerHTML).toContain(box('Nothing in this yet.'))
470
+ expect(container.innerHTML).toContain(box('This could not be read.'))
471
+ cleanup()
472
+ expect(render(<NavTree groups={[]} emptyMessage="Nothing here yet." />).container.innerHTML).toContain(box('Nothing here yet.'))
473
+ })
474
+ })
package/src/NavTree.tsx CHANGED
@@ -1,5 +1,5 @@
1
- import { useEffect, useRef, type MouseEvent, type ReactNode } from 'react'
2
- import { CollapsibleSection } from './CollapsibleSection'
1
+ import { createContext, useContext, useEffect, useRef, useState, type MouseEvent, type ReactNode } from 'react'
2
+ import { CollapsibleSection, sectionLinked } from './CollapsibleSection'
3
3
  import { EmptyState } from './EmptyState'
4
4
  import { NavItem } from './NavItem'
5
5
  import { SectionHeader, type SectionAction } from './SectionHeader'
@@ -97,6 +97,16 @@ export interface NavTreeProps {
97
97
  * read, and marks nothing for it.
98
98
  */
99
99
  selectedParent?: string
100
+ /**
101
+ * The group a link led to — a folder's own link: each time it names a new
102
+ * group, the group opens, as `selected` opens a row's — closed by hand too,
103
+ * once — and is remembered open as a click would be, open already or not,
104
+ * so it stays open when the reader goes on to a row in another group; and
105
+ * the column scrolls to it at once. It marks nothing. A group the app draws
106
+ * itself is found by its `id`, and opened the same way: told through
107
+ * `onOpenChange` when the app holds it.
108
+ */
109
+ selectedGroup?: string
100
110
  /** A row was clicked. A router app prevents the default and navigates. */
101
111
  onSelect?: (node: NavTreeNode, event: MouseEvent<HTMLAnchorElement>) => void
102
112
  /** What to say when `groups` is empty. The words are the caller's; absent, nothing is said. */
@@ -111,6 +121,9 @@ export const NAV_TREE_INTENT_MS = 150
111
121
  /** How long the column waits to scroll to the current row: the rows above it slide open in 150ms. */
112
122
  export const NAV_TREE_REVEAL_MS = 200
113
123
 
124
+ /** How long a `pending` group waits shut for its rows before it opens on the skeleton (Peek's Folders, OPT-11: a cold read is ~0.9s). */
125
+ export const NAV_TREE_PENDING_MS = 2000
126
+
114
127
  function holds(nodes: NavTreeNode[] | null, id: string | undefined): boolean {
115
128
  return !!nodes && id !== undefined && nodes.some((node) => node.id === id || holds(node.children ?? null, id))
116
129
  }
@@ -149,6 +162,8 @@ function openingFor(groups: NavTreeGroup[], selected: string | undefined, select
149
162
  /**
150
163
  * Scroll the column the row is in, and only that box — never the page, nor a
151
164
  * drawer that is shut — so the row is in sight. A row in sight stays put.
165
+ * A group taller than the column keeps its top in sight, as the browser's
166
+ * `block: 'nearest'` does (a row is never that tall).
152
167
  */
153
168
  function scrollToRow(row: HTMLElement) {
154
169
  let box = row.parentElement
@@ -157,20 +172,25 @@ function scrollToRow(row: HTMLElement) {
157
172
  const at = row.getBoundingClientRect()
158
173
  const view = box.getBoundingClientRect()
159
174
  if (at.top < view.top) box.scrollTop -= view.top - at.top
160
- else if (at.bottom > view.bottom) box.scrollTop += at.bottom - view.bottom
175
+ else if (at.bottom > view.bottom) box.scrollTop += Math.min(at.bottom - view.bottom, at.top - view.top)
161
176
  }
162
177
 
163
- /** A line in the rows' place: level with the rows, which pad themselves (Katerina, 14 September). */
178
+ /** A line in the rows' place: level with the rows, which pad themselves (Katerina, 14 September) — `EmptyState`'s `rows`, as an app draws it under its own rows. */
164
179
  function Line({ message }: { message: string }) {
165
- return (
166
- <div className="px-2 py-1">
167
- <EmptyState scope="section" message={message} />
168
- </div>
169
- )
180
+ return <EmptyState scope="rows" message={message} />
170
181
  }
171
182
 
172
183
  type Drawn = Pick<NavTreeProps, 'selected' | 'onSelect'> & { opening: Opening | null }
173
184
 
185
+ /** Set by a NavTree round its groups, its own and the app's: the group a link led to (`selectedGroup`), found by its `id`. */
186
+ const groupLinked = createContext<string | undefined>(undefined)
187
+
188
+ /** The group `selectedGroup` names, drawn and shown: its box, or nothing yet. */
189
+ function groupBox(box: HTMLElement | null, id: string): HTMLElement | undefined {
190
+ const group = [...(box?.querySelectorAll<HTMLElement>('[data-nav-group]') ?? [])].find((one) => one.dataset.navGroup === id)
191
+ return group && group.getBoundingClientRect().height > 0 ? group : undefined
192
+ }
193
+
174
194
  function Row({ node, selected, onSelect, opening }: { node: NavTreeNode } & Drawn) {
175
195
  const under =
176
196
  node.childrenMessage !== undefined ? (
@@ -228,7 +248,7 @@ function Group({ group, selected, onSelect, opening, storageKey }: { group: NavT
228
248
 
229
249
  export interface NavTreeSectionProps {
230
250
  title: string
231
- /** Marks the group's box as `data-nav-group`, for tests and photo runs to find it. */
251
+ /** Marks the group's box as `data-nav-group`: the tree finds it by it for `selectedGroup` (opens it, remembers it open, scrolls to it), and tests and photo runs do. */
232
252
  id?: string
233
253
  /** Said in the rows' place, level with them. The caller's words. */
234
254
  message?: string
@@ -252,7 +272,8 @@ export interface NavTreeSectionProps {
252
272
  /**
253
273
  * Opened, and its rows are being read: the arrow turns and the group stays
254
274
  * shut until they are in, then opens once — `CollapsibleSection`'s. For a
255
- * read that is usually quick; a slow one is `loading`'s skeleton.
275
+ * read that is usually quick: one still out after `NAV_TREE_PENDING_MS`
276
+ * (2s) opens the group on `loading`'s skeleton after all, until they are in.
256
277
  */
257
278
  pending?: boolean
258
279
  /** Remember it open or closed in this browser, under this key. */
@@ -270,10 +291,21 @@ export interface NavTreeSectionProps {
270
291
  * `groups`; an app whose groups each read their own data draws them itself,
271
292
  * as `NavTree`'s children.
272
293
  */
273
- export function NavTreeSection({ id, title, message, loading = false, pending, trailing, actions, menu, icon, defaultOpen = true, open, onOpenChange, storageKey, openFor, onIntent, children }: NavTreeSectionProps) {
294
+ export function NavTreeSection({ id, title, message, loading = false, pending = false, trailing, actions, menu, icon, defaultOpen = true, open, onOpenChange, storageKey, openFor, onIntent, children }: NavTreeSectionProps) {
274
295
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
275
296
  useEffect(() => () => clearTimeout(timer.current), [])
297
+ // Pending for too long: a slow read, drawn as `loading` is (OPT-11). Each new wait starts the time again.
298
+ const [slow, setSlow] = useState(false)
299
+ if (!pending && slow) setSlow(false)
300
+ useEffect(() => {
301
+ if (!pending) return
302
+ const wait = setTimeout(() => setSlow(true), NAV_TREE_PENDING_MS)
303
+ return () => clearTimeout(wait)
304
+ }, [pending])
276
305
  const intent = onIntent
306
+ // The group a link led to: opened and remembered open, as a click would, even when it was open already.
307
+ const linkedTo = useContext(groupLinked)
308
+ const linked = id !== undefined && linkedTo === id ? id : undefined
277
309
  return (
278
310
  <div
279
311
  // 4px between groups, none above the first: a folded group's heading
@@ -290,25 +322,28 @@ export function NavTreeSection({ id, title, message, loading = false, pending, t
290
322
  onPointerLeave={intent ? () => clearTimeout(timer.current) : undefined}
291
323
  onFocus={intent}
292
324
  >
293
- <CollapsibleSection
294
- title={title}
295
- indent
296
- defaultOpen={defaultOpen}
297
- open={open}
298
- onOpenChange={onOpenChange}
299
- pending={pending}
300
- storageKey={storageKey}
301
- openFor={openFor}
302
- trailing={trailing}
303
- actions={actions}
304
- menu={menu}
305
- icon={icon}
306
- className="shrink-0"
307
- // 2px between rows, as a list column's and a menu's (Katerina, 5 October).
308
- contentClassName="gap-0.5"
309
- >
310
- {message !== undefined ? <Line message={message} /> : loading ? <SkeletonList rows={3} /> : children}
311
- </CollapsibleSection>
325
+ <sectionLinked.Provider value={linked}>
326
+ <CollapsibleSection
327
+ title={title}
328
+ indent
329
+ defaultOpen={defaultOpen}
330
+ open={open}
331
+ onOpenChange={onOpenChange}
332
+ pending={pending && !slow}
333
+ storageKey={storageKey}
334
+ openFor={openFor}
335
+ trailing={trailing}
336
+ actions={actions}
337
+ menu={menu}
338
+ icon={icon}
339
+ className="shrink-0"
340
+ // 2px between rows, as a list column's and a menu's (Katerina, 5 October).
341
+ contentClassName="gap-0.5"
342
+ >
343
+ {/* The link is this section's alone: nothing folding inside its rows takes it. */}
344
+ <sectionLinked.Provider value={undefined}>{message !== undefined ? <Line message={message} /> : loading || slow ? <SkeletonList rows={3} /> : children}</sectionLinked.Provider>
345
+ </CollapsibleSection>
346
+ </sectionLinked.Provider>
312
347
  </div>
313
348
  )
314
349
  }
@@ -329,7 +364,7 @@ export function NavTreeSection({ id, title, message, loading = false, pending, t
329
364
  * and the column scrolls to it. Groups the app draws itself take `openFor`
330
365
  * for that; the scroll is the tree's either way.
331
366
  */
332
- export function NavTree({ title, titleActions, groups, children, selected, selectedParent, onSelect, emptyMessage = '', storageKey }: NavTreeProps) {
367
+ export function NavTree({ title, titleActions, groups, children, selected, selectedParent, selectedGroup, onSelect, emptyMessage = '', storageKey }: NavTreeProps) {
333
368
  const opening = groups ? openingFor(groups, selected, selectedParent) : null
334
369
  // Once per current row, when it is drawn and shown: a later draw, or a read landing, does not pull the column back to it.
335
370
  const box = useRef<HTMLDivElement>(null)
@@ -348,20 +383,35 @@ export function NavTree({ title, titleActions, groups, children, selected, selec
348
383
  }, NAV_TREE_REVEAL_MS)
349
384
  })
350
385
  useEffect(() => () => clearTimeout(waiting.current), [])
386
+ // Once per arrival, as soon as the group is drawn: its heading does not move as it opens, so nothing is waited for.
387
+ const groupScrolled = useRef<string | undefined>(undefined)
388
+ useEffect(() => {
389
+ if (selectedGroup === undefined) {
390
+ groupScrolled.current = undefined
391
+ return
392
+ }
393
+ if (groupScrolled.current === selectedGroup) return
394
+ const group = groupBox(box.current, selectedGroup)
395
+ if (!group) return
396
+ groupScrolled.current = selectedGroup
397
+ scrollToRow(group)
398
+ })
351
399
  return (
352
400
  // `contents`: a box to find the current row in, that lays nothing out — the groups stay the column's own.
353
401
  <div ref={box} className="contents">
354
- {title && <SectionHeader title={title} look="quiet" showActions="always" actions={titleActions} className="mt-4 shrink-0" />}
355
- {groups === undefined ? (
356
- children
357
- ) : groups === null ? (
358
- <SkeletonList rows={5} />
359
- ) : groups.length === 0 ? (
360
- // No words, no line: an app that says nothing when it has no groups.
361
- emptyMessage ? <Line message={emptyMessage} /> : null
362
- ) : (
363
- groups.map((group) => <Group key={group.id} group={group} selected={selected} onSelect={onSelect} opening={opening} storageKey={storageKey} />)
364
- )}
402
+ <groupLinked.Provider value={selectedGroup}>
403
+ {title && <SectionHeader title={title} look="quiet" showActions="always" actions={titleActions} className="mt-4 shrink-0" />}
404
+ {groups === undefined ? (
405
+ children
406
+ ) : groups === null ? (
407
+ <SkeletonList rows={5} />
408
+ ) : groups.length === 0 ? (
409
+ // No words, no line: an app that says nothing when it has no groups.
410
+ emptyMessage ? <Line message={emptyMessage} /> : null
411
+ ) : (
412
+ groups.map((group) => <Group key={group.id} group={group} selected={selected} onSelect={onSelect} opening={opening} storageKey={storageKey} />)
413
+ )}
414
+ </groupLinked.Provider>
365
415
  </div>
366
416
  )
367
417
  }
@@ -30,10 +30,15 @@ import { Thread } from '@estiva-app/ui'
30
30
  ```
31
31
 
32
32
  - Give `time` its day: no day line stands above it here.
33
+ - `at`, its moment: the time says the exact date and time under the pointer, as a comment's does. In a **Thread**, `start.at`.
33
34
 
34
35
  ## What it owns
35
36
 
36
- Nothing. It only draws. Clicks and keys are yours.
37
+ | It does | So you never write | Refused when written by hand |
38
+ |---|---|---|
39
+ | Says the exact date and time under the pointer, from `at` | a tooltip round the time | |
40
+
41
+ Clicks and keys are yours.
37
42
 
38
43
  ## Props
39
44
 
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
- import { Column, ONE, WORDS } from './conversation.examples'
2
+ import { userEvent, within } from 'storybook/test'
3
+ import { AT, Column, ONE, WORDS } from './conversation.examples'
3
4
  import { PinnedComment } from './PinnedComment'
4
5
 
5
6
  /** The comment a thread answers, at the top of the replies column. */
@@ -17,5 +18,14 @@ type Story = StoryObj<typeof meta>
17
18
  /** Who, when, and its first line. */
18
19
  export const Pinned: Story = {}
19
20
 
21
+ /** With its moment, `at`: the time says the exact date and time under the pointer. The story points at it. */
22
+ export const ExactTime: Story = {
23
+ name: 'Exact time',
24
+ args: { at: AT },
25
+ play: async ({ canvasElement }) => {
26
+ await userEvent.hover(within(canvasElement).getByText('Today 11:08 AM'))
27
+ },
28
+ }
29
+
20
30
  /** It was deleted; its replies stay under it. */
21
31
  export const Deleted: Story = { args: { deleted: true } }
@@ -3,11 +3,15 @@ import { Avatar } from './Avatar'
3
3
  import { Card } from './Card'
4
4
  import type { ConversationPerson } from './ConversationCard'
5
5
  import { MetaText } from './MetaText'
6
+ import { exactTime, momentOf } from './threadCard'
7
+ import { WithTooltip } from './Tooltip'
6
8
 
7
9
  export interface PinnedCommentProps {
8
10
  author: ConversationPerson
9
11
  /** When it was written, in the app's words, with its day: no day line stands above it here. */
10
12
  time: ReactNode
13
+ /** When it was written, as a moment (ms since 1970): the time then says the exact date and time under the pointer, as a comment's does. */
14
+ at?: number
11
15
  /** Its words, cut to one line: plain words read best. */
12
16
  words: ReactNode
13
17
  /** It was deleted; its replies stay. */
@@ -18,7 +22,8 @@ export interface PinnedCommentProps {
18
22
  * The comment a thread answers, pinned at the top of the replies column: who, when, and its first line, on a raised
19
23
  * card. Peek's pinned message, moved with the conversation.
20
24
  */
21
- export function PinnedComment({ author, time, words, deleted = false }: PinnedCommentProps) {
25
+ export function PinnedComment({ author, time, at: given, words, deleted = false }: PinnedCommentProps) {
26
+ const at = momentOf(given)
22
27
  return (
23
28
  <Card fill="elevated" clip>
24
29
  {deleted ? (
@@ -28,7 +33,15 @@ export function PinnedComment({ author, time, words, deleted = false }: PinnedCo
28
33
  <div className="flex items-center gap-2">
29
34
  <Avatar size={24} src={author.picture} alt={author.name} bot={author.bot} />
30
35
  <span className="min-w-0 truncate text-body-2-strong text-text-primary">{author.name}</span>
31
- <MetaText className="shrink-0">{time}</MetaText>
36
+ <MetaText className="shrink-0">
37
+ {at === undefined ? (
38
+ time
39
+ ) : (
40
+ <WithTooltip label={exactTime(at)}>
41
+ <time dateTime={new Date(at).toISOString()}>{time}</time>
42
+ </WithTooltip>
43
+ )}
44
+ </MetaText>
32
45
  </div>
33
46
  <div className="pb-2 pl-8 pr-2 pt-1">
34
47
  <div className="truncate text-caption text-text-secondary">{words}</div>
@@ -12,6 +12,7 @@ The line that says reactions are read only so far back, and how many older comme
12
12
  ## When
13
13
 
14
14
  - Under a long conversation, when the app stopped reading reactions before the oldest comment.
15
+ - `keepRoom`, while only the newest comments are read and the whole read will need the line: its room is kept, unseen, so the comments do not move up when the rest lands.
15
16
 
16
17
  ## When not
17
18
 
@@ -26,6 +27,8 @@ import { ReactionHorizon } from '@estiva-app/ui'
26
27
  ```
27
28
 
28
29
  - `limit`, `omitted` and `cut` are the app's to count.
30
+ - `noun` is what the app calls what is said, in the plural: "messages" in Peek. "comments" by default.
31
+ - `keepRoom` is the app's to know: more is coming and it will be past `limit`. Nothing to draw a second, invisible line for.
29
32
 
30
33
  ## What it owns
31
34
 
@@ -25,3 +25,6 @@ export const Cut: Story = { args: { omitted: 0, cut: true } }
25
25
 
26
26
  /** Both. */
27
27
  export const Both: Story = { args: { cut: true } }
28
+
29
+ /** While older comments are still read: nothing to say yet, and the line's room kept, unseen, so nothing moves when the rest lands. */
30
+ export const KeepsRoom: Story = { name: 'Keeps its room', args: { omitted: 0, keepRoom: true } }