@estiva-app/ui 0.74.1 → 0.76.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 (87) hide show
  1. package/dist/CardUnder.d.ts +10 -0
  2. package/dist/CardUnder.d.ts.map +1 -0
  3. package/dist/CommentBox.d.ts +119 -0
  4. package/dist/CommentBox.d.ts.map +1 -0
  5. package/dist/ComposeBox.d.ts +2 -0
  6. package/dist/ComposeBox.d.ts.map +1 -1
  7. package/dist/InlineChip.d.ts +2 -0
  8. package/dist/InlineChip.d.ts.map +1 -1
  9. package/dist/LinkCard.d.ts +17 -0
  10. package/dist/LinkCard.d.ts.map +1 -0
  11. package/dist/LinkChip.d.ts +8 -0
  12. package/dist/LinkChip.d.ts.map +1 -0
  13. package/dist/LinkParts.d.ts +45 -0
  14. package/dist/LinkParts.d.ts.map +1 -0
  15. package/dist/LinkPreview.d.ts +21 -0
  16. package/dist/LinkPreview.d.ts.map +1 -0
  17. package/dist/LinkRow.d.ts +24 -0
  18. package/dist/LinkRow.d.ts.map +1 -0
  19. package/dist/PartCard.d.ts +32 -0
  20. package/dist/PartCard.d.ts.map +1 -0
  21. package/dist/ReactionRow.d.ts +44 -0
  22. package/dist/ReactionRow.d.ts.map +1 -0
  23. package/dist/Skeleton.d.ts +12 -2
  24. package/dist/Skeleton.d.ts.map +1 -1
  25. package/dist/editor.d.ts +1 -0
  26. package/dist/editor.d.ts.map +1 -1
  27. package/dist/editor.js +2340 -2043
  28. package/dist/editor.js.map +4 -4
  29. package/dist/eslint/index.js +1 -0
  30. package/dist/eslint/index.js.map +2 -2
  31. package/dist/eslint/no-restyled-part.d.ts.map +1 -1
  32. package/dist/index.d.ts +9 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +546 -72
  35. package/dist/index.js.map +4 -4
  36. package/dist/linked.d.ts +168 -0
  37. package/dist/linked.d.ts.map +1 -0
  38. package/dist/linked.examples.d.ts +27 -0
  39. package/dist/linked.examples.d.ts.map +1 -0
  40. package/package.json +6 -2
  41. package/registry.json +1129 -37
  42. package/src/CardUnder.mdx +53 -0
  43. package/src/CardUnder.stories.tsx +45 -0
  44. package/src/CardUnder.test.tsx +40 -0
  45. package/src/CardUnder.tsx +45 -0
  46. package/src/CommentBox.mdx +83 -0
  47. package/src/CommentBox.stories.tsx +218 -0
  48. package/src/CommentBox.test.tsx +265 -0
  49. package/src/CommentBox.tsx +472 -0
  50. package/src/ComposeBox.tsx +5 -4
  51. package/src/InlineChip.tsx +2 -0
  52. package/src/LinkCard.mdx +58 -0
  53. package/src/LinkCard.stories.tsx +68 -0
  54. package/src/LinkCard.test.tsx +103 -0
  55. package/src/LinkCard.tsx +209 -0
  56. package/src/LinkChip.mdx +51 -0
  57. package/src/LinkChip.stories.tsx +40 -0
  58. package/src/LinkChip.test.tsx +83 -0
  59. package/src/LinkChip.tsx +51 -0
  60. package/src/LinkParts.mdx +49 -0
  61. package/src/LinkParts.stories.tsx +61 -0
  62. package/src/LinkParts.tsx +147 -0
  63. package/src/LinkPreview.mdx +47 -0
  64. package/src/LinkPreview.stories.tsx +38 -0
  65. package/src/LinkPreview.tsx +55 -0
  66. package/src/LinkRow.mdx +47 -0
  67. package/src/LinkRow.stories.tsx +49 -0
  68. package/src/LinkRow.test.tsx +38 -0
  69. package/src/LinkRow.tsx +107 -0
  70. package/src/PartCard.mdx +43 -0
  71. package/src/PartCard.stories.tsx +35 -0
  72. package/src/PartCard.test.tsx +30 -0
  73. package/src/PartCard.tsx +59 -0
  74. package/src/ReactionRow.mdx +50 -0
  75. package/src/ReactionRow.stories.tsx +91 -0
  76. package/src/ReactionRow.test.tsx +68 -0
  77. package/src/ReactionRow.tsx +118 -0
  78. package/src/Skeleton.tsx +7 -3
  79. package/src/editor.ts +11 -0
  80. package/src/eslint/no-native-title.test.ts +3 -2
  81. package/src/eslint/no-restyled-part.ts +1 -0
  82. package/src/index.ts +26 -0
  83. package/src/linked.examples.ts +107 -0
  84. package/src/linked.test.ts +58 -0
  85. package/src/linked.ts +217 -0
  86. package/src/registry/registry.test.ts +8 -8
  87. package/stories/Choosing.mdx +10 -1
@@ -0,0 +1,53 @@
1
+ import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
+ import * as CardUnderStories from './CardUnder.stories'
3
+
4
+ <Meta of={CardUnderStories} />
5
+
6
+ # CardUnder
7
+
8
+ The one card added under a piece of text, and the ✕ that removes it.
9
+
10
+ <Canvas of={CardUnderStories.WhileWriting} />
11
+
12
+ ## When
13
+
14
+ - **while writing** — under the box: the ✕ always shows.
15
+ - **after sending** — `revealOnHover`: the ✕ shows when the pointer is over the card or the ✕ has focus, and always on a screen that cannot hover, so a tap reaches it.
16
+ - **no ✕** — no `onRemove`: to anyone but who wrote it.
17
+
18
+ <Canvas of={CardUnderStories.AfterSending} />
19
+
20
+ ## When not
21
+
22
+ - A link alone on its line, with no card chosen → **LinkRow**.
23
+ - A part of something longer: it has no ✕ → **PartCard**.
24
+
25
+ ## How
26
+
27
+ ```tsx
28
+ import { CardUnder } from '@estiva-app/ui'
29
+
30
+ <CardUnder link={link} onRemove={isAuthor ? removeCard : undefined} revealOnHover={sent} />
31
+ ```
32
+
33
+ - **Which link gets the card is the app's**, by the rule every app reads by (`defaultCardOf` in `@estiva-app/protocol`). This draws the one it is given.
34
+ - `onRemove` is the app's: before sending it drops the card from what will be sent; after, it sends the edit that removes it.
35
+ - It is at most 480px wide.
36
+
37
+ ## What it owns
38
+
39
+ | It does | So you never write |
40
+ |---|---|
41
+ | Places the ✕ at the card's top corner | a remove button of your own |
42
+ | Reveals the ✕ on hover and focus, and always shows it on touch | a hover or touch check |
43
+
44
+ ## Keys
45
+
46
+ | Key | Does |
47
+ |---|---|
48
+ | Tab | Reaches the ✕, and shows it when it was waiting for hover |
49
+ | Enter, Space | Removes the card |
50
+
51
+ ## Props
52
+
53
+ <Controls of={CardUnderStories.NoRemove} />
@@ -0,0 +1,45 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { useState } from 'react'
3
+ import { Button } from './Button'
4
+ import { CardUnder } from './CardUnder'
5
+ import { ITEM, LOADING, ready, SAID, UNAVAILABLE } from './linked.examples'
6
+
7
+ const meta = {
8
+ title: 'Components/CardUnder',
9
+ component: CardUnder,
10
+ parameters: { layout: 'padded' },
11
+ args: { link: ready(ITEM) },
12
+ } satisfies Meta<typeof CardUnder>
13
+
14
+ export default meta
15
+ type Story = StoryObj<typeof meta>
16
+
17
+ /** Under a box being written in: the ✕ always shows. Press it to remove the card. */
18
+ export const WhileWriting: Story = {
19
+ render: (args) => {
20
+ const [removed, setRemoved] = useState(false)
21
+ if (removed) return <Button onClick={() => setRemoved(false)}>Put it back</Button>
22
+ return <CardUnder {...args} onRemove={() => setRemoved(true)} />
23
+ },
24
+ }
25
+
26
+ /** Under text already sent: the ✕ shows on hover or focus, and always on a screen that cannot hover. */
27
+ export const AfterSending: Story = {
28
+ render: (args) => {
29
+ const [removed, setRemoved] = useState(false)
30
+ if (removed) return <Button onClick={() => setRemoved(false)}>Put it back</Button>
31
+ return <CardUnder {...args} revealOnHover onRemove={() => setRemoved(true)} />
32
+ },
33
+ }
34
+
35
+ /** To anyone but who wrote it: no ✕. */
36
+ export const NoRemove: Story = {}
37
+
38
+ /** Words a person wrote, as the card. */
39
+ export const WordsAPersonWrote: Story = { args: { link: ready(SAID) }, render: (args) => <CardUnder {...args} onRemove={() => {}} /> }
40
+
41
+ /** Still being looked up: at the card's height, with its ✕. */
42
+ export const Loading: Story = { args: { link: LOADING }, render: (args) => <CardUnder {...args} onRemove={() => {}} /> }
43
+
44
+ /** Deleted, or not this reader's to see. */
45
+ export const NotAvailable: Story = { args: { link: UNAVAILABLE }, render: (args) => <CardUnder {...args} onRemove={() => {}} /> }
@@ -0,0 +1,40 @@
1
+ // @vitest-environment jsdom
2
+ /** What the CardUnder page claims, pinned: the ✕ removes the card, by pointer and by keyboard, and only where it is given. */
3
+ import { cleanup, render, screen } from '@testing-library/react'
4
+ import userEvent from '@testing-library/user-event'
5
+ import { afterEach, describe, expect, it, vi } from 'vitest'
6
+ import { CardUnder } from './CardUnder'
7
+ import { ITEM, ready } from './linked.examples'
8
+
9
+ afterEach(cleanup)
10
+
11
+ describe('CardUnder', () => {
12
+ it('draws the card it is given', () => {
13
+ render(<CardUnder link={ready(ITEM)} />)
14
+ expect(screen.getByRole('link', { name: ITEM.title })).toBeTruthy()
15
+ })
16
+
17
+ it('removes the card when the ✕ is pressed', async () => {
18
+ const user = userEvent.setup()
19
+ const onRemove = vi.fn()
20
+ render(<CardUnder link={ready(ITEM)} onRemove={onRemove} />)
21
+ await user.click(screen.getByRole('button', { name: 'Remove card' }))
22
+ expect(onRemove).toHaveBeenCalledTimes(1)
23
+ })
24
+
25
+ it('reaches the ✕ from the keyboard once sent, and removes the card with Enter', async () => {
26
+ const user = userEvent.setup()
27
+ const onRemove = vi.fn()
28
+ render(<CardUnder link={ready({ ...ITEM, conversation: undefined, status: undefined, owner: undefined })} onRemove={onRemove} revealOnHover />)
29
+ await user.tab()
30
+ await user.tab()
31
+ expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Remove card' }))
32
+ await user.keyboard('{Enter}')
33
+ expect(onRemove).toHaveBeenCalledTimes(1)
34
+ })
35
+
36
+ it('has no ✕ for anyone but who wrote it', () => {
37
+ render(<CardUnder link={ready(ITEM)} />)
38
+ expect(screen.queryByRole('button', { name: 'Remove card' })).toBeNull()
39
+ })
40
+ })
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The one card added under a piece of text, and the ✕ that removes it (why:
3
+ * https://github.com/estiva-app/estiva-docs/blob/main/decisions/where-a-link-sits-and-which-file-gets-the-card.md).
4
+ *
5
+ * Under a box being written in, the ✕ always shows. Under text already sent
6
+ * (`revealOnHover`) it shows when the pointer is over the card or the ✕ has
7
+ * focus, and always on a screen that cannot hover, so a tap reaches it (Miky,
8
+ * 16 Oct, kickoff).
9
+ */
10
+ import { IconX } from '@tabler/icons-react'
11
+ import { cn } from './cn'
12
+ import { IconButton } from './IconButton'
13
+ import { LinkCard } from './LinkCard'
14
+ import type { LinkState } from './linked'
15
+
16
+ export interface CardUnderProps {
17
+ link: LinkState
18
+ /** Draws the ✕. Without it the card shows with none, as it does to anyone but the author. */
19
+ onRemove?: () => void
20
+ /** The ✕ waits for hover or focus: under text already sent. Always shown on a screen that cannot hover. */
21
+ revealOnHover?: boolean
22
+ }
23
+
24
+ export function CardUnder({ link, onRemove, revealOnHover = false }: CardUnderProps) {
25
+ return (
26
+ <div className="group/card flex max-w-[480px] items-start gap-1">
27
+ <div className="min-w-0 flex-1">
28
+ <LinkCard link={link} />
29
+ </div>
30
+ {onRemove && (
31
+ // At the card's top corner: halfway down a tall card a ✕ reads as belonging to nothing.
32
+ <div
33
+ className={cn(
34
+ 'flex shrink-0 self-start pt-2',
35
+ revealOnHover && 'opacity-0 transition-opacity group-hover/card:opacity-100 focus-within:opacity-100 [@media(hover:none)]:opacity-100',
36
+ )}
37
+ >
38
+ <IconButton aria-label="Remove card" tooltip="Remove card" onClick={onRemove}>
39
+ <IconX size={16} />
40
+ </IconButton>
41
+ </div>
42
+ )}
43
+ </div>
44
+ )
45
+ }
@@ -0,0 +1,83 @@
1
+ import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
+ import * as CommentBoxStories from './CommentBox.stories'
3
+
4
+ <Meta of={CommentBoxStories} />
5
+
6
+ # CommentBox
7
+
8
+ The one box every app writes a comment, a reply and a line of a conversation in: `@`, `!@`, `[` and `/`, the keys, drafts, files, editing, sending and a refused send. The app supplies its people, its `[` sections, its `/` Insert rows and a send.
9
+
10
+ <Canvas of={CommentBoxStories.Empty} />
11
+
12
+ ## When
13
+
14
+ - **Writing anything that is sent**, in every app: a comment, a reply, a line in a conversation. The same box writes all of them.
15
+ - `showsAtOnce` when the app shows a send before the relay answers: the box empties at once, and a refusal puts the words back. Without it the box holds the words, shut, until the answer.
16
+ - `edit` to change something already sent: the same box with Cancel and Save, and only its keys on the left.
17
+ - `upload` to offer files: the paperclip, `/` → File, a pasted picture and a dropped file.
18
+ - `closed` where nothing can be written (archived, signed out): a line saying why, in the box's place. No greyed box.
19
+
20
+ <Canvas of={CommentBoxStories.Refused} />
21
+
22
+ ## When not
23
+
24
+ - Writing a document in place → the editor itself, with **EditorBlockHandle** and **SelectionToolbar**. Nothing is sent.
25
+ - A box with nothing of this — no lists, no drafts, no files → **ComposeBox**, with the app's own editor. CommentBox is built on it.
26
+ - One line of plain text in a form → **TextInput** or **Textarea**.
27
+
28
+ ## How
29
+
30
+ ```tsx
31
+ import { CommentBox, commentBoxRows } from '@estiva-app/ui/editor'
32
+
33
+ // composerDraft, createDraftStore, draftKeys and composerText: @estiva-app/conversation, which this package does not depend on.
34
+ const draft = composerDraft(createDraftStore(localStorage), draftKeys.thread(rootId), labels)
35
+
36
+ <CommentBox
37
+ key={rootId}
38
+ label="Reply"
39
+ placeholder="Reply…"
40
+ people={people}
41
+ references={sectionsFor}
42
+ insert={[commentBoxRows.file, commentBoxRows.mention, commentBoxRows.urgent, commentBoxRows.reference]}
43
+ code="block"
44
+ draft={draft}
45
+ upload={uploadOne}
46
+ send={async (body, files) => {
47
+ const { text, urgent } = composerText(body)
48
+ return publish(text, urgent, files) // { accepted: true } or { accepted: false, reason }
49
+ }}
50
+ />
51
+ ```
52
+
53
+ - **It speaks the editor's document.** The text a document sends, and the document an edit or a draft opens with, are `@estiva-app/conversation`'s: `composerText`, `composerDocument`, `composerDraft`. Never write marker text here.
54
+ - **`send` answers.** Resolve `{ accepted: false, reason }` and the words come back with "Not sent: *reason*". A thrown send is a refusal too.
55
+ - **`label` is required**: the editor's accessible name.
56
+ - **`insert` is the app's Insert rows**, after the shared Format section: `commentBoxRows` and the app's own. An edit drops File and Urgent itself; with no `upload` there is no File.
57
+ - **Give the box a `key` per destination.** The editor, the rows and `code` are made once, as the box opens; a new thread is a new box.
58
+ - A send shown at once and refused after its box went away writes the words into its draft instead.
59
+
60
+ ## What it owns
61
+
62
+ It does these by itself. Write none of them around it.
63
+
64
+ | It does | So you never write |
65
+ |---|---|
66
+ | `@`, `!@`, `[` and `/`, with their lists and chips | the triggers and their extensions |
67
+ | Enter and Ctrl/Cmd+Enter send; Escape cancels an edit | key handlers |
68
+ | Holding the words until the answer, or showing the send at once | a sending state |
69
+ | A refusal: the words back, and a line under the box | a toast, or putting text back |
70
+ | The draft, written as you type and forgotten once sent | an update listener |
71
+ | Files: picking, pasting, dropping, uploading, failing; Send waits | a file list |
72
+ | The read-only line | a disabled box |
73
+
74
+ ## Keys
75
+
76
+ | Key | What it does |
77
+ |---|---|
78
+ | Enter | Sends; saves an edit. With a list open, picks the row. |
79
+ | Ctrl/Cmd+Enter | Sends, as Enter does. |
80
+ | Shift+Enter | A new line; in a list, a new item. |
81
+ | Escape | Cancels an edit. With a list open, closes the list first. |
82
+
83
+ <Controls />
@@ -0,0 +1,218 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { useState } from 'react'
3
+ import type { JSONContent } from '@tiptap/react'
4
+ import { userEvent, within } from 'storybook/test'
5
+ import { Button } from './Button'
6
+ import { CommentBox, commentBoxRows, type CommentBoxDraft, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
7
+ import type { CaptionedItem, MentionPerson, ReferenceSection } from './ComposerTriggers'
8
+ import { Kbd } from './Kbd'
9
+
10
+ /**
11
+ * The one box every app writes in. Every story is live: write, open a list,
12
+ * send. A send is answered after a moment; write "refuse" anywhere to see a
13
+ * refusal. Pick the theme in the toolbar.
14
+ */
15
+ const meta = {
16
+ title: 'Primitives/CommentBox',
17
+ component: CommentBox,
18
+ parameters: { layout: 'padded' },
19
+ decorators: [
20
+ (Story) => (
21
+ <div className="w-[480px]">
22
+ <Story />
23
+ </div>
24
+ ),
25
+ ],
26
+ } satisfies Meta<typeof CommentBox>
27
+
28
+ export default meta
29
+ type Story = StoryObj
30
+
31
+ const PEOPLE: MentionPerson[] = ['one', 'two', 'three', 'four'].map((n, i) => ({ id: n, name: `Person ${n}`, pubkey: String(i + 1).repeat(64) }))
32
+
33
+ const ITEMS: CaptionedItem[] = ['one', 'two', 'three'].map((n, i) => ({
34
+ id: String(i + 5).repeat(64),
35
+ label: 'Label',
36
+ snippet: `Item ${n}`,
37
+ uri: `nostr:nevent1item${n}`,
38
+ }))
39
+
40
+ const references = (query: string): ReferenceSection[] => [
41
+ { label: 'Group one', items: ITEMS.filter((item) => item.snippet.toLowerCase().includes(query.toLowerCase())) },
42
+ ]
43
+
44
+ const INSERT = [commentBoxRows.file, commentBoxRows.mention, commentBoxRows.urgent, commentBoxRows.reference]
45
+
46
+ const plain = (body: JSONContent): string => (body.text ?? '') + (body.content ?? []).map(plain).join(' ')
47
+
48
+ /** A relay that answers after a moment, and refuses whatever says "refuse". */
49
+ const answering = (body: JSONContent): Promise<SendAnswer> =>
50
+ new Promise((resolve) =>
51
+ setTimeout(() => resolve(/refuse/i.test(plain(body)) ? { accepted: false, reason: 'rate-limited, try again in a minute' } : { accepted: true }), 900),
52
+ )
53
+
54
+ /** A relay that never answers. */
55
+ const silent = (): Promise<SendAnswer> => new Promise(() => {})
56
+
57
+ const uploads =
58
+ (answer: 'ready' | 'failed' | 'never') =>
59
+ (file: File): Promise<UploadAnswer> =>
60
+ answer === 'never'
61
+ ? new Promise(() => {})
62
+ : new Promise((resolve) =>
63
+ setTimeout(() => resolve(answer === 'ready' ? { accepted: true, value: file.name } : { accepted: false, reason: 'The file is larger than 20 MB.' }), 1800),
64
+ )
65
+
66
+ const PLACEHOLDER = (
67
+ <>
68
+ <span>Write, or type</span>
69
+ <Kbd>/</Kbd>
70
+ <span>for commands</span>
71
+ </>
72
+ )
73
+
74
+ const DRAFT: JSONContent = {
75
+ type: 'doc',
76
+ content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Half written, and still here when you come back' }] }],
77
+ }
78
+
79
+ const WITH_CHIPS: JSONContent = {
80
+ type: 'doc',
81
+ content: [
82
+ {
83
+ type: 'paragraph',
84
+ content: [
85
+ { type: 'text', text: 'Agreed with ' },
86
+ { type: 'mention', attrs: { id: 'two', label: 'Person two', pubkey: '2'.repeat(64) } },
87
+ { type: 'text', text: ', as in ' },
88
+ { type: 'captionedReference', attrs: { id: ITEMS[0].id, label: 'Label', snippet: 'Item one', uri: ITEMS[0].uri } },
89
+ ],
90
+ },
91
+ ],
92
+ }
93
+
94
+ /** The sent lines above the box, so a send can be seen to land. */
95
+ function Live({ start, ...props }: Partial<CommentBoxProps> & { start?: JSONContent }) {
96
+ const [sent, setSent] = useState<string[]>([])
97
+ const [kept] = useState(() => {
98
+ let body = start
99
+ const draft: CommentBoxDraft = { read: () => body, write: (b) => (body = b), clear: () => (body = undefined) }
100
+ return draft
101
+ })
102
+ const [open, setOpen] = useState(true)
103
+ return (
104
+ <div className="flex flex-col gap-3">
105
+ {sent.map((line, i) => (
106
+ <p key={i} className="text-body-2 text-text-primary">
107
+ {line}
108
+ </p>
109
+ ))}
110
+ {open ? (
111
+ <CommentBox
112
+ people={PEOPLE}
113
+ references={references}
114
+ insert={INSERT}
115
+ send={answering}
116
+ label="Write"
117
+ placeholder={PLACEHOLDER}
118
+ draft={kept}
119
+ upload={uploads('ready')}
120
+ onSent={(body) => setSent((all) => [...all, plain(body)])}
121
+ {...props}
122
+ />
123
+ ) : (
124
+ <p className="text-body-2 text-text-muted">The box is closed. Open it again: the words are kept.</p>
125
+ )}
126
+ {start && (
127
+ <div>
128
+ <Button variant="outlined" size="small" onClick={() => setOpen((o) => !o)}>
129
+ {open ? 'Close the box' : 'Open the box'}
130
+ </Button>
131
+ </div>
132
+ )}
133
+ </div>
134
+ )
135
+ }
136
+
137
+ const typeInto = (text: string) =>
138
+ async function play({ canvasElement }: { canvasElement: HTMLElement }) {
139
+ const box = within(canvasElement).getByRole('textbox', { name: 'Write' })
140
+ await userEvent.click(box)
141
+ await userEvent.keyboard(text)
142
+ }
143
+
144
+ const pickAFile = async ({ canvasElement }: { canvasElement: HTMLElement }) => {
145
+ const input = canvasElement.querySelector('input[type=file]') as HTMLInputElement
146
+ await userEvent.upload(input, new File(['placeholder'], 'plan.pdf', { type: 'application/pdf' }))
147
+ }
148
+
149
+ /** Nothing written. */
150
+ export const Empty: Story = { render: () => <Live /> }
151
+
152
+ /** Words half written. Close the box and open it again: they are still there. */
153
+ export const WithADraft: Story = { render: () => <Live start={DRAFT} /> }
154
+
155
+ /** `@`: the people the app supplies. */
156
+ export const MentionOpen: Story = { render: () => <Live />, play: typeInto('Asking @') }
157
+
158
+ /** `!@`: the same people, urgently. */
159
+ export const UrgentOpen: Story = { render: () => <Live />, play: typeInto('Asking !@') }
160
+
161
+ /** `[`: what the app's sections list. */
162
+ export const ReferenceOpen: Story = { render: () => <Live />, play: typeInto('As in [[') }
163
+
164
+ /** `/`: the shared Format section, then the app's Insert rows. */
165
+ export const CommandsOpen: Story = { render: () => <Live />, play: typeInto('/') }
166
+
167
+ /** Held until the relay answers: the words stay, shut. */
168
+ export const Sending: Story = { render: () => <Live send={silent} />, play: typeInto('On its way{Enter}') }
169
+
170
+ /** The relay said no: the words are back in the box, and a line says why. */
171
+ export const Refused: Story = { render: () => <Live />, play: typeInto('Please refuse this{Enter}') }
172
+
173
+ /** Shown at once: the box empties now, and a refusal puts the words back. Write "refuse" to see it. */
174
+ export const ShownAtOnce: Story = { render: () => <Live showsAtOnce /> }
175
+
176
+ /** Editing something sent: the chips stay chips; only the keys on the left. */
177
+ export const Editing: Story = {
178
+ render: () => <Live edit={{ body: WITH_CHIPS, onCancel: () => {}, onSave: answering }} />,
179
+ }
180
+
181
+ /** A save the relay refused: "Saving…" while it waits, then a line under the box; the changes stay. */
182
+ export const EditingRefused: Story = {
183
+ render: () => (
184
+ <Live
185
+ edit={{
186
+ body: WITH_CHIPS,
187
+ onCancel: () => {},
188
+ onSave: () => new Promise((resolve) => setTimeout(() => resolve({ accepted: false, reason: 'rate-limited, try again in a minute' }), 900)),
189
+ }}
190
+ />
191
+ ),
192
+ play: typeInto('{Enter}'),
193
+ }
194
+
195
+ /** A file uploading: Send waits for it. */
196
+ export const FileUploading: Story = { render: () => <Live upload={uploads('never')} />, play: pickAFile }
197
+
198
+ /** A file that failed: it says why and can be removed. */
199
+ export const FileFailed: Story = { render: () => <Live upload={uploads('failed')} />, play: pickAFile }
200
+
201
+ /** Read-only, archived: a line in the box's place. */
202
+ export const ReadOnlyArchived: Story = { render: () => <Live closed={{ reason: 'This is archived, so nothing new can be written here.' }} /> }
203
+
204
+ /** Read-only, signed out: a line in the box's place. */
205
+ export const ReadOnlySignedOut: Story = { render: () => <Live closed={{ reason: 'Sign in to write here.' }} /> }
206
+
207
+ /** The narrowest column it sits in, 320px, with a file uploading. */
208
+ export const Narrow: Story = {
209
+ decorators: [
210
+ (Story) => (
211
+ <div className="w-[320px]">
212
+ <Story />
213
+ </div>
214
+ ),
215
+ ],
216
+ render: () => <Live upload={uploads('never')} start={DRAFT} />,
217
+ play: pickAFile,
218
+ }