@estiva-app/ui 0.108.1 → 0.109.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 +5 -0
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/ConversationCard.d.ts +5 -0
- package/dist/ConversationCard.d.ts.map +1 -1
- package/dist/ConversationHeading.d.ts +21 -0
- package/dist/ConversationHeading.d.ts.map +1 -0
- package/dist/editor.js +7 -6
- package/dist/editor.js.map +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +141 -110
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/registry.json +68 -3
- package/src/CommentBox.test.tsx +19 -1
- package/src/CommentBox.tsx +14 -7
- package/src/ConversationCard.tsx +23 -4
- package/src/ConversationHeading.mdx +52 -0
- package/src/ConversationHeading.stories.tsx +44 -0
- package/src/ConversationHeading.test.tsx +81 -0
- package/src/ConversationHeading.tsx +55 -0
- package/src/ConversationLayout.stories.tsx +60 -0
- package/src/index.ts +1 -0
- package/src/registry/registry.test.ts +4 -4
- package/stories/Choosing.mdx +1 -0
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.109.0",
|
|
8
|
+
"exports": 251,
|
|
9
|
+
"typeExports": 260,
|
|
10
10
|
"files": null
|
|
11
11
|
},
|
|
12
12
|
"storybook": {
|
|
@@ -2298,6 +2298,12 @@
|
|
|
2298
2298
|
"required": false,
|
|
2299
2299
|
"note": "The app shows a send before the relay answers: the box empties at once, and a refusal puts the words back."
|
|
2300
2300
|
},
|
|
2301
|
+
{
|
|
2302
|
+
"name": "reply",
|
|
2303
|
+
"takes": "true/false",
|
|
2304
|
+
"required": false,
|
|
2305
|
+
"note": "The box answers a message, which can be deleted while you write: a send refused because it went says \"this message was deleted, or you can no longer write here\"."
|
|
2306
|
+
},
|
|
2301
2307
|
{
|
|
2302
2308
|
"name": "label",
|
|
2303
2309
|
"takes": "text",
|
|
@@ -2759,6 +2765,12 @@
|
|
|
2759
2765
|
"purpose": "One comment, the same in every app: who, when, the words, files, cards, reactions and the way into its replies, with the actions on hover and the ⋯ menu.",
|
|
2760
2766
|
"purposeFrom": "page",
|
|
2761
2767
|
"props": [
|
|
2768
|
+
{
|
|
2769
|
+
"name": "heading",
|
|
2770
|
+
"takes": "anything",
|
|
2771
|
+
"required": false,
|
|
2772
|
+
"note": "Where it was said, at the top of the card: a `ConversationHeading`, when one list mixes conversations from several places."
|
|
2773
|
+
},
|
|
2762
2774
|
{
|
|
2763
2775
|
"name": "deleted",
|
|
2764
2776
|
"takes": "true/false",
|
|
@@ -3004,6 +3016,59 @@
|
|
|
3004
3016
|
"app": null,
|
|
3005
3017
|
"looks": []
|
|
3006
3018
|
},
|
|
3019
|
+
{
|
|
3020
|
+
"name": "ConversationHeading",
|
|
3021
|
+
"repo": "estiva-ui",
|
|
3022
|
+
"kind": "component",
|
|
3023
|
+
"importPath": "@estiva-app/ui",
|
|
3024
|
+
"sourceFile": "src/ConversationHeading.tsx",
|
|
3025
|
+
"purpose": "Which place a conversation is on, inside its card, when one list mixes conversations from several places.",
|
|
3026
|
+
"purposeFrom": "page",
|
|
3027
|
+
"props": [
|
|
3028
|
+
{
|
|
3029
|
+
"name": "icon",
|
|
3030
|
+
"takes": "anything",
|
|
3031
|
+
"required": true,
|
|
3032
|
+
"note": "What kind of place it is: a `KindIcon`, 16px."
|
|
3033
|
+
},
|
|
3034
|
+
{
|
|
3035
|
+
"name": "name",
|
|
3036
|
+
"takes": "text",
|
|
3037
|
+
"required": true,
|
|
3038
|
+
"note": "The place's name, cut to the column."
|
|
3039
|
+
},
|
|
3040
|
+
{
|
|
3041
|
+
"name": "onOpen",
|
|
3042
|
+
"takes": "a handler",
|
|
3043
|
+
"required": false,
|
|
3044
|
+
"note": "Pressing the name opens the place. Without it (and without `href`) the name is plain text."
|
|
3045
|
+
},
|
|
3046
|
+
{
|
|
3047
|
+
"name": "href",
|
|
3048
|
+
"takes": "text",
|
|
3049
|
+
"required": false,
|
|
3050
|
+
"note": "Or a link to the place. With `onOpen` too, a plain click calls `onOpen` and the link only serves a new tab."
|
|
3051
|
+
},
|
|
3052
|
+
{
|
|
3053
|
+
"name": "className",
|
|
3054
|
+
"takes": "text",
|
|
3055
|
+
"required": false,
|
|
3056
|
+
"note": "Placement only."
|
|
3057
|
+
}
|
|
3058
|
+
],
|
|
3059
|
+
"variants": [],
|
|
3060
|
+
"ownsBehaviours": [],
|
|
3061
|
+
"status": "stable",
|
|
3062
|
+
"migrationStage": null,
|
|
3063
|
+
"docsId": "conversation-conversationheading--docs",
|
|
3064
|
+
"storyId": "conversation-conversationheading--on-a-card",
|
|
3065
|
+
"docPage": "src/ConversationHeading.mdx",
|
|
3066
|
+
"app": null,
|
|
3067
|
+
"looks": [
|
|
3068
|
+
"-mx-1 truncate rounded text-left text-h4 text-text-primary",
|
|
3069
|
+
"-mx-1 truncate rounded text-left text-h4 text-text-primary hover:bg-bg-hover"
|
|
3070
|
+
]
|
|
3071
|
+
},
|
|
3007
3072
|
{
|
|
3008
3073
|
"name": "ConversationLayout",
|
|
3009
3074
|
"repo": "estiva-ui",
|
package/src/CommentBox.test.tsx
CHANGED
|
@@ -100,7 +100,25 @@ describe('sending, held until the relay answers', () => {
|
|
|
100
100
|
expect(screen.queryByText(/262144|invalid:/)).toBeNull()
|
|
101
101
|
})
|
|
102
102
|
|
|
103
|
-
it('a
|
|
103
|
+
it('a reply refused because its message was deleted says the message was deleted, and the text stays in the box', async () => {
|
|
104
|
+
render(<Box reply send={async () => ({ accepted: false, reason: 'invalid: reply parent not found in this team' })} />)
|
|
105
|
+
await type('Hello there')
|
|
106
|
+
await press('Enter')
|
|
107
|
+
await settle()
|
|
108
|
+
expect(editorOf().getText()).toBe('Hello there')
|
|
109
|
+
expect(screen.getByText('Not sent: this message was deleted, or you can no longer write here. Your text is back in the box.')).toBeTruthy()
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('a reply shown at once and refused because its message was deleted says so, with the text put back', async () => {
|
|
113
|
+
render(<Box reply showsAtOnce send={async () => ({ accepted: false, reason: 'invalid: reply parent not found in this team' })} />)
|
|
114
|
+
await type('Hello there')
|
|
115
|
+
await press('Enter')
|
|
116
|
+
await settle()
|
|
117
|
+
expect(editorOf().getText()).toBe('Hello there')
|
|
118
|
+
expect(screen.getByText('Not sent: this message was deleted, or you can no longer write here. Your text is back in the box.')).toBeTruthy()
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('a new message refused as on a deleted message says you can no longer write here, not that a message was deleted', async () => {
|
|
104
122
|
render(<Box send={async () => ({ accepted: false, reason: 'invalid: reply target event not found' })} />)
|
|
105
123
|
await type('Hello there')
|
|
106
124
|
await press('Enter')
|
package/src/CommentBox.tsx
CHANGED
|
@@ -80,12 +80,13 @@ export interface BoxFile {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Why a send was refused. "This message was deleted" is an edit's
|
|
84
|
-
*
|
|
83
|
+
* Why a send was refused. "This message was deleted" is an edit's, a reaction's (Decided, ONE-4) and a reply's, whose
|
|
84
|
+
* message may have gone while it was written (Decided, ONE-10, 9 November); a new top-level message refused the same
|
|
85
|
+
* way is one you can no longer write here.
|
|
85
86
|
*/
|
|
86
|
-
function sendRefusal(reason: unknown): string {
|
|
87
|
+
function sendRefusal(reason: unknown, reply: boolean): string {
|
|
87
88
|
const cause = refusalCause(reason)
|
|
88
|
-
return REFUSAL_REASONS[cause === 'gone' ? 'no-access' : cause]
|
|
89
|
+
return REFUSAL_REASONS[cause === 'gone' && !reply ? 'no-access' : cause]
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
/** A draft, in the box's terms — `@estiva-app/conversation`'s `composerDraft` is one. */
|
|
@@ -182,6 +183,11 @@ export interface CommentBoxProps {
|
|
|
182
183
|
* until the answer.
|
|
183
184
|
*/
|
|
184
185
|
showsAtOnce?: boolean
|
|
186
|
+
/**
|
|
187
|
+
* The box answers a message, which can be deleted while you write: a send refused because it went says "this message
|
|
188
|
+
* was deleted, or you can no longer write here". A box that starts something new says "you can no longer write here".
|
|
189
|
+
*/
|
|
190
|
+
reply?: boolean
|
|
185
191
|
/** The editor's accessible name: what the box is for. */
|
|
186
192
|
label: string
|
|
187
193
|
/** Said in the empty box. */
|
|
@@ -506,6 +512,7 @@ function OpenCommentBox({
|
|
|
506
512
|
marked,
|
|
507
513
|
onEditor,
|
|
508
514
|
className,
|
|
515
|
+
reply = false,
|
|
509
516
|
}: CommentBoxProps) {
|
|
510
517
|
const [files, setFiles] = useState<BoxFile[]>(edit?.files ?? [])
|
|
511
518
|
const [sending, setSending] = useState(false)
|
|
@@ -700,7 +707,7 @@ function OpenCommentBox({
|
|
|
700
707
|
ed.commands.focus('end')
|
|
701
708
|
setRemoved((now) => new Set([...now, ...took]))
|
|
702
709
|
setFiles((all) => [...sent, ...all])
|
|
703
|
-
setRefused(sendRefusal(answer.reason))
|
|
710
|
+
setRefused(sendRefusal(answer.reason, reply))
|
|
704
711
|
})
|
|
705
712
|
return true
|
|
706
713
|
}
|
|
@@ -710,7 +717,7 @@ function OpenCommentBox({
|
|
|
710
717
|
setSending(false)
|
|
711
718
|
if (!answer.accepted) {
|
|
712
719
|
layout?.refused()
|
|
713
|
-
setRefused(sendRefusal(answer.reason))
|
|
720
|
+
setRefused(sendRefusal(answer.reason, reply))
|
|
714
721
|
return
|
|
715
722
|
}
|
|
716
723
|
if (!ed.isDestroyed) ed.commands.clearContent(true)
|
|
@@ -721,7 +728,7 @@ function OpenCommentBox({
|
|
|
721
728
|
})
|
|
722
729
|
return false
|
|
723
730
|
},
|
|
724
|
-
[files, removed, underOf, showsAtOnce, send, draft, onSent, onRefused, layout],
|
|
731
|
+
[files, removed, underOf, showsAtOnce, send, draft, onSent, onRefused, layout, reply],
|
|
725
732
|
)
|
|
726
733
|
|
|
727
734
|
// An edit holding nothing, no words and no file, cannot be saved: Save is off, and nothing is said (Miky, 4 Nov). One
|
package/src/ConversationCard.tsx
CHANGED
|
@@ -95,6 +95,11 @@ export interface ConversationEntryProps {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export interface ConversationCardProps extends ConversationEntryProps {
|
|
98
|
+
/**
|
|
99
|
+
* Where it was said, at the top of the card: a `ConversationHeading`, when one list mixes conversations from several
|
|
100
|
+
* places. Drawn on a deleted one too: its replies still belong there.
|
|
101
|
+
*/
|
|
102
|
+
heading?: ReactNode
|
|
98
103
|
/** Deleted: "This comment was deleted.", and its replies stay. */
|
|
99
104
|
deleted?: boolean
|
|
100
105
|
/**
|
|
@@ -182,7 +187,10 @@ function useClearOfStrip(root: RefObject<HTMLDivElement | null>, strip: RefObjec
|
|
|
182
187
|
return
|
|
183
188
|
}
|
|
184
189
|
const stop = strip.current.getBoundingClientRect().left - 8
|
|
185
|
-
|
|
190
|
+
// A heading above the face is the top row the strip stands over: its name fades at the same point.
|
|
191
|
+
const heading = root.current?.querySelector<HTMLElement>('[data-conversation-heading]')
|
|
192
|
+
const parts = [...Array.from(words.children), ...(heading ? Array.from(heading.children) : [])]
|
|
193
|
+
const reach = Math.max(...parts.map((part) => part.getBoundingClientRect().right))
|
|
186
194
|
setEnd(reach > stop ? stop - words.getBoundingClientRect().left : undefined)
|
|
187
195
|
}, [root, strip, shown])
|
|
188
196
|
return end
|
|
@@ -300,9 +308,11 @@ function Reactions({ reactions, refused, readOnly }: { reactions?: ReactionRowPr
|
|
|
300
308
|
}
|
|
301
309
|
|
|
302
310
|
/** Being edited: the face beside the app's box, which holds the words, the files and the cards. */
|
|
303
|
-
function Editing({ author, children }: { author: ConversationPerson; children: ReactNode }) {
|
|
311
|
+
function Editing({ author, heading, children }: { author: ConversationPerson; heading?: ReactNode; children: ReactNode }) {
|
|
304
312
|
return (
|
|
305
313
|
<div className="p-2">
|
|
314
|
+
{/* Where it was said stays while it is edited: the card keeps its height and its place. */}
|
|
315
|
+
{!!heading && <div className="w-full pb-2">{heading}</div>}
|
|
306
316
|
<div className="flex items-start gap-2">
|
|
307
317
|
<Avatar size={24} src={author.picture} alt={author.name} bot={author.bot} className="mt-1 shrink-0" />
|
|
308
318
|
<div className="min-w-0 flex-1">{children}</div>
|
|
@@ -383,7 +393,7 @@ function useEditing(editing: boolean | undefined, onEditingChange: ((editing: bo
|
|
|
383
393
|
* The same card in every app, each in its own colours (the record that makes one conversation). Peek's, moved.
|
|
384
394
|
*/
|
|
385
395
|
export function ConversationCard(props: ConversationCardProps) {
|
|
386
|
-
const { author, about, files, reactions, isNew = false, urgent = false, own = false, editor, deleted: isDeleted = false, unseen = false, replies, onReply, resolved, noun = 'comment', onResolve, resolveHint, resolveRefused, onReopen, selected, onClick, onDelete, deleteNote, deleteRefused, menu, menuAfter, menuLabel, editLabel, deleteLabel, moreLabel = 'More actions', className, children } = props
|
|
396
|
+
const { author, about, files, reactions, isNew = false, urgent = false, own = false, editor, heading, deleted: isDeleted = false, unseen = false, replies, onReply, resolved, noun = 'comment', onResolve, resolveHint, resolveRefused, onReopen, selected, onClick, onDelete, deleteNote, deleteRefused, menu, menuAfter, menuLabel, editLabel, deleteLabel, moreLabel = 'More actions', className, children } = props
|
|
387
397
|
// Not shown is drawn as deleted, in its own words.
|
|
388
398
|
const deleted = isDeleted || unseen
|
|
389
399
|
const readOnly = (props.readOnly ?? false) || deleted
|
|
@@ -462,9 +472,18 @@ export function ConversationCard(props: ConversationCardProps) {
|
|
|
462
472
|
}}
|
|
463
473
|
>
|
|
464
474
|
{isEditing ? (
|
|
465
|
-
<Editing author={author}
|
|
475
|
+
<Editing author={author} heading={heading}>
|
|
476
|
+
{editor(() => setEditing(false))}
|
|
477
|
+
</Editing>
|
|
466
478
|
) : (
|
|
467
479
|
<div data-comment-body className="flex flex-col items-start px-2 pt-2">
|
|
480
|
+
{/* Where it was said, 8px over the face, inside the card (the Per-app prototype, 29 October). */}
|
|
481
|
+
{!!heading && (
|
|
482
|
+
// Faded clear of the strip, as the head's words are (useClearOfStrip).
|
|
483
|
+
<div className="w-full pb-2" style={wordsEnd === undefined ? undefined : { maskImage: fadeBefore(wordsEnd), WebkitMaskImage: fadeBefore(wordsEnd) }}>
|
|
484
|
+
{heading}
|
|
485
|
+
</div>
|
|
486
|
+
)}
|
|
468
487
|
{deleted ? (
|
|
469
488
|
<>
|
|
470
489
|
{/* What it was on stays, where the words start: its replies still talk about that place (Leaf's; Katerina, 3 November: every app). */}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
|
|
2
|
+
import * as Stories from './ConversationHeading.stories'
|
|
3
|
+
|
|
4
|
+
<Meta of={Stories} />
|
|
5
|
+
|
|
6
|
+
# ConversationHeading
|
|
7
|
+
|
|
8
|
+
Which place a conversation is on, inside its card, when one list mixes conversations from several places.
|
|
9
|
+
|
|
10
|
+
<Canvas of={Stories.OnACard} />
|
|
11
|
+
|
|
12
|
+
## When
|
|
13
|
+
|
|
14
|
+
- One list mixes this place's own conversations with conversations said on other places: each from elsewhere carries its place's icon and name at the top of its card, in the card's `heading`. This place's own carry none.
|
|
15
|
+
|
|
16
|
+
<Canvas of={Stories.WithWhatItIsOn} />
|
|
17
|
+
|
|
18
|
+
- A name longer than the column is cut.
|
|
19
|
+
|
|
20
|
+
<Canvas of={Stories.LongName} />
|
|
21
|
+
|
|
22
|
+
## When not
|
|
23
|
+
|
|
24
|
+
- A conversation shown away from its place, with how it is related ("Mentioned in") above its card → **ConversationPlace**.
|
|
25
|
+
- A comment on a part of the place: what it is on goes in the card's `about` → **QuotedLine**. Both can be on one card: the place, then the author, then the words it is on.
|
|
26
|
+
|
|
27
|
+
## How
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { ConversationCard, ConversationHeading, KindIcon } from '@estiva-app/ui'
|
|
31
|
+
|
|
32
|
+
<ConversationCard
|
|
33
|
+
author={author}
|
|
34
|
+
time={time}
|
|
35
|
+
heading={place ? <ConversationHeading icon={<KindIcon kind={kindOf(place)} />} name={place.title} onOpen={() => openPlace(place)} /> : undefined}
|
|
36
|
+
>
|
|
37
|
+
{words}
|
|
38
|
+
</ConversationCard>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- `icon` is drawn in the face's column, so the name lines up with the author's. Give it 16px; it is hidden from screen readers, the name says it.
|
|
42
|
+
- `onOpen`, or `href`, makes the name a button or a link. A press on it opens the place, never the thread: the card leaves a press on a button or a link alone, and the rest of the card still opens the thread.
|
|
43
|
+
- A deleted comment keeps its heading: its replies still belong to that place.
|
|
44
|
+
- In a `ConversationLayout`, pass it on every card from elsewhere; the layout puts them in your order (time order, mixed with this place's own).
|
|
45
|
+
|
|
46
|
+
## What it owns
|
|
47
|
+
|
|
48
|
+
Nothing. It only draws. Clicks and keys are yours.
|
|
49
|
+
|
|
50
|
+
## Props
|
|
51
|
+
|
|
52
|
+
<Controls />
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { IconSquareRounded } from '@tabler/icons-react'
|
|
3
|
+
import { ConversationCard } from './ConversationCard'
|
|
4
|
+
import { Column, ONE, TWO, WORDS } from './conversation.examples'
|
|
5
|
+
import { ConversationHeading } from './ConversationHeading'
|
|
6
|
+
import { QuotedLine } from './QuotedLine'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Which place a conversation is on, inside its card, when one list mixes several places: the place's icon in the
|
|
10
|
+
* face's column, its name beside it, opening the place.
|
|
11
|
+
*/
|
|
12
|
+
const meta = {
|
|
13
|
+
title: 'Conversation/ConversationHeading',
|
|
14
|
+
component: ConversationHeading,
|
|
15
|
+
parameters: { layout: 'padded' },
|
|
16
|
+
args: { name: 'Item one', icon: <IconSquareRounded size={16} stroke={1.5} />, onOpen: () => {} },
|
|
17
|
+
argTypes: { icon: { control: false } },
|
|
18
|
+
decorators: [(Story) => <Column>{Story()}</Column>],
|
|
19
|
+
render: (args) => (
|
|
20
|
+
<ConversationCard author={ONE} time="11:08 AM" heading={<ConversationHeading {...args} />} onClick={() => {}}>
|
|
21
|
+
{WORDS}
|
|
22
|
+
</ConversationCard>
|
|
23
|
+
),
|
|
24
|
+
} satisfies Meta<typeof ConversationHeading>
|
|
25
|
+
|
|
26
|
+
export default meta
|
|
27
|
+
type Story = StoryObj<typeof meta>
|
|
28
|
+
|
|
29
|
+
/** On a card: the place above the author; its name opens the place, the rest of the card opens the thread. */
|
|
30
|
+
export const OnACard: Story = {}
|
|
31
|
+
|
|
32
|
+
/** On a comment about a part of the place: the place, then the author, then the words it is on. */
|
|
33
|
+
export const WithWhatItIsOn: Story = {
|
|
34
|
+
render: (args) => (
|
|
35
|
+
<ConversationCard author={TWO} time="Yesterday" heading={<ConversationHeading {...args} />} about={<QuotedLine words="the words this comment is on" />} onClick={() => {}}>
|
|
36
|
+
{WORDS}
|
|
37
|
+
</ConversationCard>
|
|
38
|
+
),
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A name longer than the column is cut. */
|
|
42
|
+
export const LongName: Story = {
|
|
43
|
+
args: { name: 'An item whose name runs on well past the width of the column it sits in' },
|
|
44
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* What the ConversationHeading page claims, pinned: in a card's `heading`, the
|
|
4
|
+
* place's name sits above the author's, inside the card; pressing the name opens
|
|
5
|
+
* the place and never the thread; a deleted comment keeps its heading.
|
|
6
|
+
*/
|
|
7
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
8
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
9
|
+
import userEvent from '@testing-library/user-event'
|
|
10
|
+
import { ConversationCard } from './ConversationCard'
|
|
11
|
+
import { ConversationHeading } from './ConversationHeading'
|
|
12
|
+
|
|
13
|
+
afterEach(cleanup)
|
|
14
|
+
|
|
15
|
+
const ICON = <svg data-testid="icon" />
|
|
16
|
+
|
|
17
|
+
describe('ConversationHeading', () => {
|
|
18
|
+
it('draws the place above the author, inside the card', () => {
|
|
19
|
+
render(
|
|
20
|
+
<ConversationCard author={{ name: 'Person one' }} time="11:08 AM" heading={<ConversationHeading icon={ICON} name="Item one" onOpen={() => {}} />}>
|
|
21
|
+
The words
|
|
22
|
+
</ConversationCard>,
|
|
23
|
+
)
|
|
24
|
+
const place = screen.getByRole('button', { name: 'Item one' })
|
|
25
|
+
const author = screen.getByText('Person one')
|
|
26
|
+
expect(place.compareDocumentPosition(author) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
|
27
|
+
expect(place.closest('[data-comment-body]')).toBe(author.closest('[data-comment-body]'))
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('pressing the name opens the place, not the thread', async () => {
|
|
31
|
+
const onOpen = vi.fn()
|
|
32
|
+
const onClick = vi.fn()
|
|
33
|
+
render(
|
|
34
|
+
<ConversationCard author={{ name: 'Person one' }} time="11:08 AM" onClick={onClick} heading={<ConversationHeading icon={ICON} name="Item one" onOpen={onOpen} />}>
|
|
35
|
+
The words
|
|
36
|
+
</ConversationCard>,
|
|
37
|
+
)
|
|
38
|
+
await userEvent.click(screen.getByRole('button', { name: 'Item one' }))
|
|
39
|
+
expect(onOpen).toHaveBeenCalledTimes(1)
|
|
40
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
41
|
+
await userEvent.click(screen.getByText('The words'))
|
|
42
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('a link: a plain click goes to the app to route, never to the thread; a modified click goes to the browser', () => {
|
|
46
|
+
const onOpen = vi.fn()
|
|
47
|
+
const onClick = vi.fn()
|
|
48
|
+
render(
|
|
49
|
+
<ConversationCard author={{ name: 'Person one' }} time="11:08 AM" onClick={onClick} heading={<ConversationHeading icon={ICON} name="Item one" href="/item/one" onOpen={onOpen} />}>
|
|
50
|
+
The words
|
|
51
|
+
</ConversationCard>,
|
|
52
|
+
)
|
|
53
|
+
const link = screen.getByRole('link', { name: 'Item one' })
|
|
54
|
+
const plain = new MouseEvent('click', { bubbles: true, cancelable: true, button: 0 })
|
|
55
|
+
link.dispatchEvent(plain)
|
|
56
|
+
expect(plain.defaultPrevented).toBe(true)
|
|
57
|
+
expect(onOpen).toHaveBeenCalledTimes(1)
|
|
58
|
+
const newTab = new MouseEvent('click', { bubbles: true, cancelable: true, button: 0, metaKey: true })
|
|
59
|
+
link.dispatchEvent(newTab)
|
|
60
|
+
expect(newTab.defaultPrevented).toBe(false)
|
|
61
|
+
expect(onOpen).toHaveBeenCalledTimes(1)
|
|
62
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('with nothing to open, the name is plain text', () => {
|
|
66
|
+
render(<ConversationHeading icon={ICON} name="Item one" />)
|
|
67
|
+
expect(screen.getByText('Item one')).toBeTruthy()
|
|
68
|
+
expect(screen.queryByRole('button')).toBeNull()
|
|
69
|
+
expect(screen.queryByRole('link')).toBeNull()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('a deleted comment keeps where it was said', () => {
|
|
73
|
+
render(
|
|
74
|
+
<ConversationCard author={{ name: 'Person one' }} time="11:08 AM" deleted heading={<ConversationHeading icon={ICON} name="Item one" />}>
|
|
75
|
+
The words
|
|
76
|
+
</ConversationCard>,
|
|
77
|
+
)
|
|
78
|
+
expect(screen.getByText('Item one')).toBeTruthy()
|
|
79
|
+
expect(screen.queryByText('The words')).toBeNull()
|
|
80
|
+
})
|
|
81
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { isPlainClick } from './AppProvider'
|
|
3
|
+
import { cn } from './cn'
|
|
4
|
+
|
|
5
|
+
export interface ConversationHeadingProps {
|
|
6
|
+
/** What kind of place it is: a `KindIcon`, 16px. Drawn in the face's column, so the name lines up with the author's. */
|
|
7
|
+
icon: ReactNode
|
|
8
|
+
/** The place's name, cut to the column. */
|
|
9
|
+
name: string
|
|
10
|
+
/** Pressing the name opens the place. Without it (and without `href`) the name is plain text. */
|
|
11
|
+
onOpen?: () => void
|
|
12
|
+
/** Or a link to the place. With `onOpen` too, a plain click calls `onOpen` and the link only serves a new tab. */
|
|
13
|
+
href?: string
|
|
14
|
+
/** Placement only. */
|
|
15
|
+
className?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const NAME = '-mx-1 min-w-0 truncate rounded px-1 text-left text-h4 text-text-primary'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Where a conversation was said, above its first message, when one list mixes conversations from several places: the
|
|
22
|
+
* place's icon in the face's column and its name beside it, which opens the place. Goes in a `ConversationCard`'s
|
|
23
|
+
* `heading`, so it sits inside the card, as the Per-app prototype draws it (29 October). A press on the name opens the
|
|
24
|
+
* place, never the thread: the card leaves a press on a button or a link alone.
|
|
25
|
+
*/
|
|
26
|
+
export function ConversationHeading({ icon, name, onOpen, href, className }: ConversationHeadingProps) {
|
|
27
|
+
const label = href ? (
|
|
28
|
+
<a
|
|
29
|
+
href={href}
|
|
30
|
+
// A plain click is the app's to route (onOpen); a new tab or window is the browser's.
|
|
31
|
+
onClick={(event) => {
|
|
32
|
+
if (!onOpen || !isPlainClick(event)) return
|
|
33
|
+
event.preventDefault()
|
|
34
|
+
onOpen()
|
|
35
|
+
}}
|
|
36
|
+
className={cn(NAME, 'hover:bg-bg-hover')}
|
|
37
|
+
>
|
|
38
|
+
{name}
|
|
39
|
+
</a>
|
|
40
|
+
) : onOpen ? (
|
|
41
|
+
<button type="button" onClick={onOpen} className={cn(NAME, 'hover:bg-bg-hover')}>
|
|
42
|
+
{name}
|
|
43
|
+
</button>
|
|
44
|
+
) : (
|
|
45
|
+
<span className={NAME}>{name}</span>
|
|
46
|
+
)
|
|
47
|
+
return (
|
|
48
|
+
<div data-conversation-heading className={cn('flex w-full items-center gap-2', className)}>
|
|
49
|
+
<span aria-hidden className="flex size-6 shrink-0 items-center justify-center text-text-secondary">
|
|
50
|
+
{icon}
|
|
51
|
+
</span>
|
|
52
|
+
{label}
|
|
53
|
+
</div>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
2
|
import { useState, type ReactNode } from 'react'
|
|
3
3
|
import { ConversationCard, ReplyCard } from './ConversationCard'
|
|
4
|
+
import { ConversationHeading } from './ConversationHeading'
|
|
5
|
+
import { KindIcon } from './KindIcon'
|
|
4
6
|
import { ConversationLayout, type ConversationItem } from './ConversationLayout'
|
|
5
7
|
import { ONE, SHORT, SOME, THREE, TWO, WORDS, WriteBox, YOU, useReactions } from './conversation.examples'
|
|
6
8
|
import { ArchivedNotice } from './ArchivedNotice'
|
|
@@ -294,6 +296,64 @@ export const OneColumnBelow: Story = {
|
|
|
294
296
|
},
|
|
295
297
|
}
|
|
296
298
|
|
|
299
|
+
/** One list, three places: this place's own comments, and two other places' each under its name. */
|
|
300
|
+
const MIXED = [
|
|
301
|
+
{ id: 'm1', author: ONE, time: '9:02 AM', words: 'A comment on this place itself: no name above it.', replies: 1 },
|
|
302
|
+
{ id: 'm2', author: TWO, time: '9:40 AM', words: WORDS, replies: 2, place: 'Item one', quoted: 'the words this comment is on' },
|
|
303
|
+
{ id: 'm3', author: THREE, time: '10:15 AM', words: 'Resolved on its own place, so it is resolved here too.', replies: 1, place: 'Item two', resolved: { by: 'You', note: 'Done.' } },
|
|
304
|
+
{ id: 'm4', author: YOU, time: '11:30 AM', words: 'Another on this place, in time order with the rest.', replies: 0 },
|
|
305
|
+
{ id: 'm5', author: ONE, time: '12:05 PM', words: 'A second comment on the first other place.', replies: 0, place: 'Item one' },
|
|
306
|
+
]
|
|
307
|
+
|
|
308
|
+
function MixedItems({ open, setOpen }: { open: string | undefined; setOpen: (id: string | undefined) => void }) {
|
|
309
|
+
const [resolved, setResolved] = useState<Record<string, { by: string; note?: string } | undefined>>(() => Object.fromEntries(MIXED.map((c) => [c.id, c.resolved])))
|
|
310
|
+
const items: ConversationItem[] = MIXED.map((c) => ({
|
|
311
|
+
id: c.id,
|
|
312
|
+
card: (
|
|
313
|
+
<ConversationCard
|
|
314
|
+
author={c.author}
|
|
315
|
+
time={c.time}
|
|
316
|
+
heading={c.place ? <ConversationHeading icon={<KindIcon kind={c.place === 'Item one' ? 'file' : 'issue'} />} name={c.place} onOpen={() => {}} /> : undefined}
|
|
317
|
+
about={c.quoted ? <QuotedLine words={c.quoted} /> : undefined}
|
|
318
|
+
resolved={resolved[c.id]}
|
|
319
|
+
onResolve={(note) => setResolved((r) => ({ ...r, [c.id]: { by: 'You', note: note || undefined } }))}
|
|
320
|
+
onReopen={() => setResolved((r) => ({ ...r, [c.id]: undefined }))}
|
|
321
|
+
replies={c.replies ? { count: c.replies, faces: [TWO, YOU], last: '11:52 AM' } : undefined}
|
|
322
|
+
>
|
|
323
|
+
{c.words}
|
|
324
|
+
</ConversationCard>
|
|
325
|
+
),
|
|
326
|
+
thread: (
|
|
327
|
+
<Thread start={{ author: c.author, time: c.time, words: c.words }} onClose={() => setOpen(undefined)} box={<WriteBox />}>
|
|
328
|
+
{c.replies ? <Replies /> : undefined}
|
|
329
|
+
</Thread>
|
|
330
|
+
),
|
|
331
|
+
}))
|
|
332
|
+
return <ConversationLayout threads="beside" items={items} open={open} onOpenChange={setOpen} box={<WriteBox label="Message" />} />
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Two columns mixing several places: comments said elsewhere sit in time order with this place's own, each under its
|
|
337
|
+
* place's name (`ConversationHeading` in the card's `heading`). A reply opened from one is that place's thread.
|
|
338
|
+
*/
|
|
339
|
+
export const SeveralPlaces: Story = {
|
|
340
|
+
name: 'Several places',
|
|
341
|
+
render: function Render() {
|
|
342
|
+
const [open, setOpen] = useState<string | undefined>()
|
|
343
|
+
return <MixedItems open={open} setOpen={setOpen} />
|
|
344
|
+
},
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** The same at phone width: the place's name is cut to the column. */
|
|
348
|
+
export const SeveralPlacesNarrow: Story = {
|
|
349
|
+
name: 'Several places, narrow',
|
|
350
|
+
globals: { viewport: { value: 'mobile1', isRotated: false } },
|
|
351
|
+
render: function Render() {
|
|
352
|
+
const [open, setOpen] = useState<string | undefined>()
|
|
353
|
+
return <MixedItems open={open} setOpen={setOpen} />
|
|
354
|
+
},
|
|
355
|
+
}
|
|
356
|
+
|
|
297
357
|
/** Nobody has commented yet. */
|
|
298
358
|
export const Empty: Story = {
|
|
299
359
|
render: () => (
|
package/src/index.ts
CHANGED
|
@@ -145,6 +145,7 @@ export { ConversationLayout, type ConversationItem, type ConversationLayoutProps
|
|
|
145
145
|
export { caretOnOpen } from './threadCard'
|
|
146
146
|
// Where a two-column conversation was left, for the app's "New" line; and the layout's word to its box that the reader's own comment is on its way (CommentBox reads it, from the editor's bundle).
|
|
147
147
|
export { useLeftAt, sendsInLayout } from './conversationScroll'
|
|
148
|
+
export { ConversationHeading, type ConversationHeadingProps } from './ConversationHeading'
|
|
148
149
|
export { ConversationMenu, type ConversationMenuProps } from './ConversationMenu'
|
|
149
150
|
export { ConversationPlace, type ConversationPlaceProps } from './ConversationPlace'
|
|
150
151
|
export { EditedMarker, type EditedMarkerProps } from './EditedMarker'
|
|
@@ -48,19 +48,19 @@ 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
|
|
51
|
+
it('counts 251 names over 128 files: 166 components, 78 helpers and 7 hooks (ConversationHeading, which place a comment is on in a list mixing several places (TOPI-2), on 9 November; FollowSwitch, LevelIcon and WhoFollowsDialog, how you follow a place and who follows it (TEA-6), on 6 November; goneWords and GONE_CLOSED, what stands in a gone comment’s place and under its thread in every app (ONE-9), on 6 November; DeletedNotice and NoAccessNotice, the cards on a deleted file and on one you cannot open (ALO-4), on 3 November; useFormBusy, whether a Form around it is sending, read by the editor’s DocumentField from the main entry, in the review of 2 November; useLeftAt, sendsInLayout, useSeenOnScreen, showInConversation and showInConversationWhenDrawn, where a conversation scrolls, what was seen and a link landing on a comment, moved from Peek for every app, on 2 November; useRememberedOpen, the fold a section remembers, read by the app, and NAV_TREE_PENDING_MS and isPlainClick, Peek’s Folder timer and plain-click check, moved in, on 2 November; FormDialog, MoveDialog and ArchiveDialog, the dialogs Peek wired by hand, on 2 November; ConversationPlace, the line saying where a comment was said, and DocumentField, a rich-text field of a form, moved from Peek, on 2 November; ArchivedNotice, the card on an archived file, from Peek, Ship and Leaf, on 31 October; caretOnOpen, the box at a thread’s foot taking the caret when a ConversationLayout opens it, without scrolling, on 31 October; the conversation from Peek for every app, with PageHeader and PinnedComment, on 31 October, and ResolutionNote and ResolutionHistory gone with the resolved looks not picked, on 1 November; useSidebarFold, a folded sidebar kept folded in every app, on 31 October; cardShapeMemory, a card’s last shape on this device, lifted from Peek and Ship for Leaf, and ReferenceCards and useReferenceCards gone with their deprecated page, in the widget review, on 30 October; inTheBox, a card or part in a box being written in, on the files’ fill and in words, on 29 October; archivedLine, the line on an archived file in every app (PEEKM-2), on 23 October; keepCommentBoxWarm, a box built ahead, exported as 0.84.0 promised (PEEKM-1), on 21 October;linkedFrom and linkStateFrom, one card for a file in every app (5ebf2756), on 21 October; 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:
|
|
58
|
-
expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(
|
|
57
|
+
expect(kinds).toEqual({ component: 166, helper: 78, hook: 7 })
|
|
58
|
+
expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(128)
|
|
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(
|
|
63
|
+
expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(115)
|
|
64
64
|
expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(136)
|
|
65
65
|
})
|
|
66
66
|
|
package/stories/Choosing.mdx
CHANGED
|
@@ -99,6 +99,7 @@ The same conversation in every app; only its colours are each app's.
|
|
|
99
99
|
| Where the comments sit, and where a thread opens | **ConversationLayout** — two columns, the thread beside them; or one 384px column, the thread under its comment |
|
|
100
100
|
| One comment | **ConversationCard** — the words, files, cards, reactions, replies row, the actions on hover and the ⋯ menu |
|
|
101
101
|
| Where a conversation shown away from its place was said, above its card | **ConversationPlace** — how it is related and the place, in your words |
|
|
102
|
+
| Which place each conversation is on, in one list that mixes several places | **ConversationHeading** — the place's icon and name inside the card, in its `heading`, opening the place |
|
|
102
103
|
| One reply in a thread | **ReplyCard** — a comment's pieces, without replies of its own or Resolve |
|
|
103
104
|
| A comment's replies and the box to write one | **Thread** — in the right column under its header, or under its comment |
|
|
104
105
|
| The way into a thread | **RepliesRow** — faces, "2 replies", the last time and how many are new ("2 new") |
|