@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
@@ -0,0 +1,203 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * Move a file to another Folder, under another file, or both (FOL-45): Peek's
4
+ * MoveDialog, moved into the kit (C11, 2 November) with Peek's tests, and
5
+ * what Leaf's and Ship's moves need beside them. A Folder that could not be
6
+ * read is said as the section's empty line with its Try again (B8).
7
+ */
8
+ import { afterEach, describe, expect, it, vi } from 'vitest'
9
+ import { cleanup, render, screen, waitFor } from '@testing-library/react'
10
+ import userEvent from '@testing-library/user-event'
11
+ import { MoveDialog, type MoveDialogProps, type MovePlace } from './MoveDialog'
12
+
13
+ afterEach(cleanup)
14
+
15
+ const HQ = { id: 'hq', name: 'Estiva HQ' }
16
+ const STEER = { id: 'steer', name: 'Steer' }
17
+ const TOP: MovePlace = { id: '', path: [] }
18
+ const BRIEF: MovePlace = { id: '30840:a:brief', path: ['Brief'] }
19
+ const LIVE: MovePlace = { id: '30850:a:live', path: ['A live project'] }
20
+
21
+ const Fixture = (props: Partial<MoveDialogProps>) => (
22
+ <MoveDialog
23
+ title="Notes"
24
+ description="Everyone who can read it now still can."
25
+ from="hq"
26
+ folders={[HQ, STEER]}
27
+ places={[]}
28
+ placesIn={vi.fn(async () => [])}
29
+ onMove={vi.fn(async () => true)}
30
+ onClose={() => {}}
31
+ {...props}
32
+ />
33
+ )
34
+
35
+ const optionsOf = async (name: string) => {
36
+ await userEvent.click(screen.getByRole('combobox', { name }))
37
+ // The chosen option's check reads as a mark in jsdom; the label is the rest.
38
+ return (await screen.findAllByRole('option')).map((option) => option.textContent?.replace('✔️', ''))
39
+ }
40
+
41
+ const pick = async (name: string, option: string) => {
42
+ await userEvent.click(screen.getByRole('combobox', { name }))
43
+ await userEvent.click(await screen.findByRole('option', { name: option }))
44
+ }
45
+
46
+ describe('MoveDialog (FOL-45, Peek’s tests)', () => {
47
+ it('opens on the Folder the file is in, with only real moves there', async () => {
48
+ render(<Fixture places={[BRIEF]} />)
49
+ expect(await optionsOf('Put it under')).toEqual(['Brief'])
50
+ })
51
+
52
+ it('reads another Folder when it is picked, and moves to its top by default', async () => {
53
+ const placesIn = vi.fn(async () => [TOP, BRIEF])
54
+ const onMove = vi.fn(async () => true)
55
+ render(<Fixture startAtTop placesIn={placesIn} onMove={onMove} />)
56
+ await pick('Folder', 'Steer')
57
+ expect(placesIn).toHaveBeenCalledWith('steer')
58
+ expect(await optionsOf('Put it under')).toEqual(['The top of Steer', 'Brief'])
59
+ await userEvent.keyboard('{Escape}')
60
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
61
+ await waitFor(() => expect(onMove).toHaveBeenCalledWith({ folder: 'steer', parent: '' }))
62
+ })
63
+
64
+ it('asks a file that nests under nothing only for the Folder, never offers the one it is in, and waits for a pick', async () => {
65
+ const onMove = vi.fn(async () => true)
66
+ render(<Fixture places={undefined} placesIn={undefined} onMove={onMove} />)
67
+ expect(screen.queryByRole('combobox', { name: 'Put it under' })).toBeNull()
68
+ // Nothing preselected: a Move pressed straight away would be a move nobody chose.
69
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
70
+ expect(await optionsOf('Folder')).toEqual(['Steer'])
71
+ await userEvent.click(await screen.findByRole('option', { name: 'Steer' }))
72
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
73
+ await waitFor(() => expect(onMove).toHaveBeenCalledWith({ folder: 'steer' }))
74
+ })
75
+
76
+ it('never picks a parent for a file whose parent is one kind: Move waits until the person does', async () => {
77
+ const onMove = vi.fn(async () => true)
78
+ render(<Fixture placesIn={async () => [LIVE]} onMove={onMove} />)
79
+ await pick('Folder', 'Steer')
80
+ await screen.findByRole('combobox', { name: 'Put it under' })
81
+ await waitFor(() => expect(screen.getByRole('combobox', { name: 'Put it under' }).hasAttribute('data-disabled')).toBe(false))
82
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
83
+ await pick('Put it under', 'A live project')
84
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
85
+ await waitFor(() => expect(onMove).toHaveBeenCalledWith({ folder: 'steer', parent: LIVE.id }))
86
+ })
87
+
88
+ it('says so when the picked Folder has nowhere to put it, and does not move', async () => {
89
+ render(<Fixture placesIn={async () => []} />)
90
+ await pick('Folder', 'Steer')
91
+ expect(await screen.findByText('There is nowhere in Steer to put it.')).toBeTruthy()
92
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
93
+ })
94
+
95
+ it('says a Folder that could not be read, and reads it again on Try again', async () => {
96
+ const placesIn = vi.fn().mockRejectedValueOnce(new Error('down')).mockResolvedValueOnce([TOP])
97
+ render(<Fixture placesIn={placesIn} />)
98
+ await pick('Folder', 'Steer')
99
+ expect(await screen.findByText('Steer could not be read.')).toBeTruthy()
100
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
101
+ await userEvent.click(screen.getByRole('button', { name: 'Try again' }))
102
+ expect(await optionsOf('Put it under')).toEqual(['The top of Steer'])
103
+ })
104
+ })
105
+
106
+ describe('MoveDialog, the kit’s', () => {
107
+ it('says a Folder that could not be read as the empty line beside it does, with its Try again (B8)', async () => {
108
+ render(<Fixture placesIn={async () => Promise.reject(new Error('down'))} />)
109
+ await pick('Folder', 'Steer')
110
+ const line = await screen.findByText('Steer could not be read.')
111
+ const empty = screen.getByText((_, element) => element?.tagName === 'P' && element.textContent === 'Steer could not be read.')
112
+ expect(empty).toBe(line)
113
+ // The section's empty line: caption and muted, as "There is nowhere in … to put it." is.
114
+ expect(line.className.split(' ')).toEqual(expect.arrayContaining(['text-caption', 'text-text-muted']))
115
+ expect(line.nextElementSibling).toBe(screen.getByRole('button', { name: 'Try again' }))
116
+ })
117
+
118
+ it('reads two picks of one Folder once', async () => {
119
+ const placesIn = vi.fn(() => new Promise<MovePlace[]>(() => {}))
120
+ render(<Fixture placesIn={placesIn} />)
121
+ await pick('Folder', 'Steer')
122
+ await pick('Folder', 'Estiva HQ')
123
+ await pick('Folder', 'Steer')
124
+ expect(placesIn).toHaveBeenCalledTimes(1)
125
+ })
126
+
127
+ it('reads the Folder it opens on when its places were not handed in', async () => {
128
+ const placesIn = vi.fn(async () => [TOP])
129
+ render(<Fixture places={undefined} placesIn={placesIn} startAtTop />)
130
+ await waitFor(() => expect(placesIn).toHaveBeenCalledWith('hq'))
131
+ await waitFor(() => expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(false))
132
+ })
133
+
134
+ it('without startAtTop, chooses no place even when the top is first: Move waits (Leaf’s)', async () => {
135
+ render(<Fixture places={[TOP, BRIEF]} />)
136
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
137
+ expect(await optionsOf('Put it under')).toEqual(['The top of Estiva HQ', 'Brief'])
138
+ })
139
+
140
+ it('names the empty place with topLabel when the top is not a place: “under none of these”', async () => {
141
+ render(<Fixture places={[TOP, LIVE]} topLabel="None — under none of these" />)
142
+ expect(await optionsOf('Put it under')).toEqual(['None — under none of these', 'A live project'])
143
+ })
144
+
145
+ it('while the Folders are still read, says so in the list, and does not say there is nowhere to go (Leaf’s)', () => {
146
+ render(<Fixture folders={undefined} />)
147
+ expect(screen.queryByText('There is no other folder it can be moved to.')).toBeNull()
148
+ expect(screen.getByRole('combobox', { name: 'Folder' }).textContent).toContain('Reading…')
149
+ })
150
+
151
+ it('says there is no other Folder when none is offered', () => {
152
+ render(<Fixture folders={[HQ]} places={undefined} placesIn={undefined} />)
153
+ expect(screen.getByText('There is no other folder it can be moved to.')).toBeTruthy()
154
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
155
+ })
156
+
157
+ it('takes another app’s words, and opens on the Folder it is given (Ship’s Move to Folder)', async () => {
158
+ const onMove = vi.fn(async () => true)
159
+ render(
160
+ <Fixture
161
+ heading="Move to Folder"
162
+ folderLabel="Destination Folder"
163
+ description="Only the Folder it is listed in changes."
164
+ places={undefined}
165
+ placesIn={undefined}
166
+ startIn="steer"
167
+ onMove={onMove}
168
+ />,
169
+ )
170
+ expect(screen.getByRole('dialog', { name: 'Move to Folder' })).toBeTruthy()
171
+ expect(screen.getByText('Only the Folder it is listed in changes.')).toBeTruthy()
172
+ expect(screen.getByRole('combobox', { name: 'Destination Folder' }).textContent).toContain('Steer')
173
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
174
+ await waitFor(() => expect(onMove).toHaveBeenCalledWith({ folder: 'steer' }))
175
+ })
176
+
177
+ it('says no other Folder in the app’s words', () => {
178
+ render(<Fixture folders={[HQ]} placesIn={undefined} noFolder="There is no other Folder it can be moved to." />)
179
+ expect(screen.getByText('There is no other Folder it can be moved to.')).toBeTruthy()
180
+ })
181
+
182
+ it('stays open when the move is refused, and closes when it went through', async () => {
183
+ const onClose = vi.fn()
184
+ const { unmount } = render(<Fixture places={[BRIEF]} onMove={async () => false} onClose={onClose} />)
185
+ await pick('Put it under', 'Brief')
186
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
187
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Move' })).toBeTruthy())
188
+ expect(onClose).not.toHaveBeenCalled()
189
+ unmount()
190
+ render(<Fixture places={[BRIEF]} onClose={onClose} />)
191
+ await pick('Put it under', 'Brief')
192
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
193
+ await waitFor(() => expect(onClose).toHaveBeenCalledOnce())
194
+ })
195
+
196
+ it('says it is moving, and both buttons wait', async () => {
197
+ render(<Fixture places={[BRIEF]} onMove={() => new Promise<boolean>(() => {})} />)
198
+ await pick('Put it under', 'Brief')
199
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
200
+ expect((screen.getByRole('button', { name: 'Moving…' }) as HTMLButtonElement).disabled).toBe(true)
201
+ expect((screen.getByRole('button', { name: 'Cancel' }) as HTMLButtonElement).disabled).toBe(true)
202
+ })
203
+ })
@@ -0,0 +1,183 @@
1
+ import { useEffect, useRef, useState } from 'react'
2
+ import { EmptyState } from './EmptyState'
3
+ import { Field } from './Field'
4
+ import { FormDialog } from './FormDialog'
5
+ import { Select } from './Select'
6
+
7
+ const TOP = '__top__'
8
+
9
+ /** A Folder a file may be moved to. */
10
+ export interface MoveFolder {
11
+ id: string
12
+ name: string
13
+ }
14
+
15
+ /** One place a file may be put under, in the Folder the dialog is showing. */
16
+ export interface MovePlace {
17
+ /** What it goes under: that file's address; `''` for the top of the Folder (or, for a file whose parent is one kind, none). */
18
+ id: string
19
+ /** Its breadcrumb, outermost first, ending in its own title; empty for the top. */
20
+ path: readonly string[]
21
+ }
22
+
23
+ /** Where the person put it: the Folder, and, for a file that nests, what it goes under (`''` for the top). */
24
+ export interface MoveChoice {
25
+ folder: string
26
+ parent?: string
27
+ }
28
+
29
+ /**
30
+ * Move a file: to another Folder, under another file there, or both (FOL-45)
31
+ * — Peek's MoveDialog, moved into the kit (C11, 2 November), which Leaf's
32
+ * and Ship's moves copied. The Folder first, then what it goes under there:
33
+ * two `Select`s, the second read from the first when it is picked, never for
34
+ * every Folder up front. Nothing is chosen for the person but the top, and
35
+ * only when asked (`startAtTop`): a preselected destination is a move nobody
36
+ * chose.
37
+ *
38
+ * A file that nests under nothing (no `placesIn`) is asked only for the
39
+ * Folder, and the one it is in is not offered. A Folder that could not be
40
+ * read says so as the section's empty line does, with its Try again (B8).
41
+ */
42
+ export interface MoveDialogProps {
43
+ /** The file's name, said above the choice. */
44
+ title: string
45
+ /** The sentence under the name, in the app's words: "Everyone who can read it now still can." */
46
+ description: string
47
+ /** The Folder it is in now. */
48
+ from: string
49
+ /** The Folders it may go to. Undefined while they are still read: the list says "Reading…". */
50
+ folders: readonly MoveFolder[] | undefined
51
+ /** Where it may go in `from`, already read. Absent with `placesIn`, the Folder it opens on is read at once. */
52
+ places?: readonly MovePlace[]
53
+ /** Where it may go in another Folder, read when that Folder is picked; a rejection is said beside a Try again. Absent: it nests under nothing. */
54
+ placesIn?: (folder: string) => Promise<readonly MovePlace[]>
55
+ /** Choose the top for the person when a Folder offers it: where a file that may sit at any Folder's top lands. Off: Move waits for a pick. */
56
+ startAtTop?: boolean
57
+ /** What the place with an empty `id` says. "The top of" the Folder when absent; "None — under none of these" for a file whose parent is one kind. */
58
+ topLabel?: string
59
+ /** The Folder it opens on, when that is not the one it is in. */
60
+ startIn?: string
61
+ /** The dialog's heading. "Move" when absent. */
62
+ heading?: string
63
+ /** The Folder field's label. "Folder" when absent. */
64
+ folderLabel?: string
65
+ /** Said when no Folder is offered. "There is no other folder it can be moved to." when absent. */
66
+ noFolder?: string
67
+ /** Answer `false` to keep the dialog open (you have said why); anything else closes it. */
68
+ onMove: (choice: MoveChoice) => Promise<boolean | void> | boolean | void
69
+ onClose: () => void
70
+ }
71
+
72
+ export function MoveDialog({
73
+ title,
74
+ description,
75
+ from,
76
+ folders,
77
+ places,
78
+ placesIn,
79
+ startAtTop = false,
80
+ topLabel,
81
+ startIn,
82
+ heading = 'Move',
83
+ folderLabel = 'Folder',
84
+ noFolder = 'There is no other folder it can be moved to.',
85
+ onMove,
86
+ onClose,
87
+ }: MoveDialogProps) {
88
+ const nests = !!placesIn
89
+ // Moving a file that nests under nothing into the Folder it is in would do nothing, so that one is not offered.
90
+ const destinations = folders && (nests ? folders : folders.filter((folder) => folder.id !== from))
91
+ const offered = (id: string | undefined): id is string => !!id && !!destinations?.some((candidate) => candidate.id === id)
92
+ const [pickedFolder, setPickedFolder] = useState<string>()
93
+ // Until another is picked, the one it opens on — worked out, not set at open, so Folders read after it opened still land on it.
94
+ const folder = pickedFolder ?? [startIn, from].find(offered) ?? ''
95
+ const [read, setRead] = useState<Record<string, readonly MovePlace[] | 'reading' | 'failed'>>(() => (places ? { [from]: places } : {}))
96
+ const [picked, setPicked] = useState<string>()
97
+
98
+ // The Folders read or being read, known now rather than at the next render: two picks of one Folder before its read lands read it once.
99
+ const requested = useRef(new Set(places ? [from] : []))
100
+ const readPlaces = (id: string) => {
101
+ if (!placesIn || requested.current.has(id)) return
102
+ requested.current.add(id)
103
+ setRead((current) => ({ ...current, [id]: 'reading' }))
104
+ placesIn(id).then(
105
+ (found) => setRead((current) => ({ ...current, [id]: found })),
106
+ () => {
107
+ requested.current.delete(id)
108
+ setRead((current) => ({ ...current, [id]: 'failed' }))
109
+ },
110
+ )
111
+ }
112
+ const readNow = useRef(readPlaces)
113
+ readNow.current = readPlaces
114
+ // The Folder on show is read once, after render: a pick, or the one it opens on when its places were not handed in.
115
+ useEffect(() => {
116
+ if (folder) readNow.current(folder)
117
+ }, [folder])
118
+
119
+ const chooseFolder = (id: string) => {
120
+ setPickedFolder(id)
121
+ setPicked(undefined)
122
+ }
123
+
124
+ const folderName = destinations?.find((candidate) => candidate.id === folder)?.name ?? 'this folder'
125
+ const status = nests && folder ? read[folder] : undefined
126
+ const targets = Array.isArray(status) ? (status as readonly MovePlace[]) : []
127
+ const valueOf = (place: MovePlace) => place.id || TOP
128
+ const parent = picked ?? (startAtTop && targets[0] && !targets[0].id ? TOP : undefined)
129
+ const ready = !!folder && (!nests || !!parent)
130
+
131
+ return (
132
+ <FormDialog
133
+ title={heading}
134
+ submitLabel="Move"
135
+ busyLabel="Moving…"
136
+ ready={ready}
137
+ onSubmit={() => onMove(nests ? { folder, parent: parent === TOP ? '' : parent } : { folder })}
138
+ onClose={onClose}
139
+ >
140
+ {destinations?.length === 0 ? (
141
+ <EmptyState scope="section" message={noFolder} />
142
+ ) : (
143
+ <>
144
+ {/* The name and its sentence are one block, 8px apart; the form puts 24px between it and the fields. */}
145
+ <div className="flex flex-col gap-2">
146
+ <p className="text-body-2-strong text-text-primary">{title}</p>
147
+ <p className="text-body-2 text-text-secondary">{description}</p>
148
+ </div>
149
+ <Field label={folderLabel}>
150
+ <Select
151
+ value={folder}
152
+ onChange={chooseFolder}
153
+ options={(destinations ?? []).map((candidate) => ({ value: candidate.id, label: candidate.name }))}
154
+ placeholder={destinations ? 'Pick a folder' : 'Reading…'}
155
+ ariaLabel={folderLabel}
156
+ />
157
+ </Field>
158
+ {nests &&
159
+ folder &&
160
+ (status === 'failed' ? (
161
+ <EmptyState scope="section" message={`${folderName} could not be read.`} action={{ label: 'Try again', onClick: () => readPlaces(folder) }} />
162
+ ) : Array.isArray(status) && targets.length === 0 ? (
163
+ <EmptyState scope="section" message={`There is nowhere in ${folderName} to put it.`} />
164
+ ) : (
165
+ <Field label="Put it under">
166
+ <Select
167
+ value={parent ?? ''}
168
+ onChange={setPicked}
169
+ options={targets.map((place) => ({
170
+ value: valueOf(place),
171
+ label: place.id ? place.path.join(' › ') : (topLabel ?? `The top of ${folderName}`),
172
+ }))}
173
+ placeholder={Array.isArray(status) ? 'Pick where it goes' : 'Reading…'}
174
+ disabled={!Array.isArray(status)}
175
+ ariaLabel="Put it under"
176
+ />
177
+ </Field>
178
+ ))}
179
+ </>
180
+ )}
181
+ </FormDialog>
182
+ )
183
+ }
package/src/NavItem.mdx CHANGED
@@ -66,11 +66,21 @@ count — a muted mono number whose tooltip says what it counts.
66
66
 
67
67
  <Canvas of={NavItemStories.Unread} />
68
68
 
69
+ - A row the app opens its own way, with what it already knows — beside the
70
+ list, in place — is `onPlainClick`: it runs on a plain click only, and the
71
+ link is not followed. Ctrl, Cmd, Shift, Alt and the middle button are still
72
+ the link's, a new tab, so the row keeps a real `href`.
73
+
74
+ <Canvas of={NavItemStories.OpensInPlace} />
75
+
69
76
  ## When not
70
77
 
71
78
  - An icon rail's tile → **RailItem**.
72
79
  - Switching views inside a page → **Tabs**.
73
80
  - A row in a popover → **MenuItem**.
81
+ - A plain-click check written in the row's `onClick` (`event.button`,
82
+ `metaKey`, `ctrlKey`…) → `onPlainClick`; anywhere else a link's click is
83
+ handled by hand, `isPlainClick(event)` (**AppProvider**'s page).
74
84
 
75
85
  ## How
76
86
 
@@ -105,6 +115,10 @@ import { NavItem } from '@estiva-app/ui'
105
115
  and takes its 24px slot only while it shows.
106
116
  - `active` is `bg-nav-active`, the current row in a sidebar, which each theme
107
117
  sets for itself.
118
+ - `onPlainClick` runs after `onClick`, so a click `onClick` already handled
119
+ (`preventDefault`) is left alone. Under **AppProvider** it takes `navigate`'s
120
+ place for that row; another site's address, a `target` and a `download` stay
121
+ the browser's.
108
122
 
109
123
  - A row is 32px tall, 8px in on each side, 8px between the icon and the label,
110
124
  the label 14px regular (medium when unread), 8px corners as a **MenuItem**'s.
@@ -122,6 +136,7 @@ It does these by itself. Write none of them around it.
122
136
  | Tells assistive technology whether its rows are open | `aria-expanded`, `aria-controls` | |
123
137
  | Shows `hint` only while pointed at or focused, and makes the label give way | a positioned chip over the row, `group-hover` reveals | |
124
138
  | Draws the dot or the badge for `unread` and `urgent`, and brightens the row | an **UnreadDot** placed by hand, a weight or colour passed in | |
139
+ | Tells a plain click from one for a new tab, for `onPlainClick` | `event.button`, `event.metaKey`, `event.ctrlKey`… read by hand in an `onClick` | |
125
140
 
126
141
  ## Keys
127
142
 
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
2
  import { IconSquareRounded, IconX } from '@tabler/icons-react'
3
+ import { useState } from 'react'
3
4
  import { Chip } from './Chip'
4
5
  import { MenuItem } from './Menu'
5
6
  import { NavItem } from './NavItem'
@@ -136,3 +137,17 @@ export const WithActionAndHint: Story = {
136
137
  export const UnreadWithAction: Story = {
137
138
  args: { icon: placeholder, unread: true, action: REMOVE },
138
139
  }
140
+
141
+ /** `onPlainClick`: a plain click opens the row here, the app's own way, and the page does not change; Cmd-click or Ctrl-click is still the link's, a new tab. */
142
+ export const OpensInPlace: Story = {
143
+ render: function Render(args) {
144
+ const [opened, setOpened] = useState<string | null>(null)
145
+ return (
146
+ <>
147
+ <NavItem {...args} label="Item one" href="?opened=one" icon={placeholder} active={opened === 'Item one'} onPlainClick={() => setOpened('Item one')} />
148
+ <NavItem {...args} label="Item two" href="?opened=two" icon={placeholder} active={opened === 'Item two'} onPlainClick={() => setOpened('Item two')} />
149
+ <p className="px-2 pt-2 text-caption text-text-muted">{opened ? `Opened here: ${opened}` : 'Nothing opened here yet.'}</p>
150
+ </>
151
+ )
152
+ },
153
+ }
@@ -6,8 +6,9 @@
6
6
  * The reveal on hover and the slide are Chrome's to show.
7
7
  */
8
8
  import { afterEach, describe, expect, it, vi } from 'vitest'
9
- import { cleanup, render, screen, waitFor } from '@testing-library/react'
9
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
10
10
  import userEvent from '@testing-library/user-event'
11
+ import { AppProvider } from './AppProvider'
11
12
  import { NavItem } from './NavItem'
12
13
 
13
14
  afterEach(cleanup)
@@ -216,3 +217,65 @@ describe('NavItem with a tooltip', () => {
216
217
  expect((await screen.findByRole('tooltip')).textContent).toBe('Remove from list')
217
218
  })
218
219
  })
220
+
221
+ /**
222
+ * A row the app opens its own way, with what it knows, in place of following
223
+ * its link — Peek's Desk opens a file or a DM beside the list, its People page
224
+ * selects a person. Only a plain click: Ctrl, Cmd, Shift, Alt or the middle
225
+ * button is still the link's, a new tab. Peek wrote this check by hand on each
226
+ * row (`inPlace`, PersonItem); its tests' cases, moved in.
227
+ */
228
+ describe('NavItem onPlainClick', () => {
229
+ const link = () => screen.getByRole('link', { name: 'Item one' })
230
+
231
+ it('a plain click runs it in place of the link: the page does not go anywhere', () => {
232
+ const open = vi.fn()
233
+ render(<NavItem href="/app/desk?open=x" label="Item one" onPlainClick={open} />)
234
+ const followed = fireEvent.click(link())
235
+ expect(open).toHaveBeenCalledTimes(1)
236
+ expect(followed).toBe(false)
237
+ })
238
+
239
+ it('a click with Ctrl, Cmd, Shift or Alt, or the middle button, is the link’s: nothing runs here', () => {
240
+ const open = vi.fn()
241
+ render(<NavItem href="/app/desk?open=x" label="Item one" onPlainClick={open} />)
242
+ for (const keys of [{ ctrlKey: true }, { metaKey: true }, { shiftKey: true }, { altKey: true }, { button: 1 }]) {
243
+ expect(fireEvent.click(link(), keys)).toBe(true)
244
+ }
245
+ expect(open).not.toHaveBeenCalled()
246
+ })
247
+
248
+ it('under AppProvider’s navigate it takes navigate’s place: the app stays on its page', () => {
249
+ const open = vi.fn()
250
+ const navigate = vi.fn()
251
+ render(
252
+ <AppProvider navigate={navigate}>
253
+ <NavItem href="/app/people/dm-1" label="Item one" onPlainClick={open} />
254
+ </AppProvider>,
255
+ )
256
+ fireEvent.click(link())
257
+ expect(open).toHaveBeenCalledTimes(1)
258
+ expect(navigate).not.toHaveBeenCalled()
259
+ fireEvent.click(link(), { metaKey: true })
260
+ expect(open).toHaveBeenCalledTimes(1)
261
+ expect(navigate).not.toHaveBeenCalled()
262
+ })
263
+
264
+ it('the row’s own onClick runs first, and a click it handled is left alone', () => {
265
+ const open = vi.fn()
266
+ render(<NavItem href="/app/desk" label="Item one" onClick={(event) => event.preventDefault()} onPlainClick={open} />)
267
+ fireEvent.click(link())
268
+ expect(open).not.toHaveBeenCalled()
269
+ })
270
+
271
+ it('another site’s address, a link that opens elsewhere, or one that downloads is not opened here', () => {
272
+ const open = vi.fn()
273
+ const { rerender } = render(<NavItem href="https://elsewhere.test/file" label="Item one" onPlainClick={open} />)
274
+ expect(fireEvent.click(link())).toBe(true)
275
+ rerender(<NavItem href="/app/desk" target="_blank" label="Item one" onPlainClick={open} />)
276
+ expect(fireEvent.click(link())).toBe(true)
277
+ rerender(<NavItem href="/app/file.pdf" download label="Item one" onPlainClick={open} />)
278
+ expect(fireEvent.click(link())).toBe(true)
279
+ expect(open).not.toHaveBeenCalled()
280
+ })
281
+ })
package/src/NavItem.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useId, useState, type ComponentPropsWithoutRef, type ReactNode } from 'react'
1
+ import { useId, useState, type ComponentPropsWithoutRef, type MouseEvent, type ReactNode } from 'react'
2
2
  import { Collapsible } from '@base-ui/react/collapsible'
3
3
  import { IconChevronRight, IconDotsVertical } from '@tabler/icons-react'
4
4
  import { UrgentMark } from './UrgentMark'
@@ -93,6 +93,13 @@ export interface NavItemProps extends Omit<ComponentPropsWithoutRef<'a'>, 'href'
93
93
  * hand, it stays closed until another opens. `NavTree` passes it.
94
94
  */
95
95
  openFor?: string
96
+ /**
97
+ * A plain click on the row — the main button, no Ctrl, Cmd, Shift or Alt, to
98
+ * this app's own address: the app opens it its own way, with what it knows,
99
+ * in place of following the link (the row prevents it, and `navigate` is not
100
+ * called). Any other click is still the link's: a new tab. After `onClick`.
101
+ */
102
+ onPlainClick?: (event: MouseEvent<HTMLAnchorElement>) => void
96
103
  className?: string
97
104
  }
98
105
 
@@ -115,11 +122,12 @@ export function NavItem({
115
122
  open: openProp,
116
123
  onOpenChange,
117
124
  openFor,
125
+ onPlainClick,
118
126
  className,
119
127
  onClick,
120
128
  ...props
121
129
  }: NavItemProps) {
122
- const inApp = useInAppClick(href, onClick)
130
+ const inApp = useInAppClick(href, onClick, onPlainClick)
123
131
  const [openState, setOpenState] = useState(defaultOpen)
124
132
  const panelId = useId()
125
133
  const hasRows = children != null && children !== false
package/src/NavTree.mdx CHANGED
@@ -29,9 +29,18 @@ rows to any depth.
29
29
 
30
30
  - In a new tab, where nothing is open yet, the same: the row is in sight
31
31
  when the tree is drawn.
32
+ - `selectedGroup` is the group a link led to — a folder's own link: each
33
+ time it names a new group, the group opens, closed by hand too, and the
34
+ column scrolls to it at once. Once per arrival, and it marks nothing. It is
35
+ remembered open as a click would be, open already or not, so it stays open
36
+ when the reader goes on to a row in another group. A group open only
37
+ because the current row is in it is never written down: it closes again
38
+ once the row goes.
32
39
 
33
40
  <Canvas of={NavTreeStories.InANewTab} />
34
41
 
42
+ <Canvas of={NavTreeStories.OpensOntoAGroup} />
43
+
35
44
  - `selectedParent` is the row the current one sits under, while the tree
36
45
  does not draw the current one. Its rows are read only when it opens: the
37
46
  tree opens onto it and opens it, and marks the current row once it is in.
@@ -80,11 +89,16 @@ rows to any depth.
80
89
  pointer rests on it or the keyboard reached it: read it then, so opening
81
90
  it draws rows. A `NavTreeSection` opened while its read is in flight takes
82
91
  `pending`: its arrow turns and it opens once the rows are in, in one move,
83
- instead of a skeleton the rows then replace; keep `loading` for a read
84
- that turns out slow.
92
+ instead of a skeleton the rows then replace. A read still out after 2
93
+ seconds (`NAV_TREE_PENDING_MS`) is a slow one: the group opens on
94
+ `loading`'s skeleton by itself, until the rows are in — no timer of the
95
+ app's own. Keep `loading` for a group whose rows are being read while it
96
+ is already open.
85
97
 
86
98
  <Canvas of={NavTreeStories.ReadAsItOpens} />
87
99
 
100
+ <Canvas of={NavTreeStories.PendingThenLoading} />
101
+
88
102
  - An app whose groups and rows each read their own data draws the groups
89
103
  itself: leave out `groups` and pass **NavTreeSection**s as children, each
90
104
  with **NavItem** rows. A `NavTreeSection` is one group exactly as `groups`
@@ -125,10 +139,16 @@ import { NavTree, Sidebar } from '@estiva-app/ui'
125
139
  - `storageKey` remembers each group open or closed in this browser, under
126
140
  the key and the group's id — a group opened for the current row is
127
141
  remembered open, as a click would be. The rows under a row are not
128
- remembered yet.
142
+ remembered yet. Groups and rows the app draws itself, whose rows are read
143
+ only once open, take `useRememberedOpen` on their `open` and
144
+ `onOpenChange`: the same memory, known before anything is read
145
+ (**CollapsibleSection**'s page).
129
146
  - Groups the app draws itself open for the current row through `openFor` on
130
147
  each **NavTreeSection** and **NavItem** that holds it; the scroll is the
131
- tree's either way, given `selected`.
148
+ tree's either way, given `selected`. A group a link led to needs nothing
149
+ more than its **NavTreeSection**'s `id`: given `selectedGroup`, the tree
150
+ opens it, remembers it open (through `onOpenChange` when you hold it) and
151
+ scrolls to it.
132
152
  - The words in `emptyMessage` are the caller's.
133
153
 
134
154
  ## What it owns
@@ -139,8 +159,10 @@ It does these by itself. Write none of them around it.
139
159
  |---|---|---|
140
160
  | Draws every level from one list, rows under rows | a recursive render of **NavItem**s and **CollapsibleSection**s | |
141
161
  | Opens the group and the rows above the current row, once per row, and scrolls to it | a search through the list for the current row, an effect that opens it, a scroll into view | |
162
+ | Opens the group a link led to, once per arrival, and scrolls to it | an effect that opens it, a `querySelector` and a scroll into view | |
142
163
  | Says it is loading, or empty, in the rows' place | a skeleton or an **EmptyState** placed by hand | |
143
164
  | Says when the pointer rests on a group, 150ms, and not while it sweeps past | a timer on pointer enter and leave | |
165
+ | Holds a `pending` group shut for 2s, then opens it on the skeleton | a timer from pending to loading, a skeleton of the app's own, a pulsing icon | |
144
166
 
145
167
  ## Keys
146
168