@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.
@@ -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/links.ts CHANGED
@@ -43,7 +43,10 @@ export const PasteOverWords = Extension.create({
43
43
  return false
44
44
  })
45
45
  if (plain && LINK_ON_WORDS_TARGET.test(url) && !/[[\]\n]/.test(state.doc.textBetween(from, to))) {
46
- view.dispatch(state.tr.addMark(from, to, schema.marks.link.create({ href: url })))
46
+ // The caret goes after the link: left selected, the words open the selection strip's Link field,
47
+ // which takes focus and the next Enter, so a box needed two to send (COMM-8).
48
+ const tr = state.tr.addMark(from, to, schema.marks.link.create({ href: url }))
49
+ view.dispatch(tr.setSelection(TextSelection.create(tr.doc, to)).removeStoredMark(schema.marks.link))
47
50
  return true
48
51
  }
49
52
  const before = state.doc.textBetween(Math.max(to - 1, $to.start()), to, '', '')
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 =
@@ -596,11 +596,10 @@ describe('one search over the package and the apps', () => {
596
596
  root: app({ 'src/Composer.tsx': '/** Where a comment is written and sent. */\nexport function Composer() {\n return <form />\n}\n' }),
597
597
  repo: 'fixture',
598
598
  })
599
- // Since the Leaf prototype (9 October) the package has a box for writing comments, ComposeBox, and it answers first by its
600
- // own purpose. What this guards still holds: the app's composer is found above the parts the words reach only through notes.
599
+ // The package's one box for writing is CommentBox (ComposeBox went into it, 21 October); the app's own composer still answers
600
+ // first, above the parts the words reach only through notes.
601
601
  const found = findInRegistries([packageRegistry, composer], 'comment composer', { limit: 10 }).map((f) => `${f.entry.repo}:${f.entry.name}`)
602
- expect(found[0]).toBe('estiva-ui:ComposeBox')
603
- expect(found.indexOf('fixture:Composer')).toBeGreaterThan(0)
602
+ expect(found[0]).toBe('fixture:Composer')
604
603
  const triggers = found.indexOf('estiva-ui:ComposerTriggers')
605
604
  if (triggers >= 0) expect(found.indexOf('fixture:Composer')).toBeLessThan(triggers)
606
605
  })
@@ -48,20 +48,20 @@ describe('the registry builds', () => {
48
48
  expect(registry.entries.map((one) => one.name).sort()).toEqual(values.map((one) => one.name).sort())
49
49
  })
50
50
 
51
- it('counts 209 names over 97 files: 141 components, 65 helpers and 3 hooks (LinkPlaces with linkPlaceAt and staysChip, a link in a document drawn where it sits (WBD-4), on 20 October; DocumentEditor, one document editor for every app, and PersonReference, `@` in a document (WBD-3), on 20 October; toggleTableHeaderRow, a table’s header row on and off (LEAF-12), on 19 October;EntryShell, the screen while nobody is signed in, moved from Peek (AUT-3), on 17 October; CommentBox with commentBoxRows, and ReactionRow with AddReactionButton and whoReacted, the shared comment box and reaction row (COMM-2), on 17 October; the link widgets — LinkChip, LinkRow, LinkCard, CardUnder, PartCard, LinkPreview and their parts, with useCanHover, chosenOf, loadingShapeOf and unavailableMemory — from the Widgets 2 prototype, on 16 October; InlineText, a title or the line under it edited where it stands (SUM-4), on 16 October; ComposeBox with ComposeKeys and its classes, CommentHighlights with its five helpers, and keepSelection and releaseSelection, from the Leaf prototype (LEAF-4), on 16 October;NavTree, NavTreeSection, the composer triggers and UnreadDot joined on 2 October; BlockHandle and EditorBlockHandle (RIC-18) on 2 October, moveBlock and blockDropCursor, the drop in the gutter, on 5 October, MembersPill and MembersDialog, moved from Peek (SHI-31), on 6 October, ShowMore on 7 October, AppProvider on 8 October, and KindIcon, thingKindOf and PastedImages with its two helpers, moved from Peek, on 8 October; CodeBlockColours, the coloured code block of the editor, on 9 October; Checklist, Callout, isChecklistTick and calloutLook (RIC-19) on 13 October; EditorTableControls and its four actions (RIC-21) on 13 October; ReferenceCards, useReferenceCards and its three helpers, the card a chip in a document asks for, on 14 October; LinkChips and its two helpers, a URL in a document read as its chip, on 14 October; ReferenceMenu, ReferenceMenuView and three helpers, the menu of a chip while writing, on 14 October; PastedMarkdown, markdown pasted as the blocks it spells (LEAF-10), on 15 October; turnIntoRows, turnListInto and turnQuoteInto, the block menu’s Turn into for a list and a quote (LEAF-11), on 15 October)', () => {
51
+ it('counts 206 names over 96 files: 139 components, 64 helpers and 3 hooks (ComposeBox, ComposeKeys and COMPOSE_EDITOR_CLASSES gone into CommentBox’s own frame (one box), on 21 October; LinkPlaces with linkPlaceAt and staysChip, a link in a document drawn where it sits (WBD-4), on 20 October; DocumentEditor, one document editor for every app, and PersonReference, `@` in a document (WBD-3), on 20 October; toggleTableHeaderRow, a table’s header row on and off (LEAF-12), on 19 October;EntryShell, the screen while nobody is signed in, moved from Peek (AUT-3), on 17 October; CommentBox with commentBoxRows, and ReactionRow with AddReactionButton and whoReacted, the shared comment box and reaction row (COMM-2), on 17 October; the link widgets — LinkChip, LinkRow, LinkCard, CardUnder, PartCard, LinkPreview and their parts, with useCanHover, chosenOf, loadingShapeOf and unavailableMemory — from the Widgets 2 prototype, on 16 October; InlineText, a title or the line under it edited where it stands (SUM-4), on 16 October; ComposeBox with ComposeKeys and its classes, CommentHighlights with its five helpers, and keepSelection and releaseSelection, from the Leaf prototype (LEAF-4), on 16 October;NavTree, NavTreeSection, the composer triggers and UnreadDot joined on 2 October; BlockHandle and EditorBlockHandle (RIC-18) on 2 October, moveBlock and blockDropCursor, the drop in the gutter, on 5 October, MembersPill and MembersDialog, moved from Peek (SHI-31), on 6 October, ShowMore on 7 October, AppProvider on 8 October, and KindIcon, thingKindOf and PastedImages with its two helpers, moved from Peek, on 8 October; CodeBlockColours, the coloured code block of the editor, on 9 October; Checklist, Callout, isChecklistTick and calloutLook (RIC-19) on 13 October; EditorTableControls and its four actions (RIC-21) on 13 October; ReferenceCards, useReferenceCards and its three helpers, the card a chip in a document asks for, on 14 October; LinkChips and its two helpers, a URL in a document read as its chip, on 14 October; ReferenceMenu, ReferenceMenuView and three helpers, the menu of a chip while writing, on 14 October; PastedMarkdown, markdown pasted as the blocks it spells (LEAF-10), on 15 October; turnIntoRows, turnListInto and turnQuoteInto, the block menu’s Turn into for a list and a quote (LEAF-11), on 15 October)', () => {
52
52
  // The reconciliation GATES.md §24 explains. If this changes, that changes.
53
53
  // The `EDITOR_EXTENSIONS` count as components by their names; they are
54
54
  // editor extensions, documented on SelectionToolbar's, BlockNodes' and
55
55
  // ComposerTriggers' pages.
56
56
  const kinds = registry.entries.reduce<Record<string, number>>((all, one) => ({ ...all, [one.kind]: (all[one.kind] ?? 0) + 1 }), {})
57
- expect(kinds).toEqual({ component: 141, helper: 65, hook: 3 })
58
- expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(97)
57
+ expect(kinds).toEqual({ component: 139, helper: 64, hook: 3 })
58
+ expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(96)
59
59
  })
60
60
 
61
61
  it('gives every entry a purpose, from its own page or from the comment above it', () => {
62
62
  expect(registry.entries.filter((one) => one.purpose.trim() === '')).toEqual([])
63
- expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(91)
64
- expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(118)
63
+ expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(90)
64
+ expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(116)
65
65
  })
66
66
 
67
67
  it('takes a name with a page of its own from the page, and a name without one from the code', () => {
@@ -76,7 +76,6 @@ fork freely, owe nothing back, mention it on the package's ticket.
76
76
  | An editor that saves a block document and must keep its block ids | **BlockNodes** — `BlockId`, `UnknownBlock`, `ReferenceNode` and `AttachmentNode` from `@estiva-app/ui/editor`, beside StarterKit and TableKit |
77
77
  | A page's title or the line under it, edited where it stands, as in a document | **InlineText**, from `@estiva-app/ui/editor` — no box; Enter saves and moves on |
78
78
  | A comment, a reply or a line written and sent, in any app | **CommentBox**, from `@estiva-app/ui/editor` — triggers, keys, drafts, files, editing and a refused send; the app supplies its people, its `[` sections, its `/` rows and a send |
79
- | The box alone, around an editor the app makes itself | **ComposeBox**, from `@estiva-app/ui/editor` — the app brings its editor and adds `ComposeKeys` |
80
79
  | Comments on words, a passage or whole blocks of a document, drawn where they are | **CommentHighlights**, from `@estiva-app/ui/editor` — a run of blocks and the words quoted; says which was clicked and which moved or are gone |
81
80
  | Move, turn, duplicate or delete one block of a document being edited | **EditorBlockHandle**, from `@estiva-app/ui/editor`, with your rows after its own |
82
81
  | Add or delete a table's rows and columns in a document being edited | **EditorTableControls**, from `@estiva-app/ui/editor`, inside the EditorBlockHandle |
@@ -1,57 +0,0 @@
1
- import { type ReactNode } from 'react';
2
- import { Extension } from '@tiptap/core';
3
- import { type Editor } from '@tiptap/react';
4
- import { type SelectionToolbarProps } from './SelectionToolbar';
5
- /**
6
- * The box a message, a reply or a comment is written in, from Katerina's Leaf
7
- * prototype (9 October). Peek's `ComposeBox`, its look and its keys, with
8
- * what only Peek knows left in Peek: drafts, uploads, highlights, its text
9
- * format. The app makes the editor (its extensions are its own) and adds
10
- * `ComposeKeys`; this draws the box around it and sends.
11
- */
12
- /** The editor's own classes inside the box: Peek's, rich text with no outline. Put them in `editorProps.attributes.class`. */
13
- export declare const COMPOSE_EDITOR_CLASSES: string;
14
- type ComposeKeysStorage = {
15
- send: (() => boolean) | null;
16
- };
17
- /**
18
- * Enter sends; Shift+Enter is a new line — in a list a new item (or out of the
19
- * list, on an empty one), in a quote a new line (or out of it, on an empty one).
20
- * Peek's keys, as its ComposeBox has them. Enter while a `/`, `@` or `[` list is
21
- * open picks a row instead. `ComposeBox` says what sending does.
22
- */
23
- export declare const ComposeKeys: Extension<Record<string, never>, ComposeKeysStorage>;
24
- /** Nothing written: no text, no chip and no picture — empty lines, spaces, lists or quotes only. */
25
- export declare function isEmptyDoc(editor: Editor): boolean;
26
- export interface ComposeBoxProps {
27
- /** The app's editor, with `ComposeKeys` in its extensions and `COMPOSE_EDITOR_CLASSES` on it. `null` while it loads. */
28
- editor: Editor | null;
29
- /**
30
- * Send what is written. The box empties afterwards — unless this returns
31
- * `false`: nothing was sent, and the words stay.
32
- */
33
- onSend: (editor: Editor) => void | boolean;
34
- /** Said in the empty box: words, and a `Kbd` where a key helps ("type / for commands"). */
35
- placeholder: ReactNode;
36
- /** The tools under the text, left: `ToolbarButton`s (attach, highlight). One Tab stop. */
37
- tools?: ReactNode;
38
- /** What is attached, under the text: `AttachmentCard pending`s. */
39
- attachments?: ReactNode;
40
- /** Something to send even with no words — a file ready. */
41
- ready?: boolean;
42
- /** Sending waits — a file still uploading. */
43
- holding?: boolean;
44
- /** The bar down the text's left: an urgent mention or a highlight, as Peek draws it. */
45
- marked?: boolean;
46
- /** The selection strip's buttons: its marks, Link, and the app's own (`actions`). */
47
- selection?: Pick<SelectionToolbarProps, 'marks' | 'link' | 'actions'>;
48
- className?: string;
49
- }
50
- /**
51
- * The box for writing: the text, the selection strip over it, what is
52
- * attached, the tools and Send. Enter sends (`ComposeKeys`), and so does the
53
- * button.
54
- */
55
- export declare function ComposeBox({ editor, onSend, placeholder, tools, attachments, ready, holding, marked, selection, className }: ComposeBoxProps): import("react").JSX.Element;
56
- export {};
57
- //# sourceMappingURL=ComposeBox.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ComposeBox.d.ts","sourceRoot":"","sources":["../src/ComposeBox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AAO1D,OAAO,EAAoB,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAGjF;;;;;;GAMG;AAEH,8HAA8H;AAC9H,eAAO,MAAM,sBAAsB,QAAgG,CAAA;AAEnI,KAAK,kBAAkB,GAAG;IAAE,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG,IAAI,CAAA;CAAE,CAAA;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,WAAW,sDA4BtB,CAAA;AAEF,oGAAoG;AACpG,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CASlD;AAED,MAAM,WAAW,eAAe;IAC9B,wHAAwH;IACxH,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB;;;OAGG;IACH,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAA;IAC1C,2FAA2F;IAC3F,WAAW,EAAE,SAAS,CAAA;IACtB,0FAA0F;IAC1F,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,mEAAmE;IACnE,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,8CAA8C;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,wFAAwF;IACxF,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,qFAAqF;IACrF,SAAS,CAAC,EAAE,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;IACrE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,KAAa,EAAE,OAAe,EAAE,MAAc,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,eAAe,+BAgFpK"}
@@ -1,58 +0,0 @@
1
- import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
- import * as ComposeBoxStories from './ComposeBox.stories'
3
-
4
- <Meta of={ComposeBoxStories} />
5
-
6
- # ComposeBox
7
-
8
- 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.
9
-
10
- <Canvas of={ComposeBoxStories.Default} />
11
-
12
- ## When
13
-
14
- - **Writing something that is sent**: a message, a reply, a comment. Enter sends, Shift+Enter is a new line.
15
- - `tools` for what acts on the draft — attach, highlight — as `ToolbarButton`s; they are one strip.
16
- - `attachments` for what is attached, as pending `AttachmentCard`s, under the text.
17
- - `marked` for the bar down the text's left while it holds an urgent mention or a highlight.
18
-
19
- <Canvas of={ComposeBoxStories.Reply} />
20
-
21
- ## When not
22
-
23
- - Editing a document in place → the editor itself, with **EditorBlockHandle** and **SelectionToolbar**. Nothing is sent.
24
- - One line of plain text in a form → **TextInput** or **Textarea**, in a **Form**.
25
-
26
- ## How
27
-
28
- ```tsx
29
- import { useEditor } from '@tiptap/react'
30
- import StarterKit from '@tiptap/starter-kit'
31
- import { ComposeBox, ComposeKeys, COMPOSE_EDITOR_CLASSES, KeptSelection } from '@estiva-app/ui/editor'
32
-
33
-
34
- const editor = useEditor({
35
- extensions: [StarterKit, KeptSelection, ComposeKeys /* and the app's own */],
36
- editorProps: { attributes: { class: COMPOSE_EDITOR_CLASSES } },
37
- })
38
-
39
- <ComposeBox editor={editor} onSend={(ed) => send(ed.getJSON())} placeholder={<span>Reply…</span>} />
40
- ```
41
-
42
- - **The app makes the editor.** Its extensions — mentions, references, `/` — are the app's; add `ComposeKeys`, and `COMPOSE_EDITOR_CLASSES` on the editor.
43
- - **`onSend` gets the editor** and writes what it holds in the app's own format. The box empties after it, unless it returns `false`.
44
- - `ready` when something can be sent with no words (a file is ready); `holding` while sending must wait (a file is uploading).
45
-
46
- ## What it owns
47
-
48
- It does these by itself. Write none of them around it.
49
-
50
- | It does | So you never write |
51
- |---|---|
52
- | Enter sends, unless a `/`, `@` or `[` list is open | a keydown handler |
53
- | Shift+Enter: a new line, a new list item, out of an empty item or quote line | list and quote commands |
54
- | Send presses on the way down, so the caret stays in the text | `preventDefault` on the button |
55
- | The placeholder while nothing is written | an empty check |
56
- | The selection strip over selected words | `SelectionToolbar` beside it |
57
-
58
- <Controls />
@@ -1,81 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite'
2
- import { useState } from 'react'
3
- import { IconPaperclip } from '@tabler/icons-react'
4
- import { useEditor, type Editor } from '@tiptap/react'
5
- import StarterKit from '@tiptap/starter-kit'
6
- import { AttachmentCard } from './AttachmentCard'
7
- import { Kbd } from './Kbd'
8
- import { ToolbarButton } from './Toolbar'
9
- import { ComposeBox, ComposeKeys, COMPOSE_EDITOR_CLASSES } from './ComposeBox'
10
- import { KeptSelection } from './SelectionToolbar'
11
-
12
- /**
13
- * The box a message, a reply or a comment is written in. Type, select
14
- * words for the strip, Enter to send, Shift+Enter for a new line.
15
- */
16
- const meta = {
17
- title: 'Primitives/ComposeBox',
18
- component: ComposeBox,
19
- parameters: { layout: 'padded' },
20
- decorators: [
21
- (Story) => (
22
- <div className="w-[480px]">
23
- <Story />
24
- </div>
25
- ),
26
- ],
27
- } satisfies Meta<typeof ComposeBox>
28
-
29
- export default meta
30
- type Story = StoryObj
31
-
32
- function Writing({ tools, placeholder, file }: { tools?: boolean; placeholder: 'new' | 'reply'; file?: boolean }) {
33
- const [sent, setSent] = useState<string[]>([])
34
- const editor = useEditor({
35
- extensions: [StarterKit.configure({ link: { openOnClick: false } }), KeptSelection, ComposeKeys],
36
- editorProps: { attributes: { class: COMPOSE_EDITOR_CLASSES } },
37
- })
38
- return (
39
- <div className="flex flex-col gap-3">
40
- {sent.map((text, i) => (
41
- <p key={i} className="text-body-2 text-text-primary">
42
- {text}
43
- </p>
44
- ))}
45
- <ComposeBox
46
- editor={editor}
47
- onSend={(ed: Editor) => setSent((all) => [...all, ed.getText()])}
48
- selection={{ link: true }}
49
- ready={file}
50
- attachments={file ? <AttachmentCard pending name="brief.pdf" size={182_000} contentType="application/pdf" state="ready" onRemove={() => {}} /> : undefined}
51
- placeholder={
52
- placeholder === 'reply' ? (
53
- <span>Reply…</span>
54
- ) : (
55
- <>
56
- <span>Start a new conversation or type</span>
57
- <Kbd>/</Kbd>
58
- <span>for commands</span>
59
- </>
60
- )
61
- }
62
- tools={
63
- tools ? (
64
- <ToolbarButton tooltip="Attach files" aria-label="Attach files">
65
- <IconPaperclip size={16} stroke={1.5} />
66
- </ToolbarButton>
67
- ) : undefined
68
- }
69
- />
70
- </div>
71
- )
72
- }
73
-
74
- /** A new message, with a tool under the text. */
75
- export const Default: Story = { render: () => <Writing placeholder="new" tools /> }
76
-
77
- /** A reply: no tools, only Send. */
78
- export const Reply: Story = { render: () => <Writing placeholder="reply" /> }
79
-
80
- /** A file waiting to be sent: under the text, and Send is ready with no words. */
81
- export const WithAFile: Story = { render: () => <Writing placeholder="new" tools file /> }