@estiva-app/ui 0.84.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/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 ComposeBox. Inset, a hairline,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/ui",
3
- "version": "0.84.0",
3
+ "version": "0.85.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",
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.84.0",
8
- "exports": 209,
9
- "typeExports": 207,
7
+ "packageVersion": "0.85.0",
8
+ "exports": 206,
9
+ "typeExports": 206,
10
10
  "files": null
11
11
  },
12
12
  "storybook": {
@@ -2125,10 +2125,7 @@
2125
2125
  "storyId": "primitives-commentbox--empty",
2126
2126
  "docPage": "src/CommentBox.mdx",
2127
2127
  "app": null,
2128
- "looks": [
2129
- "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",
2130
- "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"
2131
- ]
2128
+ "looks": []
2132
2129
  },
2133
2130
  {
2134
2131
  "name": "commentBoxRows",
@@ -2244,127 +2241,6 @@
2244
2241
  "app": null,
2245
2242
  "looks": []
2246
2243
  },
2247
- {
2248
- "name": "COMPOSE_EDITOR_CLASSES",
2249
- "repo": "estiva-ui",
2250
- "kind": "helper",
2251
- "importPath": "@estiva-app/ui/editor",
2252
- "sourceFile": "src/ComposeBox.tsx",
2253
- "purpose": "The classes the box's editor wears: rich text with no outline.",
2254
- "purposeFrom": "comment",
2255
- "props": [],
2256
- "variants": [],
2257
- "ownsBehaviours": [],
2258
- "status": "stable",
2259
- "migrationStage": null,
2260
- "docsId": "primitives-composebox--docs",
2261
- "storyId": "primitives-composebox--default",
2262
- "docPage": null,
2263
- "app": null,
2264
- "looks": []
2265
- },
2266
- {
2267
- "name": "ComposeBox",
2268
- "repo": "estiva-ui",
2269
- "kind": "component",
2270
- "importPath": "@estiva-app/ui/editor",
2271
- "sourceFile": "src/ComposeBox.tsx",
2272
- "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.",
2273
- "purposeFrom": "page",
2274
- "props": [
2275
- {
2276
- "name": "editor",
2277
- "takes": "Editor | null",
2278
- "required": true,
2279
- "note": "The app's editor, with `ComposeKeys` in its extensions and `COMPOSE_EDITOR_CLASSES` on it."
2280
- },
2281
- {
2282
- "name": "onSend",
2283
- "takes": "a handler",
2284
- "required": true,
2285
- "note": "Send what is written. The box empties afterwards — unless this returns `false`: nothing was sent, and the words stay."
2286
- },
2287
- {
2288
- "name": "placeholder",
2289
- "takes": "anything",
2290
- "required": true,
2291
- "note": "Said in the empty box: words, and a `Kbd` where a key helps (\"type / for commands\")."
2292
- },
2293
- {
2294
- "name": "tools",
2295
- "takes": "anything",
2296
- "required": false,
2297
- "note": "The tools under the text, left: `ToolbarButton`s (attach, highlight)."
2298
- },
2299
- {
2300
- "name": "attachments",
2301
- "takes": "anything",
2302
- "required": false,
2303
- "note": "What is attached, under the text: `AttachmentCard pending`s."
2304
- },
2305
- {
2306
- "name": "ready",
2307
- "takes": "true/false",
2308
- "required": false,
2309
- "note": "Something to send even with no words — a file ready."
2310
- },
2311
- {
2312
- "name": "holding",
2313
- "takes": "true/false",
2314
- "required": false,
2315
- "note": "Sending waits — a file still uploading."
2316
- },
2317
- {
2318
- "name": "marked",
2319
- "takes": "true/false",
2320
- "required": false,
2321
- "note": "The bar down the text's left: an urgent mention or a highlight, as Peek draws it."
2322
- },
2323
- {
2324
- "name": "selection",
2325
- "takes": "Pick<SelectionToolbarProps, 'marks' | 'link' | 'actions'>",
2326
- "required": false,
2327
- "note": "The selection strip's buttons: its marks, Link, and the app's own (`actions`)."
2328
- },
2329
- {
2330
- "name": "className",
2331
- "takes": "text",
2332
- "required": false,
2333
- "note": null
2334
- }
2335
- ],
2336
- "variants": [],
2337
- "ownsBehaviours": [],
2338
- "status": "stable",
2339
- "migrationStage": null,
2340
- "docsId": "primitives-composebox--docs",
2341
- "storyId": "primitives-composebox--default",
2342
- "docPage": "src/ComposeBox.mdx",
2343
- "app": null,
2344
- "looks": [
2345
- "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",
2346
- "select-none font-mono text-menu font-normal tracking-wider text-text-muted"
2347
- ]
2348
- },
2349
- {
2350
- "name": "ComposeKeys",
2351
- "repo": "estiva-ui",
2352
- "kind": "component",
2353
- "importPath": "@estiva-app/ui/editor",
2354
- "sourceFile": "src/ComposeBox.tsx",
2355
- "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).",
2356
- "purposeFrom": "comment",
2357
- "props": [],
2358
- "variants": [],
2359
- "ownsBehaviours": [],
2360
- "status": "stable",
2361
- "migrationStage": null,
2362
- "docsId": "primitives-composebox--docs",
2363
- "storyId": "primitives-composebox--default",
2364
- "docPage": null,
2365
- "app": null,
2366
- "looks": []
2367
- },
2368
2244
  {
2369
2245
  "name": "ConfirmDialog",
2370
2246
  "repo": "estiva-ui",
@@ -13,7 +13,7 @@ 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, and only its keys on the left.
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.
@@ -22,6 +22,8 @@ The one box every app writes a comment, a reply and a line of a conversation in:
22
22
 
23
23
  <Canvas of={CommentBoxStories.Refused} />
24
24
 
25
+ <Canvas of={CommentBoxStories.WithAFile} />
26
+
25
27
  <Canvas of={CommentBoxStories.WithAnAppsOwnRows} />
26
28
 
27
29
  <Canvas of={CommentBoxStories.LongDraft} />
@@ -31,7 +33,6 @@ The one box every app writes a comment, a reply and a line of a conversation in:
31
33
  ## When not
32
34
 
33
35
  - Writing a document in place → the editor itself, with **EditorBlockHandle** and **SelectionToolbar**. Nothing is sent.
34
- - A box with nothing of this — no lists, no drafts, no files → **ComposeBox**, with the app's own editor. CommentBox is built on it.
35
36
  - One line of plain text in a form → **TextInput** or **Textarea**.
36
37
 
37
38
  ## How
@@ -96,6 +97,6 @@ It does these by itself. Write none of them around it.
96
97
  | Enter | Sends; saves an edit. With a list open, picks the row. Holds while a file is uploading or did not upload. |
97
98
  | Ctrl/Cmd+Enter | Sends, as Enter does. |
98
99
  | Shift+Enter | A new line; in a list, a new item. |
99
- | Escape | Cancels an edit. With a list open, closes the list first. |
100
+ | Escape | Cancels an edit. With a list open, or words selected under the strip, closes that first. |
100
101
 
101
102
  <Controls />
@@ -198,6 +198,9 @@ export const EditingRefused: Story = {
198
198
  play: typeInto('{Enter}'),
199
199
  }
200
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
+
201
204
  /** A file uploading: Send waits for it. */
202
205
  export const FileUploading: Story = { render: () => <Live upload={uploads('never')} />, play: pickAFile }
203
206
 
@@ -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')
@@ -1,6 +1,6 @@
1
1
  import { Fragment, useCallback, useEffect, useLayoutEffect, useRef, useState, type ComponentType, type DragEvent, type ReactNode } from 'react'
2
2
  import { Extension, type AnyExtension, type EditorOptions } from '@tiptap/core'
3
- import { Editor, EditorContent, type JSONContent } from '@tiptap/react'
3
+ import { Editor, type JSONContent } from '@tiptap/react'
4
4
  import { IconLock, IconPaperclip, IconSquareRounded } from '@tabler/icons-react'
5
5
  import { AttachmentCard } from './AttachmentCard'
6
6
  import { ReferenceNode, type ReferenceViewProps } from './BlockNodes'
@@ -8,7 +8,7 @@ import { Button } from './Button'
8
8
  import { Card } from './Card'
9
9
  import { CardUnder } from './CardUnder'
10
10
  import { cn } from './cn'
11
- import { ComposeBox, ComposeKeys, COMPOSE_EDITOR_CLASSES, COMPOSE_SCROLL_CLASSES, isEmptyDoc as isEmpty } from './ComposeBox'
11
+ import { BoxFrame, ComposeKeys, COMPOSE_EDITOR_CLASSES, isEmptyDoc as isEmpty, SendBox } from './commentBoxFrame'
12
12
  import {
13
13
  CaptionedReference,
14
14
  PersonMention,
@@ -27,9 +27,7 @@ import { FieldLine } from './Field'
27
27
  import { FilePicker } from './FilePicker'
28
28
  import { Kbd } from './Kbd'
29
29
  import { BoxKit, PasteOverWords } from './links'
30
- import { WRITING_BOX_CLASSES } from './looks'
31
30
  import { PastedImages } from './PastedImages'
32
- import { ScrollArea } from './ScrollArea'
33
31
  import { KeptSelection } from './SelectionToolbar'
34
32
  import { isSuggestionOpen } from './suggestionPopup'
35
33
  import { ToolbarButton } from './Toolbar'
@@ -37,7 +35,7 @@ import { ToolbarButton } from './Toolbar'
37
35
  /**
38
36
  * The one box every app writes a comment, a reply and a chat line in, from the
39
37
  * approved prototype (`concept/comments-everywhere`, Miky 17 October): the
40
- * package's `ComposeBox` with everything each app built around it — `@`,
38
+ * box's one frame (`commentBoxFrame`) with everything each app built around it — `@`,
41
39
  * `!@`, `[` and `/`, the keys, drafts, files, the edit mode, sending and a
42
40
  * refused send. An app hands over only its people, its `[` sections, its `/`
43
41
  * Insert rows and a send that says whether the relay accepted it.
@@ -188,8 +186,8 @@ export const commentBoxRows: Readonly<Record<'file' | 'mention' | 'urgent' | 're
188
186
  reference: { key: 'insert-reference', row: { label: 'Reference', shortcut: '[' }, keywords: ['[', 'Reference'], run: typeTrigger('[') },
189
187
  }
190
188
 
191
- /** Ctrl/Cmd+Enter sends as Enter does; Escape cancels an edit (an open list takes Escape first). */
192
- const BoxKeys = Extension.create<{ onEscape: () => boolean }>({
189
+ /** Ctrl/Cmd+Enter sends as Enter does; Escape cancels an edit (an open list, or the selection strip, takes Escape first). */
190
+ const BoxKeys = Extension.create<{ onEscape: (editor: Editor) => boolean }>({
193
191
  name: 'commentBoxKeys',
194
192
  addOptions() {
195
193
  return { onEscape: () => false }
@@ -198,7 +196,7 @@ const BoxKeys = Extension.create<{ onEscape: () => boolean }>({
198
196
  return {
199
197
  'Mod-Enter': ({ editor }) => (editor.storage as unknown as { composeKeys?: { send: (() => boolean) | null } }).composeKeys?.send?.() ?? false,
200
198
  // Open now, with no grace: the first Escape closes a list, the next is a deliberate cancel (suggestionPopup).
201
- Escape: () => (isSuggestionOpen() ? false : this.options.onEscape()),
199
+ Escape: ({ editor }) => (isSuggestionOpen() ? false : this.options.onEscape(editor as unknown as Editor)),
202
200
  }
203
201
  },
204
202
  })
@@ -245,9 +243,16 @@ function boxExtensions(hold: BoxHold, app: BoxApp): AnyExtension[] {
245
243
  KeptSelection,
246
244
  ComposeKeys,
247
245
  BoxKeys.configure({
248
- onEscape: () => {
246
+ onEscape: (ed) => {
249
247
  const editing = hold.current.edit
250
248
  if (!editing) return false
249
+ // Words selected: the strip is over them, and the first Escape closes it, leaving the caret at their end.
250
+ // The next is the deliberate cancel, as with an open list (Katerina, 21 Oct: the edit box gets the strip).
251
+ const { selection } = ed.state
252
+ if (!selection.empty) {
253
+ ed.commands.setTextSelection(selection.to)
254
+ return true
255
+ }
251
256
  editing.onCancel()
252
257
  return true
253
258
  },
@@ -543,7 +548,7 @@ export function CommentBox({
543
548
  setRefused(null)
544
549
  const answered = (answer: Promise<SendAnswer>) => answer.catch((): SendAnswer => ({ accepted: false, reason: 'try again in a moment' }))
545
550
  if (showsAtOnce) {
546
- // Shown at once: the box empties now (ComposeBox clears it); a refusal puts the words back above anything written since,
551
+ // Shown at once: the box empties now (the send box clears it); a refusal puts the words back above anything written since,
547
552
  // and what ✕ took off with them.
548
553
  const took = removed
549
554
  setFiles((all) => all.filter((f) => f.state !== 'ready'))
@@ -600,7 +605,7 @@ export function CommentBox({
600
605
  return true
601
606
  }
602
607
 
603
- // Enter and Ctrl/Cmd+Enter save an edit; the send box wires them through ComposeBox.
608
+ // Enter and Ctrl/Cmd+Enter save an edit; the send box wires them itself.
604
609
  useEffect(() => {
605
610
  if (!editor || !edit) return
606
611
  const storage = (editor.storage as unknown as { composeKeys?: { send: (() => boolean) | null } }).composeKeys
@@ -660,27 +665,29 @@ export function CommentBox({
660
665
  if (edit) {
661
666
  return (
662
667
  <div className={cn('flex flex-col gap-1', className)}>
663
- <div className={cn(WRITING_BOX_CLASSES, 'focus-within:border-border-strong transition-colors', sending && '[&_.ProseMirror]:text-text-muted')}>
664
- <div data-composer-editor data-marked={marking || undefined} className={cn('relative min-h-[20px]', marking && 'border-l-4 border-border-strong pl-2')}>
665
- <ScrollArea className={COMPOSE_SCROLL_CLASSES.area} viewportClassName={COMPOSE_SCROLL_CLASSES.viewport} contentClassName={COMPOSE_SCROLL_CLASSES.content}>
666
- <EditorContent editor={editor} />
667
- </ScrollArea>
668
- </div>
669
- {fileCards && <div className="flex flex-wrap gap-2">{fileCards}</div>}
670
- <div className="flex items-center justify-between gap-2">
671
- <span className="flex items-center gap-1 text-caption text-text-muted">
672
- <Kbd>Esc</Kbd> to cancel · <Kbd>Enter</Kbd> to save
673
- </span>
674
- <div className="flex items-center gap-2">
675
- <Button variant="outlined" size="small" onClick={edit.onCancel}>
676
- Cancel
677
- </Button>
678
- <Button variant="primary" size="small" disabled={uploading || sending} onClick={() => save.current()}>
679
- Save
680
- </Button>
668
+ <BoxFrame
669
+ editor={editor}
670
+ marked={marking}
671
+ // The same strip as the send box: writing and editing work the same way (Katerina, 21 Oct).
672
+ selection={{ link: true }}
673
+ attachments={fileCards}
674
+ className={cn(sending && '[&_.ProseMirror]:text-text-muted')}
675
+ footer={
676
+ <div className="flex items-center justify-between gap-2">
677
+ <span className="flex items-center gap-1 text-caption text-text-muted">
678
+ <Kbd>Esc</Kbd> to cancel · <Kbd>Enter</Kbd> to save
679
+ </span>
680
+ <div className="flex items-center gap-2">
681
+ <Button variant="outlined" size="small" onClick={edit.onCancel}>
682
+ Cancel
683
+ </Button>
684
+ <Button variant="primary" size="small" disabled={uploading || sending} onClick={() => save.current()}>
685
+ Save
686
+ </Button>
687
+ </div>
681
688
  </div>
682
- </div>
683
- </div>
689
+ }
690
+ />
684
691
  {underBox}
685
692
  {sending && <FieldLine>Saving…</FieldLine>}
686
693
  {refusedLine}
@@ -697,7 +704,7 @@ export function CommentBox({
697
704
 
698
705
  return (
699
706
  <div ref={root} className={cn('flex flex-col gap-1', className)} onDragOver={upload ? (e) => e.preventDefault() : undefined} onDrop={onDrop}>
700
- <ComposeBox
707
+ <SendBox
701
708
  editor={editor}
702
709
  onSend={go}
703
710
  placeholder={placeholder}
@@ -1,3 +1,4 @@
1
+ // @estiva-escape(component-has-a-page, component-has-a-story): CommentBox's own frame, not offered to apps — CommentBox's page and stories show it (Katerina, 21 Oct: one box)
1
2
  import { useCallback, useEffect, useState, type ReactNode } from 'react'
2
3
  import { Extension } from '@tiptap/core'
3
4
  import { EditorContent, type Editor } from '@tiptap/react'
@@ -12,14 +13,15 @@ import { SelectionToolbar, type SelectionToolbarProps } from './SelectionToolbar
12
13
  import { isSuggestionActive } from './suggestionPopup'
13
14
 
14
15
  /**
15
- * The box a message, a reply or a comment is written in, from Katerina's Leaf
16
- * prototype (9 October). Peek's `ComposeBox`, its look and its keys, with
17
- * what only Peek knows left in Peek: drafts, uploads, highlights, its text
18
- * format. The app makes the editor (its extensions are its own) and adds
19
- * `ComposeKeys`; this draws the box around it and sends.
16
+ * The frame `CommentBox` writes in, from Katerina's Leaf prototype (9
17
+ * October): the text, scrolling in a `ScrollArea` past half the window, the
18
+ * bar down its left while it is marked, what is attached, and a footer. The
19
+ * send box and the edit box are this one frame with different footers, so a
20
+ * change to the box is made once (Katerina, 21 Oct: the scrollbar had to be
21
+ * fixed in two copies). It was `ComposeBox`, a part of its own until 0.85.0;
22
+ * no app used it, and two box names invited the wrong pick.
20
23
  */
21
24
 
22
- /** The editor's own classes inside the box: Peek's, rich text with no outline. Put them in `editorProps.attributes.class`. */
23
25
  /** The classes the box's editor wears: rich text with no outline. It never scrolls itself; the box does, in a `ScrollArea`. */
24
26
  export const COMPOSE_EDITOR_CLASSES = richTextClassName('default', 'outline-none w-full bg-transparent min-h-[20px] [&>p+p]:-mt-1')
25
27
 
@@ -86,8 +88,45 @@ export function isEmptyDoc(editor: Editor): boolean {
86
88
  return empty
87
89
  }
88
90
 
89
- export interface ComposeBoxProps {
90
- /** The app's editor, with `ComposeKeys` in its extensions and `COMPOSE_EDITOR_CLASSES` on it. `null` while it loads. */
91
+ export interface BoxFrameProps {
92
+ /** The box's editor, with `ComposeKeys` in its extensions and `COMPOSE_EDITOR_CLASSES` on it. `null` while it loads. */
93
+ editor: Editor | null
94
+ /** The bar down the text's left: an urgent mention or a highlight, as Peek draws it. */
95
+ marked?: boolean
96
+ /** The selection strip over the text, with these buttons. Absent, no strip (the edit box). */
97
+ selection?: Pick<SelectionToolbarProps, 'marks' | 'link' | 'actions'>
98
+ /** Said while the text is empty: words, and a `Kbd` where a key helps. */
99
+ placeholder?: ReactNode
100
+ empty?: boolean
101
+ /** What is attached, under the text: `AttachmentCard pending`s. */
102
+ attachments?: ReactNode
103
+ /** The row under it all: the tools and Send, or the keys and Cancel/Save. */
104
+ footer: ReactNode
105
+ /** On the box itself. */
106
+ className?: string
107
+ }
108
+
109
+ /** The one frame both boxes draw: the bordered box, its text in a `ScrollArea`, what is attached, the footer. */
110
+ export function BoxFrame({ editor, marked = false, selection, placeholder, empty = false, attachments, footer, className }: BoxFrameProps) {
111
+ return (
112
+ <div className={cn(WRITING_BOX_CLASSES, 'focus-within:border-border-strong transition-colors', className)}>
113
+ <div data-composer-editor data-marked={marked || undefined} className={cn('relative min-h-[20px] transition-all', marked && 'border-l-4 border-border-strong pl-2')}>
114
+ <ScrollArea className={COMPOSE_SCROLL_CLASSES.area} viewportClassName={COMPOSE_SCROLL_CLASSES.viewport} contentClassName={COMPOSE_SCROLL_CLASSES.content}>
115
+ <EditorContent editor={editor} />
116
+ </ScrollArea>
117
+ {selection && <SelectionToolbar editor={editor} {...selection} />}
118
+ {empty && placeholder != null && (
119
+ <div className="pointer-events-none absolute inset-0 flex flex-wrap items-center gap-1 text-body-2 text-text-muted">{placeholder}</div>
120
+ )}
121
+ </div>
122
+ {attachments && <div className="flex flex-wrap gap-2">{attachments}</div>}
123
+ {footer}
124
+ </div>
125
+ )
126
+ }
127
+
128
+ export interface SendBoxProps {
129
+ /** The box's editor. `null` while it loads. */
91
130
  editor: Editor | null
92
131
  /**
93
132
  * Send what is written. The box empties afterwards — unless this returns
@@ -112,11 +151,10 @@ export interface ComposeBoxProps {
112
151
  }
113
152
 
114
153
  /**
115
- * The box for writing: the text, the selection strip over it, what is
116
- * attached, the tools and Send. Enter sends (`ComposeKeys`), and so does the
117
- * button.
154
+ * The send box: the frame with the selection strip over the text, the tools
155
+ * and Send under it. Enter sends (`ComposeKeys`), and so does the button.
118
156
  */
119
- export function ComposeBox({ editor, onSend, placeholder, tools, attachments, ready = false, holding = false, marked = false, selection, className }: ComposeBoxProps) {
157
+ export function SendBox({ editor, onSend, placeholder, tools, attachments, ready = false, holding = false, marked = false, selection, className }: SendBoxProps) {
120
158
  const [empty, setEmpty] = useState(true)
121
159
  const canSend = (!empty || ready) && !holding
122
160
 
@@ -151,20 +189,15 @@ export function ComposeBox({ editor, onSend, placeholder, tools, attachments, re
151
189
 
152
190
  return (
153
191
  <div className={cn('relative', className)}>
154
- <div className={cn(WRITING_BOX_CLASSES, 'focus-within:border-border-strong transition-colors')}>
155
- <div data-composer-editor data-marked={marked || undefined} className={cn('relative min-h-[20px] transition-all', marked && 'border-l-4 border-border-strong pl-2')}>
156
- <ScrollArea className={COMPOSE_SCROLL_CLASSES.area} viewportClassName={COMPOSE_SCROLL_CLASSES.viewport} contentClassName={COMPOSE_SCROLL_CLASSES.content}>
157
- <EditorContent editor={editor} />
158
- </ScrollArea>
159
- <SelectionToolbar editor={editor} {...selection} />
160
- {empty && (
161
- <div className="pointer-events-none absolute inset-0 flex flex-wrap items-center gap-1 text-body-2 text-text-muted">{placeholder}</div>
162
- )}
163
- </div>
164
-
165
- {attachments && <div className="flex flex-wrap gap-2">{attachments}</div>}
166
-
167
- {/* The tools are one strip — one Tab stop, arrows along it; Send, the answer rather than a tool, keeps its own. */}
192
+ <BoxFrame
193
+ editor={editor}
194
+ marked={marked}
195
+ selection={selection ?? {}}
196
+ placeholder={placeholder}
197
+ empty={empty}
198
+ attachments={attachments}
199
+ footer={
200
+ // The tools are one strip — one Tab stop, arrows along it; Send, the answer rather than a tool, keeps its own.
168
201
  <div className="flex items-center justify-between">
169
202
  {tools ? (
170
203
  <Toolbar aria-label="Compose tools" surface={false} className="flex items-center gap-1">
@@ -195,7 +228,8 @@ export function ComposeBox({ editor, onSend, placeholder, tools, attachments, re
195
228
  </IconButton>
196
229
  </div>
197
230
  </div>
198
- </div>
231
+ }
232
+ />
199
233
  </div>
200
234
  )
201
235
  }
package/src/editor.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * `Toolbar`, `MenuItem`, `SuggestionMenu` — is the main entry's own, not a copy.
9
9
  */
10
10
  export { KeptSelection, SelectionToolbar, keepSelection, releaseSelection, normalizeHref, type MarkId, type SelectionAction, type SelectionToolbarProps } from './SelectionToolbar'
11
- export { ComposeBox, ComposeKeys, COMPOSE_EDITOR_CLASSES, type ComposeBoxProps } from './ComposeBox'
11
+
12
12
  export {
13
13
  CommentBox,
14
14
  commentBoxRows,
@@ -39,6 +39,13 @@ tester.run('no-hand-rolled-behaviour', noHandRolledBehaviour, {
39
39
  name: 'a global listener kept with its reason',
40
40
  code: 'export function probe() {\n // @estiva-escape(no-hand-rolled-behaviour): the frame measures the window, which no floating part owns\n window.addEventListener("resize", () => {})\n}\n',
41
41
  },
42
+ { name: "the package's ScrollArea, its cap on the viewport", code: 'export const Probe = () => <ScrollArea viewportClassName="max-h-[50vh]" />\n' },
43
+ { name: 'a box that clips, which draws no bar', code: 'export const Probe = () => <div className="overflow-hidden" />\n' },
44
+ { name: 'the class named in a comment', code: '// a hand-made overflow-y-auto box never scrolled\nexport const Probe = () => null\n' },
45
+ {
46
+ name: 'a scroll class kept with its reason',
47
+ code: "// @estiva-escape(no-hand-rolled-behaviour): a probe that keeps the browser bar on purpose\nexport const PROBE_CLASSES = 'overflow-y-auto'\n",
48
+ },
42
49
  ],
43
50
  invalid: [
44
51
  {
@@ -66,5 +73,25 @@ tester.run('no-hand-rolled-behaviour', noHandRolledBehaviour, {
66
73
  code: 'export function probe() {\n document.addEventListener("keydown", () => {})\n}\n',
67
74
  errors: [{ messageId: 'listener', data: { event: 'keydown', target: 'document' } }],
68
75
  },
76
+ {
77
+ name: "the comment box's long draft, as the review of 0.83 found it",
78
+ code: "export const COMPOSE_EDITOR_CLASSES = 'outline-none max-h-[50vh] overflow-y-auto'\n",
79
+ errors: [{ messageId: 'scroll', data: { what: 'overflow-y-auto' } }],
80
+ },
81
+ {
82
+ name: 'a scroll class in a className, behind a variant',
83
+ code: 'export const Probe = () => <div className="[&_pre]:overflow-x-auto" />\n',
84
+ errors: [{ messageId: 'scroll', data: { what: '[&_pre]:overflow-x-auto' } }],
85
+ },
86
+ {
87
+ name: 'a scroll class in a template',
88
+ code: 'export const probe = (h: string) => `max-h-${h} overflow-auto`\n',
89
+ errors: [{ messageId: 'scroll', data: { what: 'overflow-auto' } }],
90
+ },
91
+ {
92
+ name: 'a style that scrolls',
93
+ code: "export const Probe = () => <div style={{ overflowY: 'scroll' }} />\n",
94
+ errors: [{ messageId: 'scroll', data: { what: "overflowY: 'scroll'" } }],
95
+ },
69
96
  ],
70
97
  })
@@ -1,5 +1,6 @@
1
1
  import type { Rule } from 'eslint'
2
2
  import { ESCAPE_MESSAGES, isEscaped } from './escape'
3
+ import { SCROLL_CLASS, utilityOf } from './no-rebuilt-behaviour'
3
4
 
4
5
  /**
5
6
  * Behaviour Base UI already owns, written by hand inside the package (UIG-5,
@@ -17,6 +18,12 @@ import { ESCAPE_MESSAGES, isEscaped } from './escape'
17
18
  * - **a listener on `window` or `document`** for the events a floating part
18
19
  * lives on — resize, scroll, an outside press, a key. Base UI's Positioner
19
20
  * follows the anchor and its Root closes on an outside press and on Escape.
21
+ * - **a box that scrolls with the browser's bar**: `overflow-auto`,
22
+ * `overflow-y-scroll`… in any string, or `overflow: 'auto'` in a style. The
23
+ * apps' rule (`no-rebuilt-behaviour`) refuses it and names `ScrollArea`; until
24
+ * 21 Oct nothing refused it here, and a part's own box drew the browser's bar
25
+ * in every app (the comment box's long draft, Katerina's review of 0.83).
26
+ * `ScrollArea` is Base UI's, so it needs no such class itself.
20
27
  *
21
28
  * What it deliberately does not try to read: measuring arithmetic. `Popover`
22
29
  * hands Base UI a virtual anchor with a `getBoundingClientRect`, which is the
@@ -76,11 +83,48 @@ export const noHandRolledBehaviour: Rule.RuleModule = {
76
83
  'A portal written by hand. Base UI\'s parts carry their own (Popover, Menu, Select, Tooltip, Dialog, Toast): use the part, or say why this one stays.',
77
84
  listener:
78
85
  'A `{{event}}` listener on `{{target}}`. A floating part follows its anchor and closes on an outside press and on Escape by itself (Base UI Positioner and Root): use the part, or say why this one stays.',
86
+ scroll:
87
+ '`{{what}}` scrolls with the browser\'s own bar, and some browsers draw none. Put what grows in a ScrollArea, with a `max-h-*` cap on its viewport (`viewportClassName`), or say why this one stays.',
79
88
  ...ESCAPE_MESSAGES,
80
89
  },
81
90
  },
82
91
  create(context) {
92
+ const reported = new Set<string>()
93
+ const scroll = (node: Rule.Node, what: string) => {
94
+ // The escape sits above the whole line: `export const …` puts the declaration inside the export.
95
+ let at = statement(node as unknown as CallExpression)
96
+ for (let p: Rule.Node | null = node.parent; p; p = p.parent) {
97
+ if (p.range?.[0] === at.range[0] && p.range?.[1] === at.range[1]) {
98
+ if (p.parent && /^Export/.test(p.parent.type) && p.parent.loc && p.parent.range) at = { loc: p.parent.loc, range: p.parent.range }
99
+ break
100
+ }
101
+ }
102
+ const key = `${at.range[0]}:${what}`
103
+ if (reported.has(key) || isEscaped(context, at)) return
104
+ reported.add(key)
105
+ context.report({ loc: (node as unknown as Node).loc, messageId: 'scroll', data: { what } })
106
+ }
107
+ const classTokens = (node: Rule.Node, value: string) => {
108
+ for (const token of value.split(/\s+/)) if (token && SCROLL_CLASS.test(utilityOf(token))) scroll(node, token)
109
+ }
83
110
  return {
111
+ Literal(node: Rule.Node) {
112
+ const literal = node as unknown as { value: unknown; parent?: { type: string } }
113
+ if (typeof literal.value !== 'string') return
114
+ if (literal.parent && /^(Import|Export)|^TSLiteralType$|^TSExternalModuleReference$/.test(literal.parent.type)) return
115
+ classTokens(node, literal.value)
116
+ },
117
+ TemplateElement(node: Rule.Node) {
118
+ const cooked = (node as unknown as { value: { cooked: string | null } }).value.cooked
119
+ if (cooked) classTokens(node, cooked)
120
+ },
121
+ Property(node: Rule.Node) {
122
+ const property = node as unknown as { key: { type: string; name?: string; value?: unknown }; value: { type: string; value?: unknown } }
123
+ const name = property.key.type === 'Identifier' ? property.key.name : typeof property.key.value === 'string' ? property.key.value : undefined
124
+ if (!name || !/^overflow[XY]?$/.test(name)) return
125
+ const setting = property.value.type === 'Literal' ? property.value.value : undefined
126
+ if (setting === 'auto' || setting === 'scroll') scroll(node, `${name}: '${setting}'`)
127
+ },
84
128
  ImportDeclaration(node: Rule.Node) {
85
129
  const declaration = node as unknown as ImportDeclaration
86
130
  if (declaration.source.value !== 'react-dom') return
package/src/looks.ts CHANGED
@@ -70,7 +70,7 @@ export const COLLAPSIBLE_PANEL_CLASSES = 'h-[var(--collapsible-panel-height)] ov
70
70
 
71
71
  /**
72
72
  * The box a message or a comment is written in: Peek's writing box (its
73
- * `looks.ts`, Katerina 24 September), moved with ComposeBox. Inset, a hairline,
73
+ * `looks.ts`, Katerina 24 September), moved with the comment box. Inset, a hairline,
74
74
  * 12px in, 16px between the text and the row under it; the focus ring in Signal.
75
75
  */
76
76
  export const WRITING_BOX_CLASSES =