@estiva-app/ui 0.75.0 β†’ 0.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * The shared reaction row (COMM-2): the pills in the order first chosen, the
4
+ * viewer's lit, who reacted, toggling, and no row when nobody reacted.
5
+ */
6
+ import { afterEach, describe, expect, it, vi } from 'vitest'
7
+ import { cleanup, fireEvent, render, screen } from '@testing-library/react'
8
+ import { ReactionRow, whoReacted } from './ReactionRow'
9
+
10
+ const OPTIONS = [
11
+ { emoji: 'πŸ‘', label: 'Makes sense' },
12
+ { emoji: 'πŸ™', label: 'Thank you' },
13
+ ]
14
+ const NAMES: Record<string, string> = { a: 'Person one', b: 'Person two', me: 'Me' }
15
+ const nameOf = (id: string) => NAMES[id] ?? 'Someone'
16
+
17
+ afterEach(() => cleanup())
18
+
19
+ describe('the pills', () => {
20
+ it('draws each emoji with its count in the order first chosen, the viewer’s pressed', () => {
21
+ render(
22
+ <ReactionRow
23
+ reactions={[
24
+ { emoji: 'πŸ™', by: ['a'] },
25
+ { emoji: 'πŸ‘', by: ['a', 'me'] },
26
+ ]}
27
+ options={OPTIONS}
28
+ nameOf={nameOf}
29
+ viewer="me"
30
+ onToggle={() => {}}
31
+ />,
32
+ )
33
+ const pills = screen.getAllByRole('button').filter((b) => b.getAttribute('aria-label') !== 'Add a reaction')
34
+ expect(pills.map((p) => p.getAttribute('aria-label'))).toEqual(['Thank you, 1', 'Makes sense, 2'])
35
+ expect(pills.map((p) => p.getAttribute('aria-pressed'))).toEqual(['false', 'true'])
36
+ })
37
+
38
+ it('a click toggles your reaction; read-only, the pills are disabled and nothing adds one', () => {
39
+ const onToggle = vi.fn()
40
+ const { rerender } = render(<ReactionRow reactions={[{ emoji: 'πŸ‘', by: ['a'] }]} options={OPTIONS} nameOf={nameOf} viewer="me" onToggle={onToggle} />)
41
+ fireEvent.click(screen.getByRole('button', { name: 'Makes sense, 1' }))
42
+ expect(onToggle).toHaveBeenCalledWith('πŸ‘')
43
+ rerender(<ReactionRow reactions={[{ emoji: 'πŸ‘', by: ['a'] }]} options={OPTIONS} nameOf={nameOf} viewer="me" />)
44
+ expect((screen.getByRole('button', { name: 'Makes sense, 1' }) as HTMLButtonElement).disabled).toBe(true)
45
+ expect(screen.queryByRole('button', { name: 'Add a reaction' })).toBeNull()
46
+ })
47
+
48
+ it('nobody reacted: no row at all', () => {
49
+ const { container } = render(<ReactionRow reactions={[{ emoji: 'πŸ‘', by: [] }]} options={OPTIONS} nameOf={nameOf} onToggle={() => {}} />)
50
+ expect(container.innerHTML).toBe('')
51
+ })
52
+ })
53
+
54
+ describe('who reacted', () => {
55
+ it('names the others, then you, with what the emoji means', () => {
56
+ expect(whoReacted({ emoji: 'πŸ‘', by: ['a', 'me', 'b'] }, nameOf, OPTIONS, 'me')).toBe('Person one, Person two and you reacted with Makes sense')
57
+ expect(whoReacted({ emoji: 'πŸ¦†', by: ['me'] }, nameOf, OPTIONS, 'me')).toBe('You reacted with πŸ¦†')
58
+ })
59
+
60
+ it('says nothing when nobody holds the emoji', () => {
61
+ expect(whoReacted({ emoji: 'πŸ‘', by: [] }, nameOf, OPTIONS, 'me')).toBe('')
62
+ })
63
+
64
+ it('counts the names past eight', () => {
65
+ const many = Array.from({ length: 11 }, (_, i) => `p${i}`)
66
+ expect(whoReacted({ emoji: 'πŸ‘', by: many }, () => 'P', OPTIONS)).toBe('P, P, P, P, P, P, P, P and 3 more reacted with Makes sense')
67
+ })
68
+ })
@@ -0,0 +1,118 @@
1
+ import { useState } from 'react'
2
+ import { IconMoodPlus } from '@tabler/icons-react'
3
+ import { cn } from './cn'
4
+ import { IconButton } from './IconButton'
5
+ import { Popover } from './Popover'
6
+ import { Reaction } from './Reaction'
7
+ import { ReactionPicker, type ReactionOption } from './ReactionPicker'
8
+ import { WithTooltip } from './Tooltip'
9
+
10
+ /**
11
+ * The one reaction row every app draws under a comment or a chat line, from
12
+ * the approved prototype (`concept/comments-everywhere`, Miky 17 October):
13
+ * `Reaction` pills in the order they were first chosen, each saying who
14
+ * reacted on hover, then the add button with `ReactionPicker`. Nobody reacted:
15
+ * no row; the add button sits with the other actions (`AddReactionButton`).
16
+ *
17
+ * What a reaction writes and how reactions are counted stay in
18
+ * `@estiva-app/conversation` (SPEC Β§6.6): its `groupReactions` answers the
19
+ * `reactions` this takes, and its `REACTION_EMOJI` the five `options`.
20
+ *
21
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/every-app-writes-and-reacts-with-one-shared-box.md
22
+ */
23
+
24
+ /** One emoji on one target, and who put it there, in the order they reacted. */
25
+ export interface ReactionCount {
26
+ emoji: string
27
+ by: readonly string[]
28
+ }
29
+
30
+ /** Names past this many are counted, not listed. */
31
+ const NAMED = 8
32
+
33
+ const meaningOf = (options: readonly ReactionOption[], emoji: string) => options.find((o) => o.emoji === emoji)?.label ?? emoji
34
+
35
+ /** "Person one, Person two and you reacted with Makes sense". */
36
+ export function whoReacted(reaction: ReactionCount, nameOf: (id: string) => string, options: readonly ReactionOption[], viewer?: string): string {
37
+ if (reaction.by.length === 0) return ''
38
+ const others = reaction.by.filter((id) => id !== viewer).map(nameOf)
39
+ const you = viewer !== undefined && reaction.by.includes(viewer)
40
+ const named = others.slice(0, you ? NAMED - 1 : NAMED)
41
+ const rest = others.length - named.length
42
+ const names = [...named, ...(rest > 0 ? [`${rest} more`] : []), ...(you ? ['you'] : [])]
43
+ const list = names.length > 1 ? `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}` : (names[0] ?? '')
44
+ return `${list.charAt(0).toUpperCase()}${list.slice(1)} reacted with ${meaningOf(options, reaction.emoji)}`
45
+ }
46
+
47
+ export interface AddReactionButtonProps {
48
+ /** The emoji offered, each named. */
49
+ options: readonly ReactionOption[]
50
+ onPick: (emoji: string) => void
51
+ className?: string
52
+ }
53
+
54
+ /** The add button: `ReactionPicker` opens over it. */
55
+ export function AddReactionButton({ options, onPick, className }: AddReactionButtonProps) {
56
+ const [picking, setPicking] = useState(false)
57
+ return (
58
+ <Popover
59
+ open={picking}
60
+ onOpenChange={setPicking}
61
+ side="top"
62
+ align="left"
63
+ ariaLabel="Add a reaction"
64
+ contentClassName="p-1"
65
+ className={className}
66
+ trigger={
67
+ <IconButton variant="muted" tooltip="Add a reaction" aria-label="Add a reaction">
68
+ <IconMoodPlus size={16} stroke={1.5} />
69
+ </IconButton>
70
+ }
71
+ >
72
+ <ReactionPicker
73
+ options={[...options]}
74
+ surface={false}
75
+ onSelect={(emoji) => {
76
+ setPicking(false)
77
+ onPick(emoji)
78
+ }}
79
+ />
80
+ </Popover>
81
+ )
82
+ }
83
+
84
+ export interface ReactionRowProps {
85
+ /** Each emoji and who chose it, in the order first chosen. An emoji nobody holds is not drawn. */
86
+ reactions: readonly ReactionCount[]
87
+ /** The emoji offered, each named; also what a pill's name is read from. */
88
+ options: readonly ReactionOption[]
89
+ /** A reactor's name, as "who reacted" says it. */
90
+ nameOf: (id: string) => string
91
+ /** Who is looking: their pills are lit, and "who reacted" says "you". */
92
+ viewer?: string
93
+ /** Your reaction on or off. Absent, the row only shows (read-only, signed out). */
94
+ onToggle?: (emoji: string) => void
95
+ className?: string
96
+ }
97
+
98
+ export function ReactionRow({ reactions, options, nameOf, viewer, onToggle, className }: ReactionRowProps) {
99
+ const shown = reactions.filter((r) => r.by.length > 0)
100
+ if (shown.length === 0) return null
101
+ return (
102
+ <div data-reaction-row className={cn('flex flex-wrap items-center gap-1', className)}>
103
+ {shown.map((r) => (
104
+ <WithTooltip key={r.emoji} label={whoReacted(r, nameOf, options, viewer)}>
105
+ <Reaction
106
+ emoji={r.emoji}
107
+ count={r.by.length}
108
+ pressed={viewer !== undefined && r.by.includes(viewer)}
109
+ disabled={!onToggle}
110
+ aria-label={`${meaningOf(options, r.emoji)}, ${r.by.length}`}
111
+ onClick={() => onToggle?.(r.emoji)}
112
+ />
113
+ </WithTooltip>
114
+ ))}
115
+ {onToggle && <AddReactionButton options={options} onPick={onToggle} />}
116
+ </div>
117
+ )
118
+ }
package/src/editor.ts CHANGED
@@ -9,6 +9,17 @@
9
9
  */
10
10
  export { KeptSelection, SelectionToolbar, keepSelection, releaseSelection, normalizeHref, type MarkId, type SelectionAction, type SelectionToolbarProps } from './SelectionToolbar'
11
11
  export { ComposeBox, ComposeKeys, COMPOSE_EDITOR_CLASSES, type ComposeBoxProps } from './ComposeBox'
12
+ export {
13
+ CommentBox,
14
+ commentBoxRows,
15
+ type CommentBoxProps,
16
+ type CommentBoxDraft,
17
+ type CommentBoxEdit,
18
+ type BoxFile,
19
+ type BoxFileState,
20
+ type SendAnswer,
21
+ type UploadAnswer,
22
+ } from './CommentBox'
12
23
  export { InlineText, type InlineTextProps, type InlineTextHandle } from './InlineText'
13
24
  export {
14
25
  CommentHighlights,
package/src/index.ts CHANGED
@@ -117,6 +117,7 @@ export { TopBar, type TopBarProps } from './TopBar'
117
117
  export { PersonTrigger, type PersonTriggerProps } from './PersonTrigger'
118
118
  export { Property, type PropertyProps } from './Property'
119
119
  export { Reaction, type ReactionProps } from './Reaction'
120
+ export { ReactionRow, AddReactionButton, whoReacted, type ReactionRowProps, type AddReactionButtonProps, type ReactionCount } from './ReactionRow'
120
121
  export { SearchInput, type SearchInputProps } from './SearchInput'
121
122
  export { SectionHeader, type SectionAction, type SectionHeaderProps } from './SectionHeader'
122
123
  export { ContainerHeader, type ContainerHeaderProps } from './ContainerHeader'
@@ -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 197 names over 92 files: 134 components, 60 helpers and 3 hooks (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 202 names over 94 files: 137 components, 62 helpers and 3 hooks (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: 134, helper: 60, hook: 3 })
58
- expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(92)
57
+ expect(kinds).toEqual({ component: 137, helper: 62, hook: 3 })
58
+ expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(94)
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(86)
64
- expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(111)
63
+ expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(88)
64
+ expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(114)
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', () => {
@@ -67,13 +67,15 @@ fork freely, owe nothing back, mention it on the package's ticket.
67
67
  | A hint on hover or on keyboard focus | **Tooltip** / **WithTooltip** β€” one `TooltipProvider` at the app root shares the delay |
68
68
  | A strip of controls that act on one thing | **Toolbar** β€” one Tab stop for the row, arrow keys along it |
69
69
  | Reactions to choose from | **ReactionPicker** β€” the row; **Reaction** is the pill it produces |
70
+ | The reactions under something people react to, and adding one | **ReactionRow** β€” the pills, who reacted, and the picker; **AddReactionButton** alone while nobody has reacted |
70
71
  | One window to find something and act on it, opened by a shortcut | **CommandPalette** β€” rows, forms and written answers, one level at a time |
71
72
  | A list that opens as you type in an editor β€” `/` for commands, `@` for people | **SuggestionMenu** β€” the editor keeps the caret and hands it the arrow keys; `suggestionPopup` from `@estiva-app/ui/editor` wires it to a Tiptap plugin |
72
73
  | Bold, italic and the like over selected text in an editor | **SelectionToolbar**, from `@estiva-app/ui/editor` β€” it follows the selection by itself |
73
74
  | A composer's `@`, `!@`, `[` and `/` β€” mention a person, reference something, format or insert | **ComposerTriggers** β€” `PersonMention`, `UrgentPersonMention`, `CaptionedReference`, `ReferenceTrigger` and `SlashCommands` from `@estiva-app/ui/editor`; the app passes its people, its items and its own `/` rows |
74
75
  | 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 |
75
76
  | 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 |
76
- | The box a message, a reply or a comment is written in and sent | **ComposeBox**, from `@estiva-app/ui/editor` β€” the app brings its editor and adds `ComposeKeys` |
77
+ | 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 |
78
+ | The box alone, around an editor the app makes itself | **ComposeBox**, from `@estiva-app/ui/editor` β€” the app brings its editor and adds `ComposeKeys` |
77
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 |
78
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 |
79
81
  | Add or delete a table's rows and columns in a document being edited | **EditorTableControls**, from `@estiva-app/ui/editor`, inside the EditorBlockHandle |