@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,90 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { useState } from 'react'
3
+ import { userEvent, within } from 'storybook/test'
4
+ import { EmptyState } from './EmptyState'
5
+ import { Field } from './Field'
6
+ import { FormDialog } from './FormDialog'
7
+ import { TextInput } from './TextInput'
8
+
9
+ /** A dialog that sends a form: the words, the fields, Cancel and the button that sends it. */
10
+ const meta = {
11
+ title: 'Menus & windows/FormDialog',
12
+ component: FormDialog,
13
+ parameters: {
14
+ layout: 'fullscreen',
15
+ // Portals a fixed overlay to document.body: an iframe on the Docs page, so it stays in its frame.
16
+ docs: { story: { inline: false, height: '400px' } },
17
+ },
18
+ argTypes: { children: { control: false }, onSubmit: { control: false }, onClose: { control: false } },
19
+ args: {
20
+ title: 'New folder',
21
+ submitLabel: 'Create',
22
+ busyLabel: 'Creating…',
23
+ onSubmit: () => {},
24
+ onClose: () => {},
25
+ children: null,
26
+ },
27
+ } satisfies Meta<typeof FormDialog>
28
+
29
+ export default meta
30
+ type Story = StoryObj<typeof meta>
31
+
32
+ /** One field and the sentence before it. Create waits for a name; Enter in the field sends. */
33
+ export const NewFolder: Story = {
34
+ name: 'New folder',
35
+ parameters: { controls: { disable: true } },
36
+ render: (args) => {
37
+ const [name, setName] = useState('')
38
+ return (
39
+ <FormDialog {...args} ready={!!name.trim()}>
40
+ <p className="text-body-2 text-text-secondary">A place for files and conversations. Everyone you add to it can read what is in it.</p>
41
+ <Field label="Folder name">
42
+ <TextInput value={name} onChange={(event) => setName(event.target.value)} placeholder="What is it for?" autoFocus />
43
+ </Field>
44
+ </FormDialog>
45
+ )
46
+ },
47
+ }
48
+
49
+ /** Sending: the button says so, and the field and both buttons wait for the answer. */
50
+ export const Sending: Story = {
51
+ parameters: { controls: { disable: true } },
52
+ args: { onSubmit: () => new Promise<void>(() => {}) },
53
+ render: NewFolder.render,
54
+ play: async ({ canvasElement }) => {
55
+ const page = within(canvasElement.ownerDocument.body)
56
+ await userEvent.type(page.getByRole('textbox', { name: 'Folder name' }), 'Steer')
57
+ await userEvent.click(page.getByRole('button', { name: 'Create' }))
58
+ },
59
+ }
60
+
61
+ /** Refused: the answer was `false`, so it stays open with what was typed, and the caller says why. */
62
+ export const Refused: Story = {
63
+ parameters: { controls: { disable: true } },
64
+ args: { onSubmit: () => false },
65
+ render: NewFolder.render,
66
+ play: Sending.play,
67
+ }
68
+
69
+ /** Nothing to choose from: a section's empty line where the fields would be, and the button greyed. */
70
+ export const NothingToChoose: Story = {
71
+ name: 'Nothing to choose',
72
+ args: { title: 'Move', submitLabel: 'Move', busyLabel: 'Moving…', ready: false, children: <EmptyState scope="section" message="There is no other folder it can be moved to." /> },
73
+ }
74
+
75
+ /** A Resolve: the kit's `resolve` look on the sending button, as `ResolveDialog` draws it. */
76
+ export const ResolveLook: Story = {
77
+ name: 'Resolve look',
78
+ parameters: { controls: { disable: true } },
79
+ args: { title: 'Resolve', submitLabel: 'Resolve', busyLabel: undefined, submitVariant: 'resolve' },
80
+ render: (args) => {
81
+ const [note, setNote] = useState('')
82
+ return (
83
+ <FormDialog {...args}>
84
+ <Field label="Resolution message (optional)">
85
+ <TextInput value={note} onChange={(event) => setNote(event.target.value)} />
86
+ </Field>
87
+ </FormDialog>
88
+ )
89
+ },
90
+ }
@@ -0,0 +1,183 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * A dialog that sends a form: what Peek's Archive, New folder, Move and Start
4
+ * a topic each wired by hand (C10, 2 November), pinned once.
5
+ */
6
+ import { afterEach, describe, expect, it, vi } from 'vitest'
7
+ import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
8
+ import userEvent from '@testing-library/user-event'
9
+ import { useState } from 'react'
10
+ import { FormDialog, type FormDialogProps } from './FormDialog'
11
+ import { Field } from './Field'
12
+ import { TextInput } from './TextInput'
13
+
14
+ afterEach(cleanup)
15
+
16
+ function Fixture(props: Partial<FormDialogProps>) {
17
+ const [name, setName] = useState('')
18
+ return (
19
+ <FormDialog title="New folder" submitLabel="Create" busyLabel="Creating…" ready={!!name.trim()} onSubmit={() => {}} onClose={() => {}} {...props}>
20
+ <p>A place for files and conversations.</p>
21
+ <Field label="Folder name">
22
+ <TextInput value={name} onChange={(event) => setName(event.target.value)} />
23
+ </Field>
24
+ </FormDialog>
25
+ )
26
+ }
27
+
28
+ const pending = () => {
29
+ let release: (value: boolean | void) => void = () => {}
30
+ const promise = new Promise<boolean | void>((resolve) => {
31
+ release = resolve
32
+ })
33
+ return { promise, release: (value?: boolean) => release(value) }
34
+ }
35
+
36
+ describe('FormDialog', () => {
37
+ it('is a dialog named by its title, holding a form, with Cancel and the button that sends it', () => {
38
+ render(<Fixture />)
39
+ const dialog = screen.getByRole('dialog', { name: 'New folder' })
40
+ expect(dialog.querySelector('form')).not.toBeNull()
41
+ expect(screen.getByRole('button', { name: 'Cancel' })).toBeTruthy()
42
+ const send = screen.getByRole('button', { name: 'Create' }) as HTMLButtonElement
43
+ expect(send.type).toBe('submit')
44
+ expect(send.getAttribute('form')).toBe(dialog.querySelector('form')!.id)
45
+ })
46
+
47
+ it('sends from its button and from Enter in a field, once there is enough to send', async () => {
48
+ const user = userEvent.setup()
49
+ const onSubmit = vi.fn(() => false)
50
+ render(<Fixture onSubmit={onSubmit} />)
51
+ const send = screen.getByRole('button', { name: 'Create' }) as HTMLButtonElement
52
+ expect(send.disabled).toBe(true)
53
+ await user.keyboard('{Enter}')
54
+ expect(onSubmit).not.toHaveBeenCalled()
55
+ await user.type(screen.getByRole('textbox', { name: 'Folder name' }), 'Steer{Enter}')
56
+ expect(onSubmit).toHaveBeenCalledTimes(1)
57
+ expect(send.disabled).toBe(false)
58
+ await user.click(send)
59
+ expect(onSubmit).toHaveBeenCalledTimes(2)
60
+ })
61
+
62
+ it('sends nothing while not ready, not even on Ctrl+Enter', async () => {
63
+ const user = userEvent.setup()
64
+ const onSubmit = vi.fn()
65
+ render(<Fixture ready={false} onSubmit={onSubmit} />)
66
+ await user.type(screen.getByRole('textbox', { name: 'Folder name' }), 'Steer{Control>}{Enter}{/Control}')
67
+ expect(onSubmit).not.toHaveBeenCalled()
68
+ })
69
+
70
+ it('while it sends: the button says so, both buttons wait, and the fields are off', async () => {
71
+ const user = userEvent.setup()
72
+ const sending = pending()
73
+ render(<Fixture onSubmit={() => sending.promise} />)
74
+ await user.type(screen.getByRole('textbox', { name: 'Folder name' }), 'Steer')
75
+ await user.click(screen.getByRole('button', { name: 'Create' }))
76
+ const send = screen.getByRole('button', { name: 'Creating…' }) as HTMLButtonElement
77
+ expect(send.disabled).toBe(true)
78
+ // Cancel too: nothing can stop a send under way, so a Cancel then would say what is not so.
79
+ expect((screen.getByRole('button', { name: 'Cancel' }) as HTMLButtonElement).disabled).toBe(true)
80
+ expect((screen.getByRole('textbox', { name: 'Folder name' }) as HTMLInputElement).disabled).toBe(true)
81
+ sending.release(false)
82
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Create' })).toBeTruthy())
83
+ expect((screen.getByRole('button', { name: 'Cancel' }) as HTMLButtonElement).disabled).toBe(false)
84
+ })
85
+
86
+ it('keeps its words on the button while it sends when it has no busy words', async () => {
87
+ const user = userEvent.setup()
88
+ render(<Fixture busyLabel={undefined} submitLabel="Archive topic" ready onSubmit={() => pending().promise} />)
89
+ await user.click(screen.getByRole('button', { name: 'Archive topic' }))
90
+ expect((screen.getByRole('button', { name: 'Archive topic' }) as HTMLButtonElement).disabled).toBe(true)
91
+ })
92
+
93
+ it('closes when the send went through, and stays open when it was refused', async () => {
94
+ const user = userEvent.setup()
95
+ const onClose = vi.fn()
96
+ const { unmount } = render(<Fixture ready onSubmit={async () => false} onClose={onClose} />)
97
+ await user.click(screen.getByRole('button', { name: 'Create' }))
98
+ await waitFor(() => expect((screen.getByRole('button', { name: 'Create' }) as HTMLButtonElement).disabled).toBe(false))
99
+ expect(onClose).not.toHaveBeenCalled()
100
+ unmount()
101
+ for (const answer of [true, undefined]) {
102
+ const closed = vi.fn()
103
+ const { unmount: done } = render(<Fixture ready onSubmit={async () => answer} onClose={closed} />)
104
+ await user.click(screen.getByRole('button', { name: 'Create' }))
105
+ await waitFor(() => expect(closed).toHaveBeenCalledOnce())
106
+ done()
107
+ }
108
+ })
109
+
110
+ it('a send that throws is a refusal: it stays open, and the buttons come back', async () => {
111
+ const user = userEvent.setup()
112
+ const onClose = vi.fn()
113
+ render(
114
+ <Fixture
115
+ ready
116
+ onSubmit={async () => {
117
+ throw new Error('down')
118
+ }}
119
+ onClose={onClose}
120
+ />,
121
+ )
122
+ await user.click(screen.getByRole('button', { name: 'Create' }))
123
+ await waitFor(() => expect((screen.getByRole('button', { name: 'Create' }) as HTMLButtonElement).disabled).toBe(false))
124
+ expect(onClose).not.toHaveBeenCalled()
125
+ })
126
+
127
+ it('sends once, however often it is asked while it sends', async () => {
128
+ const user = userEvent.setup()
129
+ const sending = pending()
130
+ const onSubmit = vi.fn(() => sending.promise)
131
+ render(<Fixture onSubmit={onSubmit} />)
132
+ const field = screen.getByRole('textbox', { name: 'Folder name' })
133
+ await user.type(field, 'Steer')
134
+ await user.keyboard('{Control>}{Enter}{Enter}{/Control}')
135
+ expect(onSubmit).toHaveBeenCalledTimes(1)
136
+ sending.release(true)
137
+ })
138
+
139
+ it('closed with Escape while it sends, it is closed once, not again when the send goes through', async () => {
140
+ const user = userEvent.setup()
141
+ const sending = pending()
142
+ const onClose = vi.fn()
143
+ function Page() {
144
+ const [open, setOpen] = useState(true)
145
+ return open ? (
146
+ <Fixture
147
+ ready
148
+ onSubmit={() => sending.promise}
149
+ onClose={() => {
150
+ onClose()
151
+ setOpen(false)
152
+ }}
153
+ />
154
+ ) : null
155
+ }
156
+ render(<Page />)
157
+ await user.click(screen.getByRole('button', { name: 'Create' }))
158
+ await user.keyboard('{Escape}')
159
+ expect(onClose).toHaveBeenCalledOnce()
160
+ await act(async () => sending.release(true))
161
+ expect(onClose).toHaveBeenCalledOnce()
162
+ })
163
+
164
+ it('Cancel closes without sending', async () => {
165
+ const user = userEvent.setup()
166
+ const onSubmit = vi.fn()
167
+ const onClose = vi.fn()
168
+ render(<Fixture ready onSubmit={onSubmit} onClose={onClose} />)
169
+ await user.click(screen.getByRole('button', { name: 'Cancel' }))
170
+ expect(onClose).toHaveBeenCalledOnce()
171
+ expect(onSubmit).not.toHaveBeenCalled()
172
+ })
173
+
174
+ it('the send button is primary, or the kit’s Resolve look', () => {
175
+ const { unmount } = render(<Fixture ready />)
176
+ expect(screen.getByRole('button', { name: 'Create' }).className).toContain('bg-accent-primary')
177
+ unmount()
178
+ render(<Fixture ready submitLabel="Resolve" submitVariant="resolve" />)
179
+ const resolve = screen.getByRole('button', { name: 'Resolve' })
180
+ expect(resolve.className).not.toContain('bg-accent-primary')
181
+ expect(resolve.className).toContain('hover:bg-success-muted')
182
+ })
183
+ })
@@ -0,0 +1,93 @@
1
+ import { useId, useRef, useState, type ReactNode } from 'react'
2
+ import { Button } from './Button'
3
+ import { DialogShell } from './DialogShell'
4
+ import { Form } from './Form'
5
+
6
+ /**
7
+ * A dialog that sends a form: `DialogShell` holding a `Form`, with Cancel and
8
+ * the button that sends it in the footer — what Peek's Archive, New folder,
9
+ * Move and Start a topic each wired by hand, and `ResolveDialog` too (C10,
10
+ * 2 November). The look is theirs, unchanged.
11
+ *
12
+ * It owns the send: the button says its busy words while it waits, the fields
13
+ * and both buttons are off until the answer comes, and a send that went
14
+ * through closes it. An answer of `false` keeps it open, because the caller
15
+ * has said why; so does a throw.
16
+ *
17
+ * **Cancel waits too** (decided once for all, 2 November; only Peek's Archive
18
+ * did it before): nothing can stop a send already under way, so a Cancel
19
+ * pressed then would close over a write still running, and its answer, a
20
+ * refusal included, would have nowhere to land. `ConfirmDialog` waits the same
21
+ * way. Escape and the ✕ still close it, as they do there.
22
+ */
23
+ export interface FormDialogProps {
24
+ /** The dialog's heading. */
25
+ title: string
26
+ /** The words on the button that sends the form: "Move", "Create". */
27
+ submitLabel: string
28
+ /** Its words while the form sends — "Moving…". Absent, they stay as they are. */
29
+ busyLabel?: string
30
+ /** How the sending button looks: `primary`, or `resolve` for a Resolve. */
31
+ submitVariant?: 'primary' | 'resolve'
32
+ /** Whether there is enough to send. While it is not, the button is greyed and Enter sends nothing. */
33
+ ready?: boolean
34
+ /** Sends the form. Answer `false` to keep the dialog open (you have said why); anything else closes it. */
35
+ onSubmit: () => Promise<boolean | void> | boolean | void
36
+ /** Cancel, Escape, the ✕, a press outside, and a send that went through: once, when it was closed while it sent. */
37
+ onClose: () => void
38
+ /** What the form holds: the words before the fields, then the fields. The form puts 24px between them. */
39
+ children: ReactNode
40
+ }
41
+
42
+ export function FormDialog({ title, submitLabel, busyLabel, submitVariant = 'primary', ready = true, onSubmit, onClose, children }: FormDialogProps) {
43
+ const [busy, setBusy] = useState(false)
44
+ // Known at once rather than at the next render: two Ctrl+Enters before it re-renders send once.
45
+ const sending = useRef(false)
46
+ // Closed while it sent (Escape, the ✕): the send that then goes through does not close it a second time.
47
+ const closed = useRef(false)
48
+ const formId = useId()
49
+
50
+ const close = () => {
51
+ closed.current = true
52
+ onClose()
53
+ }
54
+
55
+ const send = async () => {
56
+ if (!ready || sending.current) return
57
+ sending.current = true
58
+ closed.current = false
59
+ setBusy(true)
60
+ let answer: boolean | void = false
61
+ try {
62
+ answer = await onSubmit()
63
+ } catch {
64
+ /* a refusal: the caller has said why, and the dialog stays */
65
+ answer = false
66
+ } finally {
67
+ sending.current = false
68
+ setBusy(false)
69
+ }
70
+ if (answer !== false && !closed.current) close()
71
+ }
72
+
73
+ return (
74
+ <DialogShell
75
+ title={title}
76
+ onClose={close}
77
+ footer={
78
+ <>
79
+ <Button variant="muted" onClick={close} disabled={busy}>
80
+ Cancel
81
+ </Button>
82
+ <Button variant={submitVariant} type="submit" form={formId} disabled={!ready || busy}>
83
+ {busy && busyLabel ? busyLabel : submitLabel}
84
+ </Button>
85
+ </>
86
+ }
87
+ >
88
+ <Form id={formId} busy={busy} onSubmit={send}>
89
+ {children}
90
+ </Form>
91
+ </DialogShell>
92
+ )
93
+ }
@@ -53,6 +53,7 @@ It does these by itself. Write none of them around it.
53
53
  | An unchanged or (for a title) empty value is not a write | a compare before saving |
54
54
  | Your text stays after a refused save, and a change from elsewhere waits | a draft kept beside it |
55
55
  | The placeholder while it is empty | an empty check |
56
+ | Selected words painted in the selected colour, as in every editor | a `::selection` rule |
56
57
 
57
58
  ## Keys
58
59
 
@@ -3,6 +3,7 @@ import { Extension, Node } from '@tiptap/core'
3
3
  import { history, redo, undo } from '@tiptap/pm/history'
4
4
  import { EditorContent, useEditor } from '@tiptap/react'
5
5
  import { cn } from './cn'
6
+ import { EDITOR_SELECTION_CLASSES } from './looks'
6
7
 
7
8
  /**
8
9
  * A line of plain text on a page that you edit where it stands, as in a
@@ -132,7 +133,7 @@ export function InlineText({ value, placeholder, label, onCommit, onText, onEnte
132
133
  'aria-multiline': 'false',
133
134
  'aria-placeholder': placeholder,
134
135
  ...(readOnly ? { 'aria-readonly': 'true' } : {}),
135
- class: 'outline-none',
136
+ class: cn('outline-none', EDITOR_SELECTION_CLASSES),
136
137
  },
137
138
  handleKeyDown: (view, event) => {
138
139
  if (event.key === 'Enter') {
@@ -0,0 +1,74 @@
1
+ import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
+ import * as MoveDialogStories from './MoveDialog.stories'
3
+
4
+ <Meta of={MoveDialogStories} />
5
+
6
+ # MoveDialog
7
+
8
+ Move a file to another Folder, under another file there, or both: the Folder
9
+ first, then what it goes under, read when the Folder is picked.
10
+
11
+ <Canvas of={MoveDialogStories.Topic} />
12
+
13
+ ## When
14
+
15
+ - Moving any file, from its menu, its row or its Folder. A file that may sit
16
+ under another passes `placesIn`; one that nests under nothing passes none, and
17
+ is asked only for the Folder.
18
+ - A file that may sit at the top of any Folder: `startAtTop`, so the top is
19
+ chosen for the person. Otherwise Move waits for a pick: a preselected place is
20
+ a move nobody chose.
21
+
22
+ <Canvas of={MoveDialogStories.Project} />
23
+
24
+ ## When not
25
+
26
+ - Renaming, or choosing a Folder for something new → **FormDialog** with a **Select**.
27
+ - One value from a list on a page, not a move → **Select**.
28
+
29
+ ## How
30
+
31
+ ```tsx
32
+ import { MoveDialog } from '@estiva-app/ui'
33
+
34
+ <MoveDialog
35
+ title="Notes"
36
+ description="Everyone who can read it now still can."
37
+ from={folder}
38
+ folders={folders}
39
+ places={placesHere}
40
+ placesIn={(id) => readPlaces(id)}
41
+ startAtTop
42
+ onMove={({ folder, parent }) => move(folder, parent)}
43
+ onClose={close}
44
+ />
45
+ ```
46
+
47
+ - A place is `{ id, path }`: `id` is what it goes under, its address, and `''`
48
+ for the top; `path` is its breadcrumb, drawn as "Brief › Notes".
49
+ - `placesIn` is called once per Folder, when it is picked; a rejection is said as
50
+ the section's empty line, with **Try again**. `places` are the ones in `from`,
51
+ already read; without them the Folder it opens on is read at once.
52
+ - `onMove` gets `{ folder }`, and `parent` too when it nests (`''` for the top).
53
+ Answer `false` to keep it open once you have said why.
54
+ - `folders` undefined while they are read: the list says "Reading…".
55
+ - `heading`, `folderLabel`, `noFolder` and `topLabel` are for your app's words;
56
+ `startIn` opens it on another Folder than the one it is in.
57
+
58
+ <Canvas of={MoveDialogStories.FolderUnreadable} />
59
+
60
+ <Canvas of={MoveDialogStories.NowhereHere} />
61
+
62
+ <Canvas of={MoveDialogStories.UnderNone} />
63
+
64
+ ## What it owns
65
+
66
+ | It does | So you never write | Refused when written by hand |
67
+ |---|---|---|
68
+ | Reads a Folder's places when it is picked, once, and says when it could not, with Try again | a read state per Folder, or a retry row | |
69
+ | Offers only moves that do something, and chooses nothing for the person but the top when asked | a filter on the Folders, or a preselection | |
70
+ | Sends on Move, says it is moving, and closes when the move went through | a busy state, or an `if (ok) onClose()` | |
71
+
72
+ ## Props
73
+
74
+ <Controls of={MoveDialogStories.Topic} />
@@ -0,0 +1,121 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { userEvent, within } from 'storybook/test'
3
+ import { MoveDialog, type MovePlace } from './MoveDialog'
4
+
5
+ const FOLDERS = [
6
+ { id: 'hq', name: 'Estiva HQ' },
7
+ { id: 'peek', name: 'Peek' },
8
+ { id: 'steer', name: 'Steer' },
9
+ ]
10
+ const TOP: MovePlace = { id: '', path: [] }
11
+ const PROJECT: MovePlace = { id: '30850:a:folders', path: ['Folders: navigation for the whole suite'] }
12
+ const BRIEF: MovePlace = { id: '30840:a:brief', path: ['Folders: navigation for the whole suite', 'Brief'] }
13
+
14
+ /**
15
+ * Moving a file to another Folder, under another file, or both. The places in
16
+ * its own Folder are the caller's, read before it opens; another Folder's are
17
+ * read when it is picked.
18
+ */
19
+ const meta = {
20
+ title: 'Menus & windows/MoveDialog',
21
+ component: MoveDialog,
22
+ parameters: {
23
+ layout: 'fullscreen',
24
+ docs: { story: { inline: false, height: '560px' } },
25
+ },
26
+ argTypes: { onMove: { control: false }, onClose: { control: false }, placesIn: { control: false } },
27
+ args: {
28
+ title: 'Notes',
29
+ description: 'Everyone who can read it now still can.',
30
+ from: 'hq',
31
+ folders: FOLDERS,
32
+ places: [TOP, PROJECT, BRIEF],
33
+ placesIn: async (): Promise<readonly MovePlace[]> => [TOP, { id: '30840:a:brief', path: ['Brief'] }],
34
+ startAtTop: true,
35
+ onMove: async () => true,
36
+ onClose: () => {},
37
+ },
38
+ } satisfies Meta<typeof MoveDialog>
39
+
40
+ export default meta
41
+ type Story = StoryObj<typeof meta>
42
+
43
+ const pickSteer = async ({ canvasElement }: { canvasElement: HTMLElement }) => {
44
+ const page = within(canvasElement.ownerDocument.body)
45
+ await userEvent.click(page.getByRole('combobox', { name: 'Folder' }))
46
+ await userEvent.click(await page.findByRole('option', { name: 'Steer' }))
47
+ }
48
+
49
+ /** A file that may sit under any other: its own Folder first, at the top, with every other place there. */
50
+ export const Topic: Story = {}
51
+
52
+ /** A file that nests under nothing: only the Folder is asked, and not the one it is in. Move waits for a pick. */
53
+ export const Project: Story = {
54
+ args: { title: 'Folders: navigation for the whole suite', places: undefined, placesIn: undefined },
55
+ }
56
+
57
+ /** Nowhere to go in its own Folder: one holding only this file and what is under it. */
58
+ export const NowhereHere: Story = {
59
+ name: 'Nowhere here',
60
+ args: { places: [] },
61
+ }
62
+
63
+ /** Another Folder could not be read: the section's empty line, with Try again. */
64
+ export const FolderUnreadable: Story = {
65
+ name: 'Folder unreadable',
66
+ args: { places: [], placesIn: (): Promise<readonly MovePlace[]> => Promise.reject(new Error('down')) },
67
+ play: pickSteer,
68
+ }
69
+
70
+ /** Another Folder, still being read: the second list says so and waits. */
71
+ export const ReadingAFolder: Story = {
72
+ name: 'Reading a folder',
73
+ args: { placesIn: () => new Promise<readonly MovePlace[]>(() => {}) },
74
+ play: pickSteer,
75
+ }
76
+
77
+ /** A file whose parent is one kind: the empty place is "none", and nothing is chosen for the person. */
78
+ export const UnderNone: Story = {
79
+ name: 'Under none',
80
+ args: { startAtTop: false, topLabel: 'None — under none of these', places: [TOP, PROJECT] },
81
+ }
82
+
83
+ /** The Folders are still being read: the list says so. */
84
+ export const ReadingFolders: Story = {
85
+ name: 'Reading folders',
86
+ args: { folders: undefined },
87
+ }
88
+
89
+ /** No Folder to offer: said in the dialog's body, and Move stays greyed. */
90
+ export const NoOtherFolder: Story = {
91
+ name: 'No other folder',
92
+ args: { folders: [FOLDERS[0]], places: undefined, placesIn: undefined },
93
+ }
94
+
95
+ /** Another app's words, opening on the Folder the app chose. */
96
+ export const AnotherAppsWords: Story = {
97
+ name: 'Another app’s words',
98
+ args: {
99
+ heading: 'Move to Folder',
100
+ folderLabel: 'Destination Folder',
101
+ noFolder: 'There is no other Folder it can be moved to.',
102
+ description: 'Only the Folder it is listed in changes. Its issues and its conversation stay exactly as they are.',
103
+ title: 'Folders: navigation for the whole suite',
104
+ places: undefined,
105
+ placesIn: undefined,
106
+ startIn: 'steer',
107
+ },
108
+ }
109
+
110
+ /** Moving: the button says so, and everything waits for the answer. */
111
+ export const Moving: Story = {
112
+ args: { onMove: () => new Promise<boolean>(() => {}) },
113
+ play: async ({ canvasElement }) => {
114
+ await userEvent.click(within(canvasElement.ownerDocument.body).getByRole('button', { name: 'Move' }))
115
+ },
116
+ }
117
+
118
+ /** The move was refused: it stays open, and the caller has said why. */
119
+ export const Refused: Story = {
120
+ args: { onMove: async () => false },
121
+ }