@estiva-app/ui 0.75.0 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/ui",
3
- "version": "0.75.0",
3
+ "version": "0.76.0",
4
4
  "description": "Estiva's design tokens (the contract) and a small set of primitives (a convenience) for every Estiva app.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -92,7 +92,8 @@
92
92
  "@tiptap/pm": "^3.22.1",
93
93
  "@tiptap/react": "^3.22.1",
94
94
  "@tiptap/suggestion": "^3.22.1",
95
- "@tiptap/extension-code-block-lowlight": "^3.22.1"
95
+ "@tiptap/extension-code-block-lowlight": "^3.22.1",
96
+ "@tiptap/starter-kit": "^3.22.1"
96
97
  },
97
98
  "peerDependenciesMeta": {
98
99
  "eslint": {
@@ -121,6 +122,9 @@
121
122
  },
122
123
  "@tiptap/extension-code-block-lowlight": {
123
124
  "optional": true
125
+ },
126
+ "@tiptap/starter-kit": {
127
+ "optional": true
124
128
  }
125
129
  },
126
130
  "devDependencies": {
package/registry.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "kind": "package",
5
5
  "repo": "estiva-ui",
6
6
  "package": "@estiva-app/ui",
7
- "packageVersion": "0.75.0",
8
- "exports": 197,
9
- "typeExports": 185,
7
+ "packageVersion": "0.76.0",
8
+ "exports": 202,
9
+ "typeExports": 195,
10
10
  "files": null
11
11
  },
12
12
  "storybook": {
@@ -15,6 +15,65 @@
15
15
  "devUrl": "http://localhost:6008"
16
16
  },
17
17
  "entries": [
18
+ {
19
+ "name": "AddReactionButton",
20
+ "repo": "estiva-ui",
21
+ "kind": "component",
22
+ "importPath": "@estiva-app/ui",
23
+ "sourceFile": "src/ReactionRow.tsx",
24
+ "purpose": "The add button: `ReactionPicker` opens over it.",
25
+ "purposeFrom": "comment",
26
+ "props": [
27
+ {
28
+ "name": "options",
29
+ "takes": "readonly ReactionOption[]",
30
+ "required": true,
31
+ "note": "The emoji offered, each named."
32
+ },
33
+ {
34
+ "name": "onPick",
35
+ "takes": "a handler",
36
+ "required": true,
37
+ "note": null
38
+ },
39
+ {
40
+ "name": "className",
41
+ "takes": "text",
42
+ "required": false,
43
+ "note": null
44
+ }
45
+ ],
46
+ "variants": [],
47
+ "ownsBehaviours": [
48
+ {
49
+ "id": "portal",
50
+ "behaviour": "Floats on top of the page"
51
+ },
52
+ {
53
+ "id": "press-outside",
54
+ "behaviour": "Closes on a press outside"
55
+ },
56
+ {
57
+ "id": "page-keys",
58
+ "behaviour": "Takes its keys by itself"
59
+ },
60
+ {
61
+ "id": "focus",
62
+ "behaviour": "Holds focus inside while open, and gives it back"
63
+ },
64
+ {
65
+ "id": "follow",
66
+ "behaviour": "Stays attached to its anchor on scroll and resize"
67
+ }
68
+ ],
69
+ "status": "stable",
70
+ "migrationStage": null,
71
+ "docsId": "primitives-reactionrow--docs",
72
+ "storyId": "primitives-reactionrow--default",
73
+ "docPage": null,
74
+ "app": null,
75
+ "looks": []
76
+ },
18
77
  {
19
78
  "name": "anchorOfSelection",
20
79
  "repo": "estiva-ui",
@@ -1910,6 +1969,174 @@
1910
1969
  "app": null,
1911
1970
  "looks": []
1912
1971
  },
1972
+ {
1973
+ "name": "CommentBox",
1974
+ "repo": "estiva-ui",
1975
+ "kind": "component",
1976
+ "importPath": "@estiva-app/ui/editor",
1977
+ "sourceFile": "src/CommentBox.tsx",
1978
+ "purpose": "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.",
1979
+ "purposeFrom": "page",
1980
+ "props": [
1981
+ {
1982
+ "name": "people",
1983
+ "takes": "readonly MentionPerson[]",
1984
+ "required": true,
1985
+ "note": "Who `@` and `!@` offer."
1986
+ },
1987
+ {
1988
+ "name": "references",
1989
+ "takes": "a handler",
1990
+ "required": false,
1991
+ "note": "What `[` lists for what was typed, already in the app's order."
1992
+ },
1993
+ {
1994
+ "name": "referencesChanged",
1995
+ "takes": "a handler",
1996
+ "required": false,
1997
+ "note": "Called with a listener while `[` is open; call it when `references` would answer differently (a search landed)."
1998
+ },
1999
+ {
2000
+ "name": "referenceIcon",
2001
+ "takes": "a handler",
2002
+ "required": false,
2003
+ "note": "A `[` row's and chip's 16px icon from what it points at; absent, a neutral square."
2004
+ },
2005
+ {
2006
+ "name": "insert",
2007
+ "takes": "readonly SlashCommand[]",
2008
+ "required": false,
2009
+ "note": "The app's own `/` Insert rows, after the shared Format section: {@link commentBoxRows} and its own."
2010
+ },
2011
+ {
2012
+ "name": "code",
2013
+ "takes": "CodeFormat",
2014
+ "required": false,
2015
+ "note": "`/` → Code: a mark inside the line, or a block."
2016
+ },
2017
+ {
2018
+ "name": "send",
2019
+ "takes": "a handler",
2020
+ "required": true,
2021
+ "note": "Send what is written, with the files that are ready; resolves with the relay's answer."
2022
+ },
2023
+ {
2024
+ "name": "showsAtOnce",
2025
+ "takes": "true/false",
2026
+ "required": false,
2027
+ "note": "The app shows a send before the relay answers: the box empties at once, and a refusal puts the words back."
2028
+ },
2029
+ {
2030
+ "name": "label",
2031
+ "takes": "text",
2032
+ "required": true,
2033
+ "note": "The editor's accessible name: what the box is for."
2034
+ },
2035
+ {
2036
+ "name": "placeholder",
2037
+ "takes": "anything",
2038
+ "required": true,
2039
+ "note": "Said in the empty box."
2040
+ },
2041
+ {
2042
+ "name": "draft",
2043
+ "takes": "CommentBoxDraft",
2044
+ "required": false,
2045
+ "note": "Keeps what is written when the box goes away."
2046
+ },
2047
+ {
2048
+ "name": "edit",
2049
+ "takes": "CommentBoxEdit",
2050
+ "required": false,
2051
+ "note": "Editing something already sent."
2052
+ },
2053
+ {
2054
+ "name": "upload",
2055
+ "takes": "a handler",
2056
+ "required": false,
2057
+ "note": "Offers the paperclip, `/` → File, a pasted picture and a dropped file: uploads one, and answers."
2058
+ },
2059
+ {
2060
+ "name": "accept",
2061
+ "takes": "text",
2062
+ "required": false,
2063
+ "note": "The file picker's `accept`."
2064
+ },
2065
+ {
2066
+ "name": "closed",
2067
+ "takes": "{ reason: ReactNode }",
2068
+ "required": false,
2069
+ "note": "The box cannot write here (an archived file, signed out): a line saying why takes its place."
2070
+ },
2071
+ {
2072
+ "name": "referenceView",
2073
+ "takes": "ComponentType<ReferenceViewProps>",
2074
+ "required": false,
2075
+ "note": "How a `nostr:` reference the box holds is drawn — the app's own chip."
2076
+ },
2077
+ {
2078
+ "name": "extensions",
2079
+ "takes": "readonly AnyExtension[]",
2080
+ "required": false,
2081
+ "note": "The app's own extra editor extensions: link chips, highlights."
2082
+ },
2083
+ {
2084
+ "name": "autoFocus",
2085
+ "takes": "true/false",
2086
+ "required": false,
2087
+ "note": null
2088
+ },
2089
+ {
2090
+ "name": "onSent",
2091
+ "takes": "a handler",
2092
+ "required": false,
2093
+ "note": "Called with what was sent once it went out: at once when `showsAtOnce`, else on the answer."
2094
+ },
2095
+ {
2096
+ "name": "onRefused",
2097
+ "takes": "a handler",
2098
+ "required": false,
2099
+ "note": "Called when a send shown at once was refused, so the app takes it back."
2100
+ },
2101
+ {
2102
+ "name": "className",
2103
+ "takes": "text",
2104
+ "required": false,
2105
+ "note": null
2106
+ }
2107
+ ],
2108
+ "variants": [],
2109
+ "ownsBehaviours": [],
2110
+ "status": "stable",
2111
+ "migrationStage": null,
2112
+ "docsId": "primitives-commentbox--docs",
2113
+ "storyId": "primitives-commentbox--empty",
2114
+ "docPage": "src/CommentBox.mdx",
2115
+ "app": null,
2116
+ "looks": [
2117
+ "bg-bg-inset border border-border-default rounded-lg signal:transition-shadow signal:focus-within:border-border-focus signal:focus-within:shadow-focus-ring focus-within:border-border-strong transition-colors",
2118
+ "bg-bg-inset border border-border-default rounded-lg signal:transition-shadow signal:focus-within:border-border-focus signal:focus-within:shadow-focus-ring focus-within:border-border-strong transition-colors [&_.ProseMirror]:text-text-muted"
2119
+ ]
2120
+ },
2121
+ {
2122
+ "name": "commentBoxRows",
2123
+ "repo": "estiva-ui",
2124
+ "kind": "helper",
2125
+ "importPath": "@estiva-app/ui/editor",
2126
+ "sourceFile": "src/CommentBox.tsx",
2127
+ "purpose": "The `/` Insert rows the kit offers. Pass the ones an app can perform, in its order, with its own after them; an edit drops File and Urgent itself.",
2128
+ "purposeFrom": "comment",
2129
+ "props": [],
2130
+ "variants": [],
2131
+ "ownsBehaviours": [],
2132
+ "status": "stable",
2133
+ "migrationStage": null,
2134
+ "docsId": "primitives-commentbox--docs",
2135
+ "storyId": "primitives-commentbox--empty",
2136
+ "docPage": null,
2137
+ "app": null,
2138
+ "looks": []
2139
+ },
1913
2140
  {
1914
2141
  "name": "CommentCount",
1915
2142
  "repo": "estiva-ui",
@@ -6616,6 +6843,62 @@
6616
6843
  "app": null,
6617
6844
  "looks": []
6618
6845
  },
6846
+ {
6847
+ "name": "ReactionRow",
6848
+ "repo": "estiva-ui",
6849
+ "kind": "component",
6850
+ "importPath": "@estiva-app/ui",
6851
+ "sourceFile": "src/ReactionRow.tsx",
6852
+ "purpose": "The one row of reactions under a comment or a line, in every app: Reaction pills in the order first chosen, yours lit, who reacted on hover, and the add button with ReactionPicker.",
6853
+ "purposeFrom": "page",
6854
+ "props": [
6855
+ {
6856
+ "name": "reactions",
6857
+ "takes": "readonly ReactionCount[]",
6858
+ "required": true,
6859
+ "note": "Each emoji and who chose it, in the order first chosen."
6860
+ },
6861
+ {
6862
+ "name": "options",
6863
+ "takes": "readonly ReactionOption[]",
6864
+ "required": true,
6865
+ "note": "The emoji offered, each named; also what a pill's name is read from."
6866
+ },
6867
+ {
6868
+ "name": "nameOf",
6869
+ "takes": "a handler",
6870
+ "required": true,
6871
+ "note": "A reactor's name, as \"who reacted\" says it."
6872
+ },
6873
+ {
6874
+ "name": "viewer",
6875
+ "takes": "text",
6876
+ "required": false,
6877
+ "note": "Who is looking: their pills are lit, and \"who reacted\" says \"you\"."
6878
+ },
6879
+ {
6880
+ "name": "onToggle",
6881
+ "takes": "a handler",
6882
+ "required": false,
6883
+ "note": "Your reaction on or off. Absent, the row only shows (read-only, signed out)."
6884
+ },
6885
+ {
6886
+ "name": "className",
6887
+ "takes": "text",
6888
+ "required": false,
6889
+ "note": null
6890
+ }
6891
+ ],
6892
+ "variants": [],
6893
+ "ownsBehaviours": [],
6894
+ "status": "stable",
6895
+ "migrationStage": null,
6896
+ "docsId": "primitives-reactionrow--docs",
6897
+ "storyId": "primitives-reactionrow--default",
6898
+ "docPage": "src/ReactionRow.mdx",
6899
+ "app": null,
6900
+ "looks": []
6901
+ },
6619
6902
  {
6620
6903
  "name": "referenceAtSelection",
6621
6904
  "repo": "estiva-ui",
@@ -9173,6 +9456,38 @@
9173
9456
  "app": null,
9174
9457
  "looks": []
9175
9458
  },
9459
+ {
9460
+ "name": "whoReacted",
9461
+ "repo": "estiva-ui",
9462
+ "kind": "helper",
9463
+ "importPath": "@estiva-app/ui",
9464
+ "sourceFile": "src/ReactionRow.tsx",
9465
+ "purpose": "\"Person one, Person two and you reacted with Makes sense\".",
9466
+ "purposeFrom": "comment",
9467
+ "props": [
9468
+ {
9469
+ "name": "emoji",
9470
+ "takes": "text",
9471
+ "required": true,
9472
+ "note": null
9473
+ },
9474
+ {
9475
+ "name": "by",
9476
+ "takes": "readonly string[]",
9477
+ "required": true,
9478
+ "note": null
9479
+ }
9480
+ ],
9481
+ "variants": [],
9482
+ "ownsBehaviours": [],
9483
+ "status": "stable",
9484
+ "migrationStage": null,
9485
+ "docsId": "primitives-reactionrow--docs",
9486
+ "storyId": "primitives-reactionrow--default",
9487
+ "docPage": null,
9488
+ "app": null,
9489
+ "looks": []
9490
+ },
9176
9491
  {
9177
9492
  "name": "WithTooltip",
9178
9493
  "repo": "estiva-ui",
@@ -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
+ }