@estiva-app/ui 0.83.0 → 0.85.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/dist/CommentBox.d.ts +12 -3
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/commentBoxFrame.d.ts +93 -0
- package/dist/commentBoxFrame.d.ts.map +1 -0
- package/dist/editor.d.ts +0 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +445 -337
- package/dist/editor.js.map +4 -4
- package/dist/eslint/index.js +594 -559
- package/dist/eslint/index.js.map +4 -4
- package/dist/eslint/no-hand-rolled-behaviour.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/looks.d.ts +1 -1
- package/package.json +1 -1
- package/registry.json +16 -128
- package/src/CommentBox.mdx +15 -4
- package/src/CommentBox.stories.tsx +78 -2
- package/src/CommentBox.test.tsx +185 -3
- package/src/CommentBox.tsx +241 -76
- package/src/{ComposeBox.tsx → commentBoxFrame.tsx} +76 -25
- package/src/editor.ts +1 -1
- package/src/eslint/no-hand-rolled-behaviour.test.ts +27 -0
- package/src/eslint/no-hand-rolled-behaviour.ts +44 -0
- package/src/links.ts +4 -1
- package/src/looks.ts +1 -1
- package/src/registry/app.test.ts +3 -4
- package/src/registry/registry.test.ts +5 -5
- package/stories/Choosing.mdx +0 -1
- package/dist/ComposeBox.d.ts +0 -57
- package/dist/ComposeBox.d.ts.map +0 -1
- package/src/ComposeBox.mdx +0 -58
- package/src/ComposeBox.stories.tsx +0 -81
package/dist/links.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,cAAc,CAAA;AAenD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,cAAc,CAAA;AAenD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,qBAwCzB,CAAA;AAEF,wIAAwI;AACxI,eAAO,MAAM,MAAM,iEAIjB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,iEAatB,CAAA;AAcF,gIAAgI;AAChI,eAAO,MAAM,UAAU,kEAAkE,CAAA;AAKzF,4IAA4I;AAC5I,eAAO,MAAM,oBAAoB;;;;;CAAqG,CAAA;AAItI,eAAO,MAAM,SAAS,qBAuCpB,CAAA"}
|
package/dist/looks.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export declare const MENU_TRIGGER_CLASSES = "cursor-pointer rounded-md transitio
|
|
|
53
53
|
export declare const COLLAPSIBLE_PANEL_CLASSES = "h-[var(--collapsible-panel-height)] overflow-hidden transition-[height] duration-150 ease-out motion-reduce:transition-none data-[starting-style]:h-0 data-[ending-style]:h-0";
|
|
54
54
|
/**
|
|
55
55
|
* The box a message or a comment is written in: Peek's writing box (its
|
|
56
|
-
* `looks.ts`, Katerina 24 September), moved with
|
|
56
|
+
* `looks.ts`, Katerina 24 September), moved with the comment box. Inset, a hairline,
|
|
57
57
|
* 12px in, 16px between the text and the row under it; the focus ring in Signal.
|
|
58
58
|
*/
|
|
59
59
|
export declare const WRITING_BOX_CLASSES = "relative bg-bg-inset border border-border-default rounded-lg p-3 flex flex-col gap-4 signal:transition-shadow signal:focus-within:border-border-focus signal:focus-within:shadow-focus-ring";
|
package/package.json
CHANGED
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.
|
|
8
|
-
"exports":
|
|
9
|
-
"typeExports":
|
|
7
|
+
"packageVersion": "0.85.0",
|
|
8
|
+
"exports": 206,
|
|
9
|
+
"typeExports": 206,
|
|
10
10
|
"files": null
|
|
11
11
|
},
|
|
12
12
|
"storybook": {
|
|
@@ -2098,6 +2098,18 @@
|
|
|
2098
2098
|
"required": false,
|
|
2099
2099
|
"note": "Called when a send shown at once was refused, so the app takes it back."
|
|
2100
2100
|
},
|
|
2101
|
+
{
|
|
2102
|
+
"name": "marked",
|
|
2103
|
+
"takes": "a handler",
|
|
2104
|
+
"required": false,
|
|
2105
|
+
"note": "The bar down the text's left edge shows while this holds, besides while an urgent mention is in the box: the app's own marks (a highlight)."
|
|
2106
|
+
},
|
|
2107
|
+
{
|
|
2108
|
+
"name": "onEditor",
|
|
2109
|
+
"takes": "a handler",
|
|
2110
|
+
"required": false,
|
|
2111
|
+
"note": "Called with the box's editor once it is drawn, and with `null` as it goes: an app's launcher inserts into the box last used."
|
|
2112
|
+
},
|
|
2101
2113
|
{
|
|
2102
2114
|
"name": "className",
|
|
2103
2115
|
"takes": "text",
|
|
@@ -2113,10 +2125,7 @@
|
|
|
2113
2125
|
"storyId": "primitives-commentbox--empty",
|
|
2114
2126
|
"docPage": "src/CommentBox.mdx",
|
|
2115
2127
|
"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
|
-
]
|
|
2128
|
+
"looks": []
|
|
2120
2129
|
},
|
|
2121
2130
|
{
|
|
2122
2131
|
"name": "commentBoxRows",
|
|
@@ -2232,127 +2241,6 @@
|
|
|
2232
2241
|
"app": null,
|
|
2233
2242
|
"looks": []
|
|
2234
2243
|
},
|
|
2235
|
-
{
|
|
2236
|
-
"name": "COMPOSE_EDITOR_CLASSES",
|
|
2237
|
-
"repo": "estiva-ui",
|
|
2238
|
-
"kind": "helper",
|
|
2239
|
-
"importPath": "@estiva-app/ui/editor",
|
|
2240
|
-
"sourceFile": "src/ComposeBox.tsx",
|
|
2241
|
-
"purpose": "The editor's own classes inside the box: Peek's, rich text with no outline.",
|
|
2242
|
-
"purposeFrom": "comment",
|
|
2243
|
-
"props": [],
|
|
2244
|
-
"variants": [],
|
|
2245
|
-
"ownsBehaviours": [],
|
|
2246
|
-
"status": "stable",
|
|
2247
|
-
"migrationStage": null,
|
|
2248
|
-
"docsId": "primitives-composebox--docs",
|
|
2249
|
-
"storyId": "primitives-composebox--default",
|
|
2250
|
-
"docPage": null,
|
|
2251
|
-
"app": null,
|
|
2252
|
-
"looks": []
|
|
2253
|
-
},
|
|
2254
|
-
{
|
|
2255
|
-
"name": "ComposeBox",
|
|
2256
|
-
"repo": "estiva-ui",
|
|
2257
|
-
"kind": "component",
|
|
2258
|
-
"importPath": "@estiva-app/ui/editor",
|
|
2259
|
-
"sourceFile": "src/ComposeBox.tsx",
|
|
2260
|
-
"purpose": "The box a message, a reply or a comment is written in: the text, the selection strip over it, what is attached, the tools and Send.",
|
|
2261
|
-
"purposeFrom": "page",
|
|
2262
|
-
"props": [
|
|
2263
|
-
{
|
|
2264
|
-
"name": "editor",
|
|
2265
|
-
"takes": "Editor | null",
|
|
2266
|
-
"required": true,
|
|
2267
|
-
"note": "The app's editor, with `ComposeKeys` in its extensions and `COMPOSE_EDITOR_CLASSES` on it."
|
|
2268
|
-
},
|
|
2269
|
-
{
|
|
2270
|
-
"name": "onSend",
|
|
2271
|
-
"takes": "a handler",
|
|
2272
|
-
"required": true,
|
|
2273
|
-
"note": "Send what is written. The box empties afterwards — unless this returns `false`: nothing was sent, and the words stay."
|
|
2274
|
-
},
|
|
2275
|
-
{
|
|
2276
|
-
"name": "placeholder",
|
|
2277
|
-
"takes": "anything",
|
|
2278
|
-
"required": true,
|
|
2279
|
-
"note": "Said in the empty box: words, and a `Kbd` where a key helps (\"type / for commands\")."
|
|
2280
|
-
},
|
|
2281
|
-
{
|
|
2282
|
-
"name": "tools",
|
|
2283
|
-
"takes": "anything",
|
|
2284
|
-
"required": false,
|
|
2285
|
-
"note": "The tools under the text, left: `ToolbarButton`s (attach, highlight)."
|
|
2286
|
-
},
|
|
2287
|
-
{
|
|
2288
|
-
"name": "attachments",
|
|
2289
|
-
"takes": "anything",
|
|
2290
|
-
"required": false,
|
|
2291
|
-
"note": "What is attached, under the text: `AttachmentCard pending`s."
|
|
2292
|
-
},
|
|
2293
|
-
{
|
|
2294
|
-
"name": "ready",
|
|
2295
|
-
"takes": "true/false",
|
|
2296
|
-
"required": false,
|
|
2297
|
-
"note": "Something to send even with no words — a file ready."
|
|
2298
|
-
},
|
|
2299
|
-
{
|
|
2300
|
-
"name": "holding",
|
|
2301
|
-
"takes": "true/false",
|
|
2302
|
-
"required": false,
|
|
2303
|
-
"note": "Sending waits — a file still uploading."
|
|
2304
|
-
},
|
|
2305
|
-
{
|
|
2306
|
-
"name": "marked",
|
|
2307
|
-
"takes": "true/false",
|
|
2308
|
-
"required": false,
|
|
2309
|
-
"note": "The bar down the text's left: an urgent mention or a highlight, as Peek draws it."
|
|
2310
|
-
},
|
|
2311
|
-
{
|
|
2312
|
-
"name": "selection",
|
|
2313
|
-
"takes": "Pick<SelectionToolbarProps, 'marks' | 'link' | 'actions'>",
|
|
2314
|
-
"required": false,
|
|
2315
|
-
"note": "The selection strip's buttons: its marks, Link, and the app's own (`actions`)."
|
|
2316
|
-
},
|
|
2317
|
-
{
|
|
2318
|
-
"name": "className",
|
|
2319
|
-
"takes": "text",
|
|
2320
|
-
"required": false,
|
|
2321
|
-
"note": null
|
|
2322
|
-
}
|
|
2323
|
-
],
|
|
2324
|
-
"variants": [],
|
|
2325
|
-
"ownsBehaviours": [],
|
|
2326
|
-
"status": "stable",
|
|
2327
|
-
"migrationStage": null,
|
|
2328
|
-
"docsId": "primitives-composebox--docs",
|
|
2329
|
-
"storyId": "primitives-composebox--default",
|
|
2330
|
-
"docPage": "src/ComposeBox.mdx",
|
|
2331
|
-
"app": null,
|
|
2332
|
-
"looks": [
|
|
2333
|
-
"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",
|
|
2334
|
-
"select-none font-mono text-menu font-normal tracking-wider text-text-muted"
|
|
2335
|
-
]
|
|
2336
|
-
},
|
|
2337
|
-
{
|
|
2338
|
-
"name": "ComposeKeys",
|
|
2339
|
-
"repo": "estiva-ui",
|
|
2340
|
-
"kind": "component",
|
|
2341
|
-
"importPath": "@estiva-app/ui/editor",
|
|
2342
|
-
"sourceFile": "src/ComposeBox.tsx",
|
|
2343
|
-
"purpose": "Enter sends; Shift+Enter is a new line — in a list a new item (or out of the list, on an empty one), in a quote a new line (or out of it, on an empty one).",
|
|
2344
|
-
"purposeFrom": "comment",
|
|
2345
|
-
"props": [],
|
|
2346
|
-
"variants": [],
|
|
2347
|
-
"ownsBehaviours": [],
|
|
2348
|
-
"status": "stable",
|
|
2349
|
-
"migrationStage": null,
|
|
2350
|
-
"docsId": "primitives-composebox--docs",
|
|
2351
|
-
"storyId": "primitives-composebox--default",
|
|
2352
|
-
"docPage": null,
|
|
2353
|
-
"app": null,
|
|
2354
|
-
"looks": []
|
|
2355
|
-
},
|
|
2356
2244
|
{
|
|
2357
2245
|
"name": "ConfirmDialog",
|
|
2358
2246
|
"repo": "estiva-ui",
|
package/src/CommentBox.mdx
CHANGED
|
@@ -13,19 +13,26 @@ The one box every app writes a comment, a reply and a line of a conversation in:
|
|
|
13
13
|
|
|
14
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
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,
|
|
16
|
+
- `edit` to change something already sent: the same box with Cancel and Save, its keys on the left, and the same selection strip over selected words.
|
|
17
17
|
- `upload` to offer files: the paperclip, `/` → Upload, a pasted picture and a dropped file.
|
|
18
18
|
- `under` to show, while something is written, the one card it will be sent with (✕ takes it off) and the live part of each block link, drawn as the app draws them under a sent message. An edit box shows the card and no part.
|
|
19
19
|
- `closed` where nothing can be written (archived, signed out): a line saying why, in the box's place. No greyed box.
|
|
20
|
+
- `marked` when the app has its own reason for the bar down the text, besides an urgent mention, which always draws it.
|
|
21
|
+
- `onEditor` when something outside the box writes into it: the app keeps the editor it is handed and inserts into the box last used.
|
|
20
22
|
|
|
21
23
|
<Canvas of={CommentBoxStories.Refused} />
|
|
22
24
|
|
|
25
|
+
<Canvas of={CommentBoxStories.WithAFile} />
|
|
26
|
+
|
|
27
|
+
<Canvas of={CommentBoxStories.WithAnAppsOwnRows} />
|
|
28
|
+
|
|
29
|
+
<Canvas of={CommentBoxStories.LongDraft} />
|
|
30
|
+
|
|
23
31
|
<Canvas of={CommentBoxStories.CardUnderTheBox} />
|
|
24
32
|
|
|
25
33
|
## When not
|
|
26
34
|
|
|
27
35
|
- Writing a document in place → the editor itself, with **EditorBlockHandle** and **SelectionToolbar**. Nothing is sent.
|
|
28
|
-
- A box with nothing of this — no lists, no drafts, no files → **ComposeBox**, with the app's own editor. CommentBox is built on it.
|
|
29
36
|
- One line of plain text in a form → **TextInput** or **Textarea**.
|
|
30
37
|
|
|
31
38
|
## How
|
|
@@ -62,6 +69,8 @@ const draft = composerDraft(createDraftStore(localStorage), draftKeys.thread(roo
|
|
|
62
69
|
- **`under.read` is the app's reading of the draft**: `@estiva-app/conversation`'s `boxReadOf(body, context)` says which file gets the card and which parts show; the app adds its own view of each. Call `under.changed`'s listener when what a link names comes back. `send`'s third argument is `{ card }`, the card still shown, which the app writes with `embedsToSend` (or `embedsToEdit` for `onSave`).
|
|
63
70
|
- **An edit box's `read` passes `previous: namedBefore(<the message's text>)`**, so only a file the edit names first gets a card. A card the message already has, or one taken off with ✕ before or after sending, never shows again in the edit box, and Save leaves it as it was.
|
|
64
71
|
- **A link chip for a pasted app URL** is the app's `LinkChips`, passed in `extensions`.
|
|
72
|
+
- **`keepCommentBoxWarm({ extensions, referenceView })`**, called once as the app starts, builds an editor while the page is idle, and the next empty box given those same `extensions` and `referenceView` (the same objects, in the same order) takes it, so it opens at once. A box opening with a draft or an edit, or with other extensions, builds its own. Keep `extensions` a module constant: a new array per render never matches.
|
|
73
|
+
- **`onEditor` gets `null` as the box goes**, so a launcher never writes into a box that is gone.
|
|
65
74
|
|
|
66
75
|
## What it owns
|
|
67
76
|
|
|
@@ -76,7 +85,9 @@ It does these by itself. Write none of them around it.
|
|
|
76
85
|
| The draft, written as you type and forgotten once sent | an update listener |
|
|
77
86
|
| Files: picking, pasting, dropping, uploading, failing; Send waits for an upload and holds on a failed file until its ✕ removes it | a file list |
|
|
78
87
|
| The card under the box, its ✕, and a ✕ forgotten once the link is taken out; a refused send puts back what ✕ took off | a card state |
|
|
79
|
-
| A URL pasted over words links them when a message can carry them as a link (one line of plain words, no bracket, no chip, no `)` in the URL); otherwise the URL goes in after the words. Typing after linked words is not linked | a paste handler |
|
|
88
|
+
| A URL pasted over words links them when a message can carry them as a link (one line of plain words, no bracket, no chip, no `)` in the URL); otherwise the URL goes in after the words. The caret goes after the link, so the next Enter sends. Typing after linked words is not linked | a paste handler |
|
|
89
|
+
| A long draft stops at half the window and scrolls inside the box, in the send box and the edit box | a height or a scroll container |
|
|
90
|
+
| The bar down the text while an urgent mention is in the box | an urgent check |
|
|
80
91
|
| The read-only line | a disabled box |
|
|
81
92
|
|
|
82
93
|
## Keys
|
|
@@ -86,6 +97,6 @@ It does these by itself. Write none of them around it.
|
|
|
86
97
|
| Enter | Sends; saves an edit. With a list open, picks the row. Holds while a file is uploading or did not upload. |
|
|
87
98
|
| Ctrl/Cmd+Enter | Sends, as Enter does. |
|
|
88
99
|
| Shift+Enter | A new line; in a list, a new item. |
|
|
89
|
-
| Escape | Cancels an edit. With a list open,
|
|
100
|
+
| Escape | Cancels an edit. With a list open, or words selected under the strip, closes that first. |
|
|
90
101
|
|
|
91
102
|
<Controls />
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
2
|
import { useState } from 'react'
|
|
3
|
-
import type { JSONContent } from '@tiptap/react'
|
|
3
|
+
import type { Editor, JSONContent } from '@tiptap/react'
|
|
4
|
+
import { IconSquareRounded } from '@tabler/icons-react'
|
|
4
5
|
import { expect, userEvent, waitFor, within } from 'storybook/test'
|
|
6
|
+
import type { ReferenceViewProps } from './BlockNodes'
|
|
5
7
|
import { Button } from './Button'
|
|
6
8
|
import { CommentBox, commentBoxRows, type BoxUnder, type CommentBoxDraft, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
|
|
7
|
-
import type { CaptionedItem, MentionPerson, ReferenceSection } from './ComposerTriggers'
|
|
9
|
+
import type { CaptionedItem, MentionPerson, ReferenceSection, SlashCommand } from './ComposerTriggers'
|
|
10
|
+
import { InlineChip } from './InlineChip'
|
|
8
11
|
import { Kbd } from './Kbd'
|
|
9
12
|
import { LinkCard } from './LinkCard'
|
|
10
13
|
import { ITEM, ready } from './linked.examples'
|
|
@@ -195,6 +198,9 @@ export const EditingRefused: Story = {
|
|
|
195
198
|
play: typeInto('{Enter}'),
|
|
196
199
|
}
|
|
197
200
|
|
|
201
|
+
/** A file attached and ready: its card under the text, and Send can send it with no words. */
|
|
202
|
+
export const WithAFile: Story = { render: () => <Live />, play: pickAFile }
|
|
203
|
+
|
|
198
204
|
/** A file uploading: Send waits for it. */
|
|
199
205
|
export const FileUploading: Story = { render: () => <Live upload={uploads('never')} />, play: pickAFile }
|
|
200
206
|
|
|
@@ -264,6 +270,76 @@ export const EditingWithACard: Story = {
|
|
|
264
270
|
},
|
|
265
271
|
}
|
|
266
272
|
|
|
273
|
+
/** An app's own `/` rows, after the kit's: each puts a label at the start of the box, which the app marks. */
|
|
274
|
+
const OWN_ROWS: SlashCommand[] = ['one', 'two', 'three', 'four', 'five'].map((n) => ({
|
|
275
|
+
key: `own-${n}`,
|
|
276
|
+
row: { label: `Item ${n}` },
|
|
277
|
+
keywords: ['item'],
|
|
278
|
+
run: (editor) => editor.chain().focus().insertContentAt(1, `Item ${n}: `).run(),
|
|
279
|
+
}))
|
|
280
|
+
|
|
281
|
+
/** The app's own chip for a reference the box holds. */
|
|
282
|
+
const OwnChip = ({ uri }: ReferenceViewProps) => (
|
|
283
|
+
<InlineChip icon={<IconSquareRounded size={16} stroke={1.5} />}>{uri.endsWith('one') ? 'Item one' : 'Item'}</InlineChip>
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
const WITH_A_REFERENCE: JSONContent = {
|
|
287
|
+
type: 'doc',
|
|
288
|
+
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'As in ' }, { type: 'reference', attrs: { uri: 'nostr:item-one' } }] }],
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** What an app adds around the box: its own rows and mark, its chip, and a control outside the box that writes into the box last used. */
|
|
292
|
+
function AppAround() {
|
|
293
|
+
const [last, setLast] = useState<Editor | null>(null)
|
|
294
|
+
return (
|
|
295
|
+
<div className="flex flex-col gap-3">
|
|
296
|
+
<div>
|
|
297
|
+
<Button variant="outlined" size="small" disabled={!last} onClick={() => last?.chain().focus('end').insertContent(' Written from outside the box.').run()}>
|
|
298
|
+
Write into the box
|
|
299
|
+
</Button>
|
|
300
|
+
</div>
|
|
301
|
+
<Live
|
|
302
|
+
start={WITH_A_REFERENCE}
|
|
303
|
+
insert={[...INSERT, ...OWN_ROWS]}
|
|
304
|
+
referenceView={OwnChip}
|
|
305
|
+
marked={(editor) => editor.getText().startsWith('Item ')}
|
|
306
|
+
onEditor={(editor) => setLast(editor)}
|
|
307
|
+
/>
|
|
308
|
+
</div>
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* An app's own `/` rows after the kit's, its own mark (the bar down the text,
|
|
314
|
+
* as an urgent mention draws it), its chip for a reference, a pasted picture
|
|
315
|
+
* becoming a file, and a control outside the box writing into it.
|
|
316
|
+
*/
|
|
317
|
+
export const WithAnAppsOwnRows: Story = { render: () => <AppAround />, play: typeInto('/item') }
|
|
318
|
+
|
|
319
|
+
/** An urgent mention in the box: the bar down the text while it is there. */
|
|
320
|
+
export const UrgentMarked: Story = {
|
|
321
|
+
render: () => (
|
|
322
|
+
<Live
|
|
323
|
+
start={{
|
|
324
|
+
type: 'doc',
|
|
325
|
+
content: [{ type: 'paragraph', content: [{ type: 'urgentMention', attrs: { id: 'two', label: 'Person two', pubkey: '2'.repeat(64) } }, { type: 'text', text: ' please look' }] }],
|
|
326
|
+
}}
|
|
327
|
+
/>
|
|
328
|
+
),
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** A draft longer than the box: it stops at half the window and scrolls inside, so its first line can be reached. */
|
|
332
|
+
export const LongDraft: Story = {
|
|
333
|
+
render: () => (
|
|
334
|
+
<Live
|
|
335
|
+
start={{
|
|
336
|
+
type: 'doc',
|
|
337
|
+
content: Array.from({ length: 40 }, (_, i) => ({ type: 'paragraph', content: [{ type: 'text', text: `Line ${i + 1} of a long draft.` }] })),
|
|
338
|
+
}}
|
|
339
|
+
/>
|
|
340
|
+
),
|
|
341
|
+
}
|
|
342
|
+
|
|
267
343
|
/** The narrowest column it sits in, 320px, with a file uploading. */
|
|
268
344
|
export const Narrow: Story = {
|
|
269
345
|
decorators: [
|
package/src/CommentBox.test.tsx
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* sending held or shown at once, a refusal putting the words back, the edit
|
|
5
5
|
* mode, drafts, files and the read-only line.
|
|
6
6
|
*/
|
|
7
|
-
import { act } from 'react'
|
|
7
|
+
import { act, Suspense, use } from 'react'
|
|
8
8
|
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
9
9
|
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'
|
|
10
|
-
import type
|
|
10
|
+
import { Extension, type Editor } from '@tiptap/core'
|
|
11
11
|
import { Fragment, Slice } from '@tiptap/pm/model'
|
|
12
12
|
import type { JSONContent } from '@tiptap/react'
|
|
13
|
-
import { CommentBox, commentBoxRows, type BoxUnder, type CommentBoxDraft, type CommentBoxEdit, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
|
|
13
|
+
import { CommentBox, commentBoxRows, keepCommentBoxWarm, type BoxUnder, type CommentBoxDraft, type CommentBoxEdit, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
|
|
14
14
|
import type { MentionPerson } from './ComposerTriggers'
|
|
15
15
|
|
|
16
16
|
const PEOPLE: MentionPerson[] = [{ id: 'one', name: 'Person one', pubkey: 'b'.repeat(64) }]
|
|
@@ -169,6 +169,21 @@ describe('editing', () => {
|
|
|
169
169
|
expect(onCancel).toHaveBeenCalledTimes(1)
|
|
170
170
|
})
|
|
171
171
|
|
|
172
|
+
it('with words selected, the first Escape closes the selection strip and keeps the edit; the next cancels', async () => {
|
|
173
|
+
const onCancel = vi.fn()
|
|
174
|
+
render(<Box edit={{ body, onSave: async () => ({ accepted: true }), onCancel }} />)
|
|
175
|
+
// Selected and pressed in one act, so the box's opening focus (a frame later) cannot collapse the selection in between.
|
|
176
|
+
await act(async () => {
|
|
177
|
+
const editor = editorOf()
|
|
178
|
+
editor.commands.setTextSelection({ from: 1, to: 5 })
|
|
179
|
+
editor.view.someProp('handleKeyDown', (handle) => handle(editor.view, new KeyboardEvent('keydown', { key: 'Escape' })))
|
|
180
|
+
})
|
|
181
|
+
expect(onCancel).not.toHaveBeenCalled()
|
|
182
|
+
expect(editorOf().state.selection.empty).toBe(true)
|
|
183
|
+
await press('Escape')
|
|
184
|
+
expect(onCancel).toHaveBeenCalledTimes(1)
|
|
185
|
+
})
|
|
186
|
+
|
|
172
187
|
it('a refused save keeps the words and says it was not saved', async () => {
|
|
173
188
|
render(<Box edit={{ body, onSave: async () => ({ accepted: false, reason: 'gone' }), onCancel: () => {} }} />)
|
|
174
189
|
await press('Enter')
|
|
@@ -422,6 +437,18 @@ describe('a URL pasted over words', () => {
|
|
|
422
437
|
expect(runs()).toEqual(['text:see ', `link:the plan>${URL_}`, 'text:! now'])
|
|
423
438
|
})
|
|
424
439
|
|
|
440
|
+
it('leaves the caret after the linked words, so the selection strip stays shut and one Enter sends (COMM-8)', async () => {
|
|
441
|
+
const send = vi.fn<CommentBoxProps['send']>(async () => ({ accepted: true }))
|
|
442
|
+
render(<Box send={send} />)
|
|
443
|
+
await type('see the plan')
|
|
444
|
+
await pasteOver(5, 13, URL_)
|
|
445
|
+
expect(editorOf().state.selection.empty).toBe(true)
|
|
446
|
+
expect(editorOf().state.selection.from).toBe(13)
|
|
447
|
+
expect(screen.queryByRole('textbox', { name: /link/i })).toBeNull()
|
|
448
|
+
await press('Enter')
|
|
449
|
+
expect(send).toHaveBeenCalledTimes(1)
|
|
450
|
+
})
|
|
451
|
+
|
|
425
452
|
it('select-all over one line links all its words, without the full stop copied after the URL', async () => {
|
|
426
453
|
render(<Box edit={editing(doc({ type: 'text', text: 'the plan' }))} />)
|
|
427
454
|
await pasteOver('all', 0, `${URL_}.`)
|
|
@@ -446,3 +473,158 @@ describe('a URL pasted over words', () => {
|
|
|
446
473
|
expect(runs()).toEqual(['text:the spec https://wiki.example/Nostr_(protocol)'])
|
|
447
474
|
})
|
|
448
475
|
})
|
|
476
|
+
|
|
477
|
+
describe('what an app adds around the box', () => {
|
|
478
|
+
const bar = () => document.querySelector('[data-composer-editor]')?.hasAttribute('data-marked')
|
|
479
|
+
const URGENT = { type: 'urgentMention', attrs: { id: 'one', label: 'Person one' } }
|
|
480
|
+
|
|
481
|
+
it('draws the bar down the text while an urgent mention is in the box, and drops it when the mention goes', async () => {
|
|
482
|
+
render(<Box />)
|
|
483
|
+
expect(bar()).toBe(false)
|
|
484
|
+
await act(async () => {
|
|
485
|
+
editorOf().chain().focus('end').insertContent([URGENT, { type: 'text', text: ' look' }]).run()
|
|
486
|
+
})
|
|
487
|
+
expect(bar()).toBe(true)
|
|
488
|
+
await act(async () => {
|
|
489
|
+
editorOf().commands.clearContent(true)
|
|
490
|
+
})
|
|
491
|
+
expect(bar()).toBe(false)
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
it("draws the bar while the app's own mark holds, in the edit box too", async () => {
|
|
495
|
+
const marked = (editor: Editor) => editor.getText().includes('!!')
|
|
496
|
+
const body: JSONContent = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'plain' }] }] }
|
|
497
|
+
render(<Box marked={marked} edit={{ body, onSave: async () => ({ accepted: true }), onCancel: () => {} }} />)
|
|
498
|
+
expect(bar()).toBe(false)
|
|
499
|
+
await type(' !!')
|
|
500
|
+
expect(bar()).toBe(true)
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
it("hands the box's editor out, so a launcher inserts into it and the words are sent; and null once it goes", async () => {
|
|
504
|
+
const send = vi.fn<CommentBoxProps['send']>(async () => ({ accepted: true }))
|
|
505
|
+
let handed: Editor | null = null
|
|
506
|
+
const { unmount } = render(<Box send={send} onEditor={(editor) => (handed = editor)} />)
|
|
507
|
+
await act(async () => {
|
|
508
|
+
handed!.chain().focus('end').insertContent('from the launcher').run()
|
|
509
|
+
})
|
|
510
|
+
await press('Enter')
|
|
511
|
+
expect(textOf(send.mock.calls[0][0])).toBe('from the launcher')
|
|
512
|
+
unmount()
|
|
513
|
+
expect(handed).toBeNull()
|
|
514
|
+
})
|
|
515
|
+
})
|
|
516
|
+
|
|
517
|
+
describe('a box built ahead', () => {
|
|
518
|
+
/** Runs what waits for an idle moment at once, as a page with nothing to do would. */
|
|
519
|
+
function idleNow() {
|
|
520
|
+
const queued: IdleRequestCallback[] = []
|
|
521
|
+
window.requestIdleCallback = ((callback: IdleRequestCallback) => queued.push(callback)) as typeof window.requestIdleCallback
|
|
522
|
+
return () => {
|
|
523
|
+
while (queued.length) queued.shift()!({ didTimeout: false, timeRemaining: () => 50 })
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** An app's own extension that counts the editors built with it. */
|
|
528
|
+
function counted() {
|
|
529
|
+
const built: Editor[] = []
|
|
530
|
+
const extensions = [Extension.create({ name: 'appOwn', onBeforeCreate: ({ editor }) => void built.push(editor as Editor) })]
|
|
531
|
+
return { built, extensions }
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
it("takes the editor built while the page was idle, labelled as this box, and it sends with this box's send", async () => {
|
|
535
|
+
const flush = idleNow()
|
|
536
|
+
const { built, extensions } = counted()
|
|
537
|
+
keepCommentBoxWarm({ extensions })
|
|
538
|
+
flush()
|
|
539
|
+
expect(built).toHaveLength(1)
|
|
540
|
+
let handed: Editor | null = null
|
|
541
|
+
const send = vi.fn<CommentBoxProps['send']>(async () => ({ accepted: true }))
|
|
542
|
+
render(<Box send={send} extensions={extensions} onEditor={(editor) => (handed = editor)} />)
|
|
543
|
+
expect(handed).toBe(built[0])
|
|
544
|
+
expect(screen.getByRole('textbox', { name: 'Write' })).toBeTruthy()
|
|
545
|
+
await type('ahead')
|
|
546
|
+
await press('Enter')
|
|
547
|
+
expect(textOf(send.mock.calls[0][0])).toBe('ahead')
|
|
548
|
+
// …and the next spare is built for the next box.
|
|
549
|
+
flush()
|
|
550
|
+
expect(built).toHaveLength(2)
|
|
551
|
+
})
|
|
552
|
+
|
|
553
|
+
it('a box opening with a draft, or with other extensions, builds its own and leaves the spare', async () => {
|
|
554
|
+
const flush = idleNow()
|
|
555
|
+
const { built, extensions } = counted()
|
|
556
|
+
keepCommentBoxWarm({ extensions })
|
|
557
|
+
flush()
|
|
558
|
+
let handed: Editor | null = null
|
|
559
|
+
const kept: CommentBoxDraft = { read: () => ({ type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'kept' }] }] }), write: () => {}, clear: () => {} }
|
|
560
|
+
render(<Box draft={kept} extensions={extensions} onEditor={(editor) => (handed = editor)} />)
|
|
561
|
+
expect(built).toHaveLength(2)
|
|
562
|
+
expect(handed).not.toBe(built[0])
|
|
563
|
+
expect(editorOf().getText()).toBe('kept')
|
|
564
|
+
cleanup()
|
|
565
|
+
render(<Box onEditor={(editor) => (handed = editor)} />)
|
|
566
|
+
expect(handed).not.toBe(built[0])
|
|
567
|
+
})
|
|
568
|
+
|
|
569
|
+
it('works again, with what was typed, after a loading page hides the box and shows it again', async () => {
|
|
570
|
+
// The box lets its editor go a moment after it is hidden: that moment is this clock's.
|
|
571
|
+
vi.useFakeTimers({ toFake: ['Date', 'setTimeout', 'clearTimeout'] })
|
|
572
|
+
try {
|
|
573
|
+
let kept: JSONContent | undefined
|
|
574
|
+
const draft: CommentBoxDraft = { read: () => kept, write: (body) => void (kept = body), clear: () => void (kept = undefined) }
|
|
575
|
+
const send = vi.fn<CommentBoxProps['send']>(async () => ({ accepted: true }))
|
|
576
|
+
const loading = later<void>()
|
|
577
|
+
function Loading() {
|
|
578
|
+
use(loading.promise)
|
|
579
|
+
return null
|
|
580
|
+
}
|
|
581
|
+
function Page({ more }: { more: boolean }) {
|
|
582
|
+
return (
|
|
583
|
+
<Suspense fallback={<p>Loading</p>}>
|
|
584
|
+
<Box send={send} draft={draft} />
|
|
585
|
+
{more && <Loading />}
|
|
586
|
+
</Suspense>
|
|
587
|
+
)
|
|
588
|
+
}
|
|
589
|
+
const { rerender } = render(<Page more={false} />)
|
|
590
|
+
await type('typed before')
|
|
591
|
+
await act(async () => rerender(<Page more />))
|
|
592
|
+
expect(screen.getByText('Loading')).toBeTruthy()
|
|
593
|
+
act(() => vi.advanceTimersByTime(50))
|
|
594
|
+
await act(async () => {
|
|
595
|
+
loading.answer()
|
|
596
|
+
await loading.promise
|
|
597
|
+
})
|
|
598
|
+
expect(screen.queryByText('Loading')).toBeNull()
|
|
599
|
+
expect(screen.queryByRole('textbox', { name: 'Write' })).not.toBeNull()
|
|
600
|
+
expect(editorOf().getText()).toBe('typed before')
|
|
601
|
+
await press('Enter')
|
|
602
|
+
expect(textOf(send.mock.calls[0][0])).toBe('typed before')
|
|
603
|
+
} finally {
|
|
604
|
+
vi.useFakeTimers({ toFake: ['Date'] })
|
|
605
|
+
}
|
|
606
|
+
})
|
|
607
|
+
})
|
|
608
|
+
|
|
609
|
+
describe('a long draft', () => {
|
|
610
|
+
const said: JSONContent = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Said before' }] }] }
|
|
611
|
+
|
|
612
|
+
it('scrolls in the package’s ScrollArea, capped at half the window, in the send box and the edit box — not with the browser’s bar', () => {
|
|
613
|
+
for (const props of [{}, { edit: { body: said, onSave: async () => ({ accepted: true as const }), onCancel: () => {} } }]) {
|
|
614
|
+
const { unmount } = render(<Box {...props} />)
|
|
615
|
+
const text = document.querySelector('.ProseMirror') as HTMLElement
|
|
616
|
+
// The text itself never scrolls: that is the browser's bar (Katerina, 21 Oct).
|
|
617
|
+
expect(text.className).not.toMatch(/(^|\s)overflow(-[xy])?-(auto|scroll)(\s|$)/)
|
|
618
|
+
expect(text.className).not.toContain('max-h-')
|
|
619
|
+
// ScrollArea's viewport (its overscroll rule is its mark) holds the text, with the cap.
|
|
620
|
+
const viewport = text.parentElement?.closest('[class*="overscroll-y-contain"]') as HTMLElement | null
|
|
621
|
+
expect(viewport).not.toBeNull()
|
|
622
|
+
expect(viewport!.className.split(' ')).toContain('max-h-[50vh]')
|
|
623
|
+
// The region reaches into the box's right padding and its content gives it back: the bar at the box's edge, the text where it was.
|
|
624
|
+
expect(viewport!.parentElement!.className.split(' ')).toContain('-mr-3')
|
|
625
|
+
expect((viewport!.firstElementChild as HTMLElement).className.split(' ')).toContain('pr-3')
|
|
626
|
+
expect(viewport!.closest('[data-composer-editor]')).not.toBeNull()
|
|
627
|
+
unmount()
|
|
628
|
+
}
|
|
629
|
+
})
|
|
630
|
+
})
|