@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
@@ -65,6 +65,10 @@ function Root({ children }) {
65
65
  another scheme (`folder:`, `mailto:`).
66
66
  - A link's own `onClick` runs first, so an app that still passes its router
67
67
  click per link keeps working while it moves over.
68
+ - A row the app opens its own way is **NavItem**'s `onPlainClick`. Where an app
69
+ still handles a link's click itself — one delegated to a box of links —
70
+ `isPlainClick(event)` is the same test every part makes: the main button,
71
+ with no Ctrl, Cmd, Shift or Alt. Never write it out.
68
72
  - `active` is still the caller's: say which row is the current page where you
69
73
  place it.
70
74
 
@@ -7,9 +7,9 @@
7
7
  */
8
8
  import { type ReactNode } from 'react'
9
9
  import { afterEach, describe, expect, it, vi } from 'vitest'
10
- import { cleanup, render, screen } from '@testing-library/react'
10
+ import { cleanup, fireEvent, render, screen } from '@testing-library/react'
11
11
  import userEvent from '@testing-library/user-event'
12
- import { AppProvider } from './AppProvider'
12
+ import { AppProvider, isPlainClick } from './AppProvider'
13
13
  import { Avatar } from './Avatar'
14
14
  import { Chip } from './Chip'
15
15
  import { IconButton } from './IconButton'
@@ -171,3 +171,35 @@ describe('changing page', () => {
171
171
  })
172
172
 
173
173
  })
174
+
175
+ /**
176
+ * The check every link part makes before it keeps a click inside the app, for
177
+ * an app that handles a link's click itself: Peek wrote it by hand four times
178
+ * (its Desk, its People rows, its message links and its mention chips).
179
+ */
180
+ describe('isPlainClick', () => {
181
+ const click = (init: MouseEventInit = {}) => new MouseEvent('click', { button: 0, ...init })
182
+
183
+ it('is the main button with no Ctrl, Cmd, Shift or Alt', () => {
184
+ expect(isPlainClick(click())).toBe(true)
185
+ })
186
+
187
+ it.each([
188
+ ['Ctrl', { ctrlKey: true }],
189
+ ['Cmd', { metaKey: true }],
190
+ ['Shift', { shiftKey: true }],
191
+ ['Alt', { altKey: true }],
192
+ ['the middle button', { button: 1 }],
193
+ ['the second button', { button: 2 }],
194
+ ])('a click with %s is not plain: the browser’s, a new tab or a window', (_name, init) => {
195
+ expect(isPlainClick(click(init))).toBe(false)
196
+ })
197
+
198
+ it('reads a React click as it reads the browser’s', () => {
199
+ const seen: boolean[] = []
200
+ render(<a href="#x" onClick={(event) => seen.push(isPlainClick(event))}>Item</a>)
201
+ fireEvent.click(screen.getByRole('link'))
202
+ fireEvent.click(screen.getByRole('link'), { ctrlKey: true })
203
+ expect(seen).toEqual([true, false])
204
+ })
205
+ })
@@ -44,10 +44,16 @@ export function usePictureFor(): AppSetup['pictureFor'] {
44
44
  return useContext(Setup).pictureFor
45
45
  }
46
46
 
47
+ /** Whether a click is a plain one, the browser's to follow in this tab: the main button, with no Ctrl, Cmd, Shift or Alt — what every link part checks before it keeps a click in the app. */
48
+ export function isPlainClick(event: Pick<MouseEvent, 'button' | 'ctrlKey' | 'metaKey' | 'shiftKey' | 'altKey'>): boolean {
49
+ return event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey
50
+ }
51
+
47
52
  /**
48
53
  * A link's click, kept inside the app: the caller's own `onClick` first, then,
49
54
  * on a plain left click to this app's own address, the app's `navigate` in
50
- * place of a page load.
55
+ * place of a page load — or `inPlace`, when the caller opens it its own way
56
+ * (`NavItem`'s `onPlainClick`), with or without a provider.
51
57
  *
52
58
  * A plain left click to another site's address — another app's file — opens
53
59
  * it in a new tab that cannot reach back into this one, as "Open in …" does
@@ -59,12 +65,12 @@ export function usePictureFor(): AppSetup['pictureFor'] {
59
65
  * another scheme (`folder:`, `mailto:`). So an app that still passes its own
60
66
  * router `onClick`, as Ship's `linkTo` does, is unchanged.
61
67
  */
62
- export function useInAppClick<E extends HTMLElement>(href: string | undefined, onClick?: MouseEventHandler<E>): MouseEventHandler<E> | undefined {
68
+ export function useInAppClick<E extends HTMLElement>(href: string | undefined, onClick?: MouseEventHandler<E>, inPlace?: MouseEventHandler<E>): MouseEventHandler<E> | undefined {
63
69
  const navigate = useContext(Setup).navigate
64
- if (!navigate || href === undefined) return onClick
70
+ if ((!navigate && !inPlace) || href === undefined) return onClick
65
71
  return (event: MouseEvent<E>) => {
66
72
  onClick?.(event)
67
- if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return
73
+ if (event.defaultPrevented || !isPlainClick(event)) return
68
74
  const link = event.currentTarget
69
75
  const target = link.getAttribute('target')
70
76
  if ((target && target !== '_self') || link.hasAttribute('download')) return
@@ -75,14 +81,19 @@ export function useInAppClick<E extends HTMLElement>(href: string | undefined, o
75
81
  return
76
82
  }
77
83
  if (url.origin !== window.location.origin) {
78
- if (url.protocol !== 'https:' && url.protocol !== 'http:') return
84
+ // Without a provider another site's address is the browser's, as it always was.
85
+ if (!navigate || (url.protocol !== 'https:' && url.protocol !== 'http:')) return
79
86
  event.preventDefault()
80
87
  window.open(url.href, '_blank', 'noopener,noreferrer')
81
88
  return
82
89
  }
83
90
  event.preventDefault()
91
+ if (inPlace) {
92
+ inPlace(event)
93
+ return
94
+ }
84
95
  // The path, never the whole address: a router reads `https://…` as a path
85
96
  // under the current page and lands nowhere (Peek's message link, 8 October).
86
- navigate(`${url.pathname}${url.search}${url.hash}`)
97
+ navigate?.(`${url.pathname}${url.search}${url.hash}`)
87
98
  }
88
99
  }
@@ -0,0 +1,70 @@
1
+ import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
+ import * as ArchiveDialogStories from './ArchiveDialog.stories'
3
+
4
+ <Meta of={ArchiveDialogStories} />
5
+
6
+ # ArchiveDialog
7
+
8
+ The question asked before archiving a file or a Folder: what goes out of the
9
+ lists with it, counted, and an optional resolution.
10
+
11
+ <Canvas of={ArchiveDialogStories.AProject} />
12
+
13
+ ## When
14
+
15
+ - Before archiving anything whose manifest declares an archive action — a
16
+ topic, a project or an issue — or a Folder. Read the counts first, with
17
+ interop's `archiveImpact`, and word them: "14 issues", "2 files also in Steer".
18
+ - Open it at once, with `hides={null}`, when the count is still on its way: it
19
+ says it is counting, and Archive waits for it.
20
+
21
+ <Canvas of={ArchiveDialogStories.Counting} />
22
+
23
+ ## When not
24
+
25
+ - For a deletion → **ConfirmDialog**; its `alternative` offers archiving instead.
26
+ - For Unarchive: it only brings back what was there, so it runs on the click.
27
+ - With counts you have not read. A warning that says it hides nothing because
28
+ the read failed is worse than no warning — refuse and say why instead.
29
+
30
+ ## How
31
+
32
+ ```tsx
33
+ import { ArchiveDialog } from '@estiva-app/ui'
34
+
35
+ <ArchiveDialog
36
+ title="Conversation standard"
37
+ what="project"
38
+ hides={['14 issues']}
39
+ staysVisible={['2 files also in Steer']}
40
+ apps={['Peek', 'Ship']}
41
+ getBack="Nothing is deleted: it waits under Archive, where Unarchive brings everything back as it was."
42
+ onArchive={(resolution) => archive(resolution || undefined)}
43
+ onClose={close}
44
+ />
45
+ ```
46
+
47
+ - `apps` and `getBack` are your app's words: the apps whose lists it goes out
48
+ of, in the order to name them, and the last line, which says where an archived
49
+ file waits in your app.
50
+ - `onArchive` gets the resolution trimmed; answer `false` to keep the dialog
51
+ open once you have said why.
52
+ - It is a **FormDialog**: Ctrl+Enter archives from the resolution, and the field
53
+ and both buttons wait while it does. Archive hides and never deletes, so the
54
+ button is not destructive, and Escape or a press outside closes it.
55
+
56
+ <Canvas of={ArchiveDialogStories.AFolder} />
57
+
58
+ <Canvas of={ArchiveDialogStories.AnotherAppsWords} />
59
+
60
+ ## What it owns
61
+
62
+ | It does | So you never write | Refused when written by hand |
63
+ |---|---|---|
64
+ | Says what goes with it, counted, and what stays visible elsewhere, in one block of sentences | the archive's sentences | |
65
+ | Archives on Ctrl+Enter from the resolution, and waits for the answer with everything switched off | a key handler, or a busy state | |
66
+ | Says it is counting while `hides` is `null`, and keeps Archive greyed until the count is in | a counting state | |
67
+
68
+ ## Props
69
+
70
+ <Controls of={ArchiveDialogStories.AProject} />
@@ -0,0 +1,64 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { userEvent, within } from 'storybook/test'
3
+ import { ArchiveDialog } from './ArchiveDialog'
4
+
5
+ /**
6
+ * The question before archiving a file or a Folder: what goes with it,
7
+ * counted, and an optional resolution. The apps it goes out of and the last
8
+ * line are the caller's words; these are Peek's, and Ship's in its own story.
9
+ */
10
+ const meta = {
11
+ title: 'Menus & windows/ArchiveDialog',
12
+ component: ArchiveDialog,
13
+ parameters: {
14
+ layout: 'fullscreen',
15
+ docs: { story: { inline: false, height: '560px' } },
16
+ },
17
+ argTypes: { onArchive: { control: false }, onClose: { control: false } },
18
+ args: {
19
+ title: 'Conversation standard',
20
+ what: 'project',
21
+ hides: ['14 issues'],
22
+ apps: ['Peek', 'Ship'],
23
+ getBack: 'Nothing is deleted: it waits under Archive, where Unarchive brings everything back as it was.',
24
+ onClose: () => {},
25
+ onArchive: async () => true,
26
+ },
27
+ } satisfies Meta<typeof ArchiveDialog>
28
+
29
+ export default meta
30
+ type Story = StoryObj<typeof meta>
31
+
32
+ /** A project and the issues that go with it. */
33
+ export const AProject: Story = { name: 'A project' }
34
+
35
+ /** A topic with nothing under it: only the topic goes. */
36
+ export const ATopic: Story = {
37
+ name: 'A topic',
38
+ args: { title: 'Release notes', what: 'topic', hides: [] },
39
+ }
40
+
41
+ /** A Folder: what only it lists goes, and what another Folder lists stays there. */
42
+ export const AFolder: Story = {
43
+ name: 'A folder',
44
+ args: { title: 'Estiva HQ', what: 'folder', hides: ['3 projects', '6 topics'], staysVisible: ['2 files also in Steer'] },
45
+ }
46
+
47
+ /** Opened before the count is in: it says it is counting, and Archive waits. */
48
+ export const Counting: Story = {
49
+ args: { title: 'Estiva HQ', what: 'folder', hides: null },
50
+ }
51
+
52
+ /** Another app's words: the apps in its order, and its own last line. */
53
+ export const AnotherAppsWords: Story = {
54
+ name: "Another app's words",
55
+ args: { apps: ['Ship', 'Peek'], getBack: 'Nothing is deleted: a link still opens it, and Unarchive brings everything back as it was.' },
56
+ }
57
+
58
+ /** Archiving: the field and both buttons wait for the answer. */
59
+ export const Archiving: Story = {
60
+ args: { onArchive: () => new Promise<boolean>(() => {}) },
61
+ play: async ({ canvasElement }) => {
62
+ await userEvent.click(within(canvasElement.ownerDocument.body).getByRole('button', { name: 'Archive project' }))
63
+ },
64
+ }
@@ -0,0 +1,90 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * The question before archiving a file or a Folder (FOL-46), moved from Peek
4
+ * (C11, 2 November) with Peek's tests, and the app's words passed in: the apps
5
+ * it goes out of, and its last line.
6
+ */
7
+ import { afterEach, describe, expect, it, vi } from 'vitest'
8
+ import { cleanup, render, screen } from '@testing-library/react'
9
+ import userEvent from '@testing-library/user-event'
10
+ import { ArchiveDialog, type ArchiveDialogProps } from './ArchiveDialog'
11
+
12
+ afterEach(cleanup)
13
+
14
+ const PEEKS_LINE = 'Nothing is deleted: it waits under Archive, where Unarchive brings everything back as it was.'
15
+
16
+ const Fixture = (props: Partial<ArchiveDialogProps>) => (
17
+ <ArchiveDialog title="T" what="topic" hides={[]} apps={['Peek', 'Ship']} getBack={PEEKS_LINE} onClose={() => {}} onArchive={async () => true} {...props} />
18
+ )
19
+
20
+ describe('ArchiveDialog', () => {
21
+ it('says what goes with the file, counted, and archives with the resolution typed', async () => {
22
+ const onArchive = vi.fn(async () => true)
23
+ render(<Fixture title="Probe project" what="project" hides={['2 issues']} staysVisible={['1 file also in Steer']} onArchive={onArchive} />)
24
+ expect(screen.getByRole('dialog', { name: 'Archive “Probe project”?' })).toBeTruthy()
25
+ expect(screen.getByText('This hides the project and 2 issues from every list, in Peek and in Ship.')).toBeTruthy()
26
+ expect(screen.getByText('1 file also in Steer stay visible there.')).toBeTruthy()
27
+ await userEvent.type(screen.getByLabelText('Resolution (optional)'), ' Shipped in 0.37. ')
28
+ await userEvent.click(screen.getByRole('button', { name: 'Archive project' }))
29
+ expect(onArchive).toHaveBeenCalledWith('Shipped in 0.37.')
30
+ })
31
+
32
+ it('archives from the resolution with Ctrl+Enter, and closes when it is done', async () => {
33
+ const onArchive = vi.fn(async () => true)
34
+ const onClose = vi.fn()
35
+ render(<Fixture onClose={onClose} onArchive={onArchive} />)
36
+ await userEvent.type(screen.getByLabelText('Resolution (optional)'), 'Merged{Control>}{Enter}{/Control}')
37
+ expect(onArchive).toHaveBeenCalledWith('Merged')
38
+ await vi.waitFor(() => expect(onClose).toHaveBeenCalled())
39
+ })
40
+
41
+ it('stays open when the archive is refused', async () => {
42
+ const onClose = vi.fn()
43
+ render(<Fixture onClose={onClose} onArchive={async () => false} />)
44
+ await userEvent.click(screen.getByRole('button', { name: 'Archive topic' }))
45
+ await vi.waitFor(() => expect((screen.getByRole('button', { name: 'Archive topic' }) as HTMLButtonElement).disabled).toBe(false))
46
+ expect(onClose).not.toHaveBeenCalled()
47
+ })
48
+
49
+ it('closes on Escape, even with the cursor in the resolution', async () => {
50
+ const onClose = vi.fn()
51
+ render(<Fixture onClose={onClose} />)
52
+ await userEvent.type(screen.getByLabelText('Resolution (optional)'), 'half a thought{Escape}')
53
+ expect(onClose).toHaveBeenCalled()
54
+ })
55
+
56
+ it('hides only the file when nothing is under it', () => {
57
+ render(<Fixture />)
58
+ expect(screen.getByText('This hides the topic from every list, in Peek and in Ship.')).toBeTruthy()
59
+ })
60
+
61
+ it('opens before the count is in: says it is counting, and Archive waits for it', async () => {
62
+ const onArchive = vi.fn(async () => true)
63
+ render(<Fixture what="folder" hides={null} onArchive={onArchive} />)
64
+ expect(screen.getByText('Counting what archiving this folder would hide…')).toBeTruthy()
65
+ expect((screen.getByRole('button', { name: 'Archive folder' }) as HTMLButtonElement).disabled).toBe(true)
66
+ await userEvent.type(screen.getByLabelText('Resolution (optional)'), 'x{Control>}{Enter}{/Control}')
67
+ expect(onArchive).not.toHaveBeenCalled()
68
+ })
69
+
70
+ it('names the apps it goes out of in the order given, and its last line is the app’s', () => {
71
+ const shipsLine = 'Nothing is deleted: a link still opens it, and Unarchive brings everything back as it was.'
72
+ const { unmount } = render(<Fixture what="project" hides={['14 issues']} apps={['Ship', 'Peek']} getBack={shipsLine} />)
73
+ expect(screen.getByText('This hides the project and 14 issues from every list, in Ship and in Peek.')).toBeTruthy()
74
+ expect(screen.getByText(shipsLine)).toBeTruthy()
75
+ unmount()
76
+ const { unmount: next } = render(<Fixture apps={['Leaf']} />)
77
+ expect(screen.getByText('This hides the topic from every list, in Leaf.')).toBeTruthy()
78
+ next()
79
+ render(<Fixture apps={[]} hides={['3 projects', '6 topics']} />)
80
+ expect(screen.getByText('This hides the topic and 3 projects and 6 topics from every list.')).toBeTruthy()
81
+ })
82
+
83
+ it('both buttons wait while it archives', async () => {
84
+ render(<Fixture onArchive={() => new Promise<boolean>(() => {})} />)
85
+ await userEvent.click(screen.getByRole('button', { name: 'Archive topic' }))
86
+ expect((screen.getByRole('button', { name: 'Archive topic' }) as HTMLButtonElement).disabled).toBe(true)
87
+ expect((screen.getByRole('button', { name: 'Cancel' }) as HTMLButtonElement).disabled).toBe(true)
88
+ expect((screen.getByLabelText('Resolution (optional)') as HTMLTextAreaElement).disabled).toBe(true)
89
+ })
90
+ })
@@ -0,0 +1,70 @@
1
+ import { useState } from 'react'
2
+ import { Field } from './Field'
3
+ import { FormDialog } from './FormDialog'
4
+ import { Textarea } from './Textarea'
5
+
6
+ /** "a, b and c". */
7
+ const listOf = (parts: readonly string[]) => (parts.length <= 1 ? (parts[0] ?? '') : `${parts.slice(0, -1).join(', ')} and ${parts.at(-1)}`)
8
+
9
+ /**
10
+ * The question asked before archiving a file or a Folder (FOL-46): what goes
11
+ * out of the lists with it, counted, and an optional resolution — Peek's
12
+ * ArchiveDialog, moved into the kit (C11, 2 November), whose sentences were
13
+ * already Ship's. The app passes its words: the apps it goes out of, and the
14
+ * last line, which says where an archived file waits in that app.
15
+ *
16
+ * A `FormDialog`, not a `ConfirmDialog` (1 October): it asks for a resolution,
17
+ * and a question with a field is a form. So Ctrl+Enter archives from the
18
+ * field, everything waits while it archives, and Escape or a press outside
19
+ * closes it. Archive hides and never deletes, so the button is not destructive.
20
+ */
21
+ export interface ArchiveDialogProps {
22
+ /** The file's name, for the title. */
23
+ title: string
24
+ /** What it is, in a word: "topic", "project", "issue", "folder". */
25
+ what: string
26
+ /**
27
+ * What goes out of the lists with it, already counted and worded — "14
28
+ * issues". Empty: nothing else. `null` while it is still being counted: the
29
+ * dialog opens at once and says so, and Archive waits for the count.
30
+ */
31
+ hides: readonly string[] | null
32
+ /** What it lists that stays visible somewhere else, worded — "2 files also in Steer". */
33
+ staysVisible?: readonly string[]
34
+ /** The apps whose lists it goes out of, in the order to name them: `['Peek', 'Ship']` reads "in Peek and in Ship". */
35
+ apps: readonly string[]
36
+ /** The last line, in the app's words: that nothing is deleted, and how to get it back there. */
37
+ getBack: string
38
+ onClose: () => void
39
+ /** With the resolution, trimmed (`''` for none). Resolve `false` to keep the dialog open (you have said why). */
40
+ onArchive: (resolution: string) => Promise<boolean | void> | boolean | void
41
+ }
42
+
43
+ export function ArchiveDialog({ title, what, hides, staysVisible = [], apps, getBack, onClose, onArchive }: ArchiveDialogProps) {
44
+ const [resolution, setResolution] = useState('')
45
+ const where = apps.length ? `, ${listOf(apps.map((app) => `in ${app}`))}` : ''
46
+ return (
47
+ <FormDialog title={`Archive “${title}”?`} submitLabel={`Archive ${what}`} ready={hides !== null} onSubmit={() => onArchive(resolution.trim())} onClose={onClose}>
48
+ {/* The words are one block, 8px apart, before the field; the Form puts 24px between them (1 October). Ctrl+Enter archives from the resolution; Enter there is a new line. */}
49
+ <div className="flex flex-col gap-2 text-body-2 text-text-primary">
50
+ <p>
51
+ {hides === null
52
+ ? `Counting what archiving this ${what} would hide…`
53
+ : hides.length
54
+ ? `This hides the ${what} and ${listOf(hides)} from every list${where}.`
55
+ : `This hides the ${what} from every list${where}.`}
56
+ </p>
57
+ {staysVisible.length > 0 && <p>{`${listOf(staysVisible)} stay visible there.`}</p>}
58
+ <p className="text-text-secondary">{getBack}</p>
59
+ </div>
60
+ <Field label="Resolution (optional)">
61
+ <Textarea
62
+ value={resolution}
63
+ rows={3}
64
+ placeholder={`What happened with this ${what}? Shown first to anyone who opens it.`}
65
+ onChange={(event) => setResolution(event.target.value)}
66
+ />
67
+ </Field>
68
+ </FormDialog>
69
+ )
70
+ }
@@ -14,6 +14,7 @@ The one card attached to a piece of text, and the ✕ that removes it.
14
14
  - **while writing** — `CommentBox` places it inside the box, with the files, on their fill, its values and its links as words, so a click on it never leaves the draft. Write nothing for that.
15
15
  - **after sending** — under the text, its values as pickers.
16
16
  - **no ✕** — no `onRemove`: to anyone but who wrote it.
17
+ - **`remember`** — a card that loads where something is being read: it keeps its height while it loads, from the last time this device drew it.
17
18
 
18
19
  The ✕ is a file's: round, on the card's corner, shown when the pointer is over the card or the ✕ has focus, and always on a screen that cannot hover, so a tap reaches it.
19
20
 
@@ -35,6 +36,10 @@ import { AttachedCard } from '@estiva-app/ui'
35
36
  - `onRemove` is the app's: before sending it drops the card from what will be sent; after, it sends the edit that removes it.
36
37
  - It is at most 480px wide.
37
38
  - **An app that draws its sent cards itself** passes its card as `children` instead of `link`, so the card in a box and under a sent message are the same: `<AttachedCard onRemove={remove}>{appCard}</AttachedCard>`. `CommentBox` draws its card this way.
39
+ - **It keeps its height while it loads** with `remember={{ memory: cardShapes, id: address }}`: `memory` is the app's one `cardShapeMemory` (cleared at sign-out), `id` the card's address. It measures the card it draws, again once a resize settles (500ms), and while it loads next time holds that height and draws the placeholder in that shape. A card measured at 0 (not on screen) keeps the height it had. A `shape` the app puts on the loading `link` wins over the remembered one.
40
+
41
+ <Canvas of={AttachedCardStories.LoadingAtItsLastHeight} />
42
+
38
43
  - **One inside another draws only its card**, with the outer one's ✕: an app whose sent card is an `AttachedCard` hands the box that same card, and the box's ✕ is the one. There is never a card in a card.
39
44
 
40
45
  ## What it owns
@@ -43,6 +48,7 @@ import { AttachedCard } from '@estiva-app/ui'
43
48
  |---|---|
44
49
  | Places the ✕ on the card's corner, as a file's | a remove button of your own |
45
50
  | Reveals the ✕ on hover and focus, and always shows it on touch | a hover or touch check |
51
+ | With `remember`: measures the drawn card, notes its shape and height once a resize settles, and holds them while it loads | a `ResizeObserver`, a timer, a `minHeight` |
46
52
 
47
53
  ## Keys
48
54
 
@@ -2,7 +2,8 @@ import type { Meta, StoryObj } from '@storybook/react-vite'
2
2
  import { useState } from 'react'
3
3
  import { AttachedCard } from './AttachedCard'
4
4
  import { Button } from './Button'
5
- import { ITEM, LOADING, ready, SAID, UNAVAILABLE } from './linked.examples'
5
+ import { cardShapeMemory, loadingShapeOf } from './linked'
6
+ import { ITEM, ITEM_NO_SUMMARY, LOADING, ready, SAID, UNAVAILABLE } from './linked.examples'
6
7
 
7
8
  const meta = {
8
9
  title: 'Links & references/AttachedCard',
@@ -34,3 +35,10 @@ export const Loading: Story = { args: { link: LOADING }, render: (args) => <Atta
34
35
 
35
36
  /** Deleted, or not this reader's to see. */
36
37
  export const NotAvailable: Story = { args: { link: UNAVAILABLE }, render: (args) => <AttachedCard {...args} onRemove={() => {}} /> }
38
+
39
+ /** This device drew it last time with no summary, at 120px: loading again, it holds that shape and that height. */
40
+ const DRAWN_BEFORE = cardShapeMemory('story.attached-card')
41
+ DRAWN_BEFORE.note('item-two', { ...loadingShapeOf(ITEM_NO_SUMMARY), height: 120 })
42
+
43
+ /** Loading, at the shape and height it last drew at on this device (`remember`), so nothing around it moves. */
44
+ export const LoadingAtItsLastHeight: Story = { args: { link: LOADING, remember: { memory: DRAWN_BEFORE, id: 'item-two' } } }
@@ -4,8 +4,8 @@ import { cleanup, render, screen } from '@testing-library/react'
4
4
  import userEvent from '@testing-library/user-event'
5
5
  import { afterEach, describe, expect, it, vi } from 'vitest'
6
6
  import { AttachedCard } from './AttachedCard'
7
- import { inTheBox } from './linked'
8
- import { ITEM, ready } from './linked.examples'
7
+ import { cardShapeMemory, inTheBox, loadingShapeOf } from './linked'
8
+ import { ITEM, ITEM_NO_SUMMARY, LOADING, ready } from './linked.examples'
9
9
 
10
10
  afterEach(cleanup)
11
11
 
@@ -66,3 +66,112 @@ describe('AttachedCard', () => {
66
66
  expect(screen.queryByRole('button', { name: 'Remove' })).toBeNull()
67
67
  })
68
68
  })
69
+
70
+ /*
71
+ A card keeps its height while it loads (C4): given the app's memory (`cardShapeMemory`) and the card's id there, it
72
+ measures the card it draws and, the next time it loads, holds that height and that shape, so the conversation around
73
+ it does not move. Peek's and Ship's `MessageCard` did this by hand, with these timings; their tests, moved.
74
+ */
75
+ describe('AttachedCard, remembered', () => {
76
+ let shapes = 0
77
+ const memory = (firstDraw?: Parameters<typeof cardShapeMemory>[1]) => cardShapeMemory(`test.attached-${++shapes}`, firstDraw)
78
+ /** The lines the loading card holds room for, top to bottom: the title, a key line, a summary, the pickers. */
79
+ const placeholderLines = (container: HTMLElement) => container.querySelector('[aria-busy] > *')?.children.length
80
+ const held = (container: HTMLElement) => (container.querySelector('.group\\/card') as HTMLElement).style.minHeight
81
+
82
+ afterEach(() => {
83
+ vi.restoreAllMocks()
84
+ vi.useRealTimers()
85
+ localStorage.clear()
86
+ })
87
+
88
+ it('holds room for only a title and its pickers on a first draw, when that is the app’s first shape for the kind', () => {
89
+ const remember = { memory: memory({ firstDraw: { issue: { subtitle: false, summary: false, footer: 'pickers' } } }), id: 'item-1' }
90
+ const { container } = render(<AttachedCard link={LOADING} remember={remember} />)
91
+ expect(placeholderLines(container)).toBe(2)
92
+ })
93
+
94
+ it('holds room for what it drew with last time on this device: no summary, where the kind’s usual card has one', () => {
95
+ const remember = { memory: memory(), id: 'item-2' }
96
+ const first = render(<AttachedCard link={ready(ITEM_NO_SUMMARY)} remember={remember} />)
97
+ first.unmount()
98
+ const again = render(<AttachedCard link={LOADING} remember={remember} />)
99
+ expect(placeholderLines(again.container)).toBe(2)
100
+ })
101
+
102
+ it('…and the summary it drew with, after a first shape without one', () => {
103
+ const remember = { memory: memory({ firstDraw: { issue: { subtitle: false, summary: false, footer: 'pickers' } } }), id: 'item-8' }
104
+ const first = render(<AttachedCard link={ready(ITEM)} remember={remember} />)
105
+ first.unmount()
106
+ const again = render(<AttachedCard link={LOADING} remember={remember} />)
107
+ expect(placeholderLines(again.container)).toBe(3)
108
+ })
109
+
110
+ it('holds the height it drew at last time, which a summary wrapped to two lines needs (17 Oct, 114 → 134 px)', () => {
111
+ const remember = { memory: memory(), id: 'item-3' }
112
+ const measured = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({ height: 134 } as DOMRect)
113
+ const first = render(<AttachedCard link={ready(ITEM)} remember={remember} />)
114
+ first.unmount()
115
+ measured.mockRestore()
116
+ const again = render(<AttachedCard link={LOADING} remember={remember} />)
117
+ expect(held(again.container)).toBe('134px')
118
+ })
119
+
120
+ it('holds nothing once it has drawn, and nothing without a height to hold', () => {
121
+ const remember = { memory: memory(), id: 'item-4' }
122
+ const { container, rerender } = render(<AttachedCard link={LOADING} remember={remember} />)
123
+ expect(held(container)).toBe('')
124
+ vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({ height: 134 } as DOMRect)
125
+ rerender(<AttachedCard link={ready(ITEM)} remember={remember} />)
126
+ expect(held(container)).toBe('')
127
+ })
128
+
129
+ it('a card not on screen (a closed panel) measures 0, and keeps the height it last drew at', () => {
130
+ const remember = { memory: memory(), id: 'item-5' }
131
+ remember.memory.note('item-5', { ...loadingShapeOf(ITEM_NO_SUMMARY), height: 134 })
132
+ vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({ height: 0 } as DOMRect)
133
+ render(<AttachedCard link={ready(ITEM)} remember={remember} />)
134
+ expect(remember.memory.of('item-5', 'issue')).toEqual({ ...loadingShapeOf(ITEM), height: 134 })
135
+ })
136
+
137
+ it('a window being resized notes the new height once it settles, 500ms after the last change, not every frame', () => {
138
+ vi.useFakeTimers()
139
+ let resized: () => void = () => {}
140
+ vi.stubGlobal(
141
+ 'ResizeObserver',
142
+ class {
143
+ constructor(callback: () => void) {
144
+ resized = callback
145
+ }
146
+ observe() {}
147
+ disconnect() {}
148
+ },
149
+ )
150
+ const remember = { memory: memory(), id: 'item-6' }
151
+ const measured = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({ height: 134 } as DOMRect)
152
+ render(<AttachedCard link={ready(ITEM)} remember={remember} />)
153
+ expect(remember.memory.of('item-6', 'issue')?.height).toBe(134)
154
+ measured.mockReturnValue({ height: 150 } as DOMRect)
155
+ resized()
156
+ vi.advanceTimersByTime(300)
157
+ measured.mockReturnValue({ height: 154 } as DOMRect)
158
+ resized()
159
+ vi.advanceTimersByTime(499)
160
+ expect(remember.memory.of('item-6', 'issue')?.height).toBe(134)
161
+ vi.advanceTimersByTime(1)
162
+ expect(remember.memory.of('item-6', 'issue')?.height).toBe(154)
163
+ vi.unstubAllGlobals()
164
+ })
165
+
166
+ it('inside another, as the box wraps the card an app hands it, it still holds its height, and draws one card', () => {
167
+ const remember = { memory: memory(), id: 'item-7' }
168
+ remember.memory.note('item-7', { ...loadingShapeOf(ITEM), height: 134 })
169
+ const { container } = render(
170
+ <AttachedCard onRemove={() => {}}>
171
+ <AttachedCard link={LOADING} remember={remember} />
172
+ </AttachedCard>,
173
+ )
174
+ expect(container.querySelectorAll('.group\\/card')).toHaveLength(1)
175
+ expect([...container.querySelectorAll<HTMLElement>('*')].some((element) => element.style.minHeight === '134px')).toBe(true)
176
+ })
177
+ })