@estiva-app/ui 0.91.0 → 0.91.2
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/AttachedCard.d.ts +2 -2
- package/dist/AttachedCard.d.ts.map +1 -1
- package/dist/Card.d.ts +4 -1
- package/dist/Card.d.ts.map +1 -1
- package/dist/LinkCard.d.ts.map +1 -1
- package/dist/LinkParts.d.ts.map +1 -1
- package/dist/LinkRow.d.ts +1 -1
- package/dist/LinkRow.d.ts.map +1 -1
- package/dist/PartCard.d.ts +10 -2
- package/dist/PartCard.d.ts.map +1 -1
- package/dist/Select.d.ts +7 -1
- package/dist/Select.d.ts.map +1 -1
- package/dist/ShowMore.d.ts +8 -3
- package/dist/ShowMore.d.ts.map +1 -1
- package/dist/eslint/index.js +1 -1
- package/dist/eslint/index.js.map +2 -2
- package/dist/index.js +71 -38
- package/dist/index.js.map +3 -3
- package/dist/linkedFrom.d.ts +5 -0
- package/dist/linkedFrom.d.ts.map +1 -1
- package/package.json +1 -1
- package/registry.json +51 -19
- package/src/AttachedCard.test.tsx +3 -3
- package/src/AttachedCard.tsx +5 -7
- package/src/Card.test.tsx +1 -1
- package/src/Card.tsx +5 -2
- package/src/CommentBox.test.tsx +1 -1
- package/src/LinkCard.mdx +5 -4
- package/src/LinkCard.stories.tsx +3 -0
- package/src/LinkCard.test.tsx +8 -2
- package/src/LinkCard.tsx +28 -21
- package/src/LinkChip.mdx +1 -1
- package/src/LinkChip.test.tsx +1 -1
- package/src/LinkChip.tsx +1 -1
- package/src/LinkParts.tsx +3 -0
- package/src/LinkRow.mdx +2 -2
- package/src/LinkRow.test.tsx +1 -1
- package/src/LinkRow.tsx +6 -7
- package/src/PartCard.mdx +2 -1
- package/src/PartCard.stories.tsx +24 -0
- package/src/PartCard.test.tsx +1 -1
- package/src/PartCard.tsx +21 -6
- package/src/Select.mdx +4 -0
- package/src/Select.stories.tsx +11 -1
- package/src/Select.tsx +10 -2
- package/src/ShowMore.mdx +4 -4
- package/src/ShowMore.tsx +11 -6
- package/src/eslint/no-restyled-part.ts +1 -1
- package/src/linked.examples.ts +1 -1
- package/src/linkedFrom.test.tsx +55 -3
- package/src/linkedFrom.ts +46 -2
package/src/PartCard.stories.tsx
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { IconExternalLink } from '@tabler/icons-react'
|
|
3
|
+
import { Button } from './Button'
|
|
2
4
|
import { PartCard } from './PartCard'
|
|
3
5
|
import { RichText, type RichTextBlock } from './RichText'
|
|
4
6
|
|
|
@@ -31,6 +33,28 @@ export const Default: Story = {
|
|
|
31
33
|
},
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
const LONG_BLOCKS: RichTextBlock[] = [
|
|
37
|
+
{ type: 'heading', level: 2, inline: [{ text: 'A heading in the part', marks: [] }] },
|
|
38
|
+
...Array.from({ length: 6 }, (_, i): RichTextBlock => ({ type: 'paragraph', inline: [{ text: `Paragraph ${i + 1} of the part, long enough to fill a line of the card and go on to a second one.`, marks: [] }] })),
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
/** As an app quotes a long part: cut behind Show more, and its way out ("Open in App one") level with it, under the quote bar, not beside it. */
|
|
42
|
+
export const WithItsWayOut: Story = {
|
|
43
|
+
args: {
|
|
44
|
+
state: 'ready',
|
|
45
|
+
kind: 'page',
|
|
46
|
+
heading: 'Document one',
|
|
47
|
+
href: '#part',
|
|
48
|
+
maxHeight: 160,
|
|
49
|
+
action: (
|
|
50
|
+
<Button size="small" leadingIcon={<IconExternalLink stroke={1.5} className="size-3.5" />} onClick={() => {}}>
|
|
51
|
+
Open in App one
|
|
52
|
+
</Button>
|
|
53
|
+
),
|
|
54
|
+
children: <RichText blocks={LONG_BLOCKS} size="small" />,
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
|
|
34
58
|
/** Still being looked up. */
|
|
35
59
|
export const Loading: Story = { args: { state: 'loading', kind: 'issue' } }
|
|
36
60
|
|
package/src/PartCard.test.tsx
CHANGED
|
@@ -21,7 +21,7 @@ describe('PartCard', () => {
|
|
|
21
21
|
|
|
22
22
|
it('says a part is not available in words', () => {
|
|
23
23
|
render(<PartCard state="unavailable" kind="issue" noun="Issue" />)
|
|
24
|
-
expect(screen.getByText('A part of this issue
|
|
24
|
+
expect(screen.getByText('A part of this issue not available')).toBeTruthy()
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
it('while it loads, is busy and shows nothing of it', () => {
|
package/src/PartCard.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import { inTheBox, type LinkedKind } from './linked'
|
|
|
18
18
|
import { kindNounOf, LinkTile } from './LinkParts'
|
|
19
19
|
import { LinkUnavailable } from './LinkRow'
|
|
20
20
|
import { QUOTE_BAR_CLASSES } from './looks'
|
|
21
|
+
import { ShowMore } from './ShowMore'
|
|
21
22
|
|
|
22
23
|
export interface PartCardProps {
|
|
23
24
|
/** Where its lookup stands. Default `ready`. */
|
|
@@ -30,22 +31,30 @@ export interface PartCardProps {
|
|
|
30
31
|
href?: string
|
|
31
32
|
/** The key of what it is part of: "ABC-2". */
|
|
32
33
|
partKey?: string
|
|
33
|
-
/** What it is part of, in a word, for "A part of this issue
|
|
34
|
+
/** What it is part of, in a word, for "A part of this issue not available". Absent, its kind's word. */
|
|
34
35
|
noun?: string
|
|
35
36
|
/** Where it may still open, for someone who can, when it is not available. */
|
|
36
37
|
openIn?: { app: string; href: string }
|
|
37
38
|
/** The part's blocks, drawn by the app. */
|
|
38
39
|
children?: ReactNode
|
|
40
|
+
/**
|
|
41
|
+
* The way out to where the part lives: a small `Button` with a leading icon ("Open in Leaf"). Drawn under the
|
|
42
|
+
* blocks at the right, level with Show more, outside the quote bar (Katerina, 30 Oct: "the vertical line should not
|
|
43
|
+
* be covering the button"). Peek and Ship put it in ShowMore's row inside the blocks before.
|
|
44
|
+
*/
|
|
45
|
+
action?: ReactNode
|
|
46
|
+
/** Cut the blocks at this height, in px, behind ShowMore's fade and its Show more. Absent, they are drawn whole. */
|
|
47
|
+
maxHeight?: number
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
export function PartCard({ state = 'ready', kind, heading, href, partKey, noun, openIn, children }: PartCardProps) {
|
|
50
|
+
export function PartCard({ state = 'ready', kind, heading, href, partKey, noun, openIn, children, action, maxHeight }: PartCardProps) {
|
|
42
51
|
const word = noun ?? kindNounOf({ kind }) ?? 'File'
|
|
43
52
|
const boxed = useContext(inTheBox)
|
|
44
53
|
if (state === 'loading') return <LinkCardLoading kind={kind} shape={{ summary: true, rows: 0, footer: 'none' }} />
|
|
45
54
|
if (state === 'unavailable') return <LinkUnavailable kind={kind} noun={`A part of this ${word.toLowerCase()}`} openIn={openIn} card />
|
|
46
55
|
return (
|
|
47
|
-
//
|
|
48
|
-
<Card fill={boxed ? 'elevated' : 'inset'} className=
|
|
56
|
+
// At most 480px wide, in a box too; in a box being written in, on the files' fill as the card beside it is.
|
|
57
|
+
<Card fill={boxed ? 'elevated' : 'inset'} className="flex max-w-[480px] flex-col gap-3 p-3">
|
|
49
58
|
<div className="flex items-center gap-3">
|
|
50
59
|
<LinkTile kind={kind} />
|
|
51
60
|
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
@@ -61,8 +70,14 @@ export function PartCard({ state = 'ready', kind, heading, href, partKey, noun,
|
|
|
61
70
|
<span className="truncate text-caption text-text-secondary">{partKey ? `A part of ${partKey}` : `A part of this ${word.toLowerCase()}`}</span>
|
|
62
71
|
</span>
|
|
63
72
|
</div>
|
|
64
|
-
{/* The quote bar starts where the tile above it starts (Katerina, 29 Oct). */}
|
|
65
|
-
|
|
73
|
+
{/* The quote bar starts where the tile above it starts (Katerina, 29 Oct), and runs beside the blocks only. */}
|
|
74
|
+
{action || maxHeight !== undefined ? (
|
|
75
|
+
<ShowMore maxHeight={maxHeight ?? Infinity} surface={boxed ? 'elevated' : 'inset'} action={action} contentClassName={QUOTE_BAR_CLASSES}>
|
|
76
|
+
{children}
|
|
77
|
+
</ShowMore>
|
|
78
|
+
) : (
|
|
79
|
+
<div className={QUOTE_BAR_CLASSES}>{children}</div>
|
|
80
|
+
)}
|
|
66
81
|
</Card>
|
|
67
82
|
)
|
|
68
83
|
}
|
package/src/Select.mdx
CHANGED
|
@@ -20,6 +20,10 @@ corners and scrolling panels.
|
|
|
20
20
|
trigger and the list alike.
|
|
21
21
|
- Two sizes; `small` for dense rows and rails (it sits well inside
|
|
22
22
|
**Property**).
|
|
23
|
+
- Two fills: a form's `field` (default), and `wash` on a see-through card
|
|
24
|
+
(`Card fill="inset"`), one step over it, as a link card's pickers are. A
|
|
25
|
+
field's own fill there reads as a hole when the message behind is selected.
|
|
26
|
+
Leaf's fields are white and stay white.
|
|
23
27
|
|
|
24
28
|
<Canvas of={SelectStories.WithLeading} />
|
|
25
29
|
|
package/src/Select.stories.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
2
|
import { useState, type ComponentProps } from 'react'
|
|
3
3
|
import { Avatar } from './Avatar'
|
|
4
|
+
import { Card } from './Card'
|
|
4
5
|
import { Field } from './Field'
|
|
5
6
|
import { Select } from './Select'
|
|
6
7
|
import { TextInput } from './TextInput'
|
|
@@ -32,7 +33,7 @@ const meta = {
|
|
|
32
33
|
],
|
|
33
34
|
ariaLabel: 'Status',
|
|
34
35
|
},
|
|
35
|
-
argTypes: { size: { control: 'inline-radio', options: ['default', 'small'] } },
|
|
36
|
+
argTypes: { size: { control: 'inline-radio', options: ['default', 'small'] }, fill: { control: 'inline-radio', options: ['field', 'wash'] } },
|
|
36
37
|
} satisfies Meta<typeof Select>
|
|
37
38
|
|
|
38
39
|
export default meta
|
|
@@ -59,6 +60,15 @@ export const Empty: Story = {
|
|
|
59
60
|
/** The dense size, matching `Button`'s small — for property rows, where a full-height field would dominate the label beside it. */
|
|
60
61
|
export const Small: Story = { render: (args) => <Demo {...args} size="small" initial="todo" /> }
|
|
61
62
|
|
|
63
|
+
/** `fill="wash"` on a see-through card, as a link card's pickers: one step over the card, so a selected message's tint shows through both. */
|
|
64
|
+
export const OnASeeThroughCard: Story = {
|
|
65
|
+
render: (args) => (
|
|
66
|
+
<Card fill="inset" className="flex gap-2 p-3">
|
|
67
|
+
<Demo {...args} size="small" fill="wash" className="w-auto" initial="in_progress" />
|
|
68
|
+
</Card>
|
|
69
|
+
),
|
|
70
|
+
}
|
|
71
|
+
|
|
62
72
|
/** An option may carry a `leading` node — a face beside a person's name — shown in the trigger and in the list. Ship's addition. */
|
|
63
73
|
export const WithLeading: Story = {
|
|
64
74
|
render: (args) => (
|
package/src/Select.tsx
CHANGED
|
@@ -47,6 +47,12 @@ export interface SelectProps {
|
|
|
47
47
|
onChange: (value: string) => void
|
|
48
48
|
options: SelectOption[]
|
|
49
49
|
size?: 'default' | 'small'
|
|
50
|
+
/**
|
|
51
|
+
* What the trigger is filled with: a form's `field` (default), or the see-through `wash` on a see-through card,
|
|
52
|
+
* one step over it, as the card is over the message (a link card's pickers; Katerina, 30 Oct: the field's fill
|
|
53
|
+
* read as a dark hole in a card on a selected message). Leaf's white fields stay white.
|
|
54
|
+
*/
|
|
55
|
+
fill?: 'field' | 'wash'
|
|
50
56
|
ariaLabel?: string
|
|
51
57
|
/** Set by a `Field` with `required`; a caller inside one owes nothing. */
|
|
52
58
|
'aria-required'?: boolean | 'true' | 'false'
|
|
@@ -68,7 +74,7 @@ export interface SelectProps {
|
|
|
68
74
|
const GAP = 4
|
|
69
75
|
const VIEWPORT_PAD = 8
|
|
70
76
|
|
|
71
|
-
export function Select({ value, onChange, options, size = 'default', ariaLabel, placeholder = 'Select…', disabled, disabledReason, className, ...aria }: SelectProps) {
|
|
77
|
+
export function Select({ value, onChange, options, size = 'default', fill = 'field', ariaLabel, placeholder = 'Select…', disabled, disabledReason, className, ...aria }: SelectProps) {
|
|
72
78
|
const selected = options.find((o) => o.value === value)
|
|
73
79
|
// With a reason it is held shut rather than disabled: a disabled trigger is
|
|
74
80
|
// a native `disabled` button, which Tab skips and a tooltip cannot open on.
|
|
@@ -88,7 +94,9 @@ export function Select({ value, onChange, options, size = 'default', ariaLabel,
|
|
|
88
94
|
* `truncate` from ever engaging; in a block container max-w-full is
|
|
89
95
|
* the cap. Full-width callers are unaffected.
|
|
90
96
|
*/
|
|
91
|
-
'flex w-full min-w-0 max-w-full items-center justify-between gap-2 rounded-lg border
|
|
97
|
+
'flex w-full min-w-0 max-w-full items-center justify-between gap-2 rounded-lg border text-left',
|
|
98
|
+
// Leaf's fields are white, raised on their shadow, and stay so on a card: they never read as a hole (Katerina, 30 Oct).
|
|
99
|
+
fill === 'wash' ? 'bg-bg-wash leaf:bg-bg-field leaf:shadow-field' : 'bg-bg-field shadow-field',
|
|
92
100
|
'border-border-field outline-none transition-colors',
|
|
93
101
|
FIELD_TEXT_CLASSES,
|
|
94
102
|
// The focused border survives a hover: hover alone strengthens the
|
package/src/ShowMore.mdx
CHANGED
|
@@ -31,16 +31,16 @@ Long content cut at a height behind a fade, with "Show more" under it.
|
|
|
31
31
|
```tsx
|
|
32
32
|
import { ShowMore } from '@estiva-app/ui'
|
|
33
33
|
|
|
34
|
-
<ShowMore
|
|
34
|
+
<ShowMore>
|
|
35
35
|
<p className="text-caption text-text-secondary">{description}</p>
|
|
36
36
|
</ShowMore>
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
- Wrap only the part that runs long. Keep titles and controls outside it, so
|
|
40
40
|
they are never the part that is cut.
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
- The fade is the content's own: its last 40px fade out over whatever it sits
|
|
42
|
+
on, a panel, an inset card or a selected message alike. `surface` is no
|
|
43
|
+
longer needed, and ignored.
|
|
44
44
|
- `maxHeight` is in px, 96 by default.
|
|
45
45
|
- The toggle is a small outlined `Button` with a chevron: down on "Show more",
|
|
46
46
|
up on "Show less". Its edge starts where the content does.
|
package/src/ShowMore.tsx
CHANGED
|
@@ -27,16 +27,22 @@ export interface ShowMoreProps {
|
|
|
27
27
|
children: ReactNode
|
|
28
28
|
/** The height to cut at, in px. Default 96: about seven lines of caption text. */
|
|
29
29
|
maxHeight?: number
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Nothing to choose: the fade is the content's own, fading out over whatever it sits on, a see-through
|
|
32
|
+
* inset card and a selected message included. Accepted, and ignored.
|
|
33
|
+
*/
|
|
34
|
+
surface?: 'surface' | 'inset' | 'elevated'
|
|
32
35
|
/** A small muted `Button` with a leading icon, at the right of the toggle's row: the way out to where the content lives. Its words end where the content does. */
|
|
33
36
|
action?: ReactNode
|
|
37
|
+
/** On the content alone, not the toggle's row under it: PartCard's quote bar runs beside the blocks only. */
|
|
38
|
+
contentClassName?: string
|
|
34
39
|
className?: string
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
/** The last 40px of cut content fade out: a mask on the content, not a fill over it, so it ends in whatever is behind. */
|
|
43
|
+
const FADE = 'linear-gradient(to top, transparent, black 40px)'
|
|
38
44
|
|
|
39
|
-
export function ShowMore({ children, maxHeight = 96,
|
|
45
|
+
export function ShowMore({ children, maxHeight = 96, action, contentClassName, className }: ShowMoreProps) {
|
|
40
46
|
const box = useRef<HTMLDivElement>(null)
|
|
41
47
|
const [open, setOpen] = useState(false)
|
|
42
48
|
const [overflows, setOverflows] = useState(false)
|
|
@@ -55,9 +61,8 @@ export function ShowMore({ children, maxHeight = 96, surface = 'surface', action
|
|
|
55
61
|
const cut = overflows && !open
|
|
56
62
|
return (
|
|
57
63
|
<div className={cn('flex flex-col items-start', className)}>
|
|
58
|
-
<div ref={box} className={cn('relative w-full', cut && 'overflow-hidden')} style={cut ? { maxHeight } : undefined} onFocus={cut ? () => setOpen(true) : undefined}>
|
|
64
|
+
<div ref={box} className={cn('relative w-full', cut && 'overflow-hidden', contentClassName)} style={cut ? { maxHeight, maskImage: FADE, WebkitMaskImage: FADE } : undefined} onFocus={cut ? () => setOpen(true) : undefined}>
|
|
59
65
|
{children}
|
|
60
|
-
{cut && <div aria-hidden className={cn('pointer-events-none absolute inset-x-0 bottom-0 h-10 bg-gradient-to-t to-transparent', FADE_CLASSES[surface])} />}
|
|
61
66
|
</div>
|
|
62
67
|
{action ? (
|
|
63
68
|
<div className={cn('mt-1 flex w-full items-center gap-2', overflows ? 'justify-between' : 'justify-end')}>
|
|
@@ -159,7 +159,7 @@ export const PART_LOOK_PROPS: Record<string, string[]> = {
|
|
|
159
159
|
SectionHeader: ['hover', 'look'],
|
|
160
160
|
SectionLabel: ['tone', 'truncate'],
|
|
161
161
|
ShowMore: ['surface'],
|
|
162
|
-
Select: ['size'],
|
|
162
|
+
Select: ['size', 'fill'],
|
|
163
163
|
Tabs: ['size'],
|
|
164
164
|
TextInput: ['size'],
|
|
165
165
|
Toast: ['type'],
|
package/src/linked.examples.ts
CHANGED
package/src/linkedFrom.test.tsx
CHANGED
|
@@ -152,11 +152,63 @@ describe('a card built from interop’s projection', () => {
|
|
|
152
152
|
})
|
|
153
153
|
})
|
|
154
154
|
|
|
155
|
+
// Katerina, 30 Oct: "there are no metadata in the card, no date no person".
|
|
156
|
+
describe('when it changed, and who made it', () => {
|
|
157
|
+
const now = Math.floor(Date.now() / 1000)
|
|
158
|
+
const PAGE: LinkedSource = {
|
|
159
|
+
ref: `30842:${OTHER}:page`,
|
|
160
|
+
address: `30842:${OTHER}:page`,
|
|
161
|
+
kind: 30842,
|
|
162
|
+
widget: 'card',
|
|
163
|
+
slots: { title: { value: 'Page one', field: 'title' }, subtitle: { value: 'What the page is for.' } },
|
|
164
|
+
meta: [],
|
|
165
|
+
actions: [],
|
|
166
|
+
changedAt: now - 2 * 3600,
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
it('says when it last changed, and who made it, by the key its address is signed by', () => {
|
|
170
|
+
const card = render(<LinkCard link={linkStateFrom(PAGE, UNREAD, options())} />)
|
|
171
|
+
expect(within(card.container).getByText('Updated 2h ago')).toBeTruthy()
|
|
172
|
+
expect(within(card.container).getByText('PT')).toBeTruthy()
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('says it in the app’s words when the app gives them', () => {
|
|
176
|
+
render(<LinkCard link={linkStateFrom(PAGE, UNREAD, options({ whenOf: () => 'Tuesday' }))} />)
|
|
177
|
+
expect(screen.getByText('Updated Tuesday')).toBeTruthy()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('names nobody it cannot name, and a topic, whose key is its relay’s', () => {
|
|
181
|
+
const stranger = { ...PAGE, address: `30842:${'c'.repeat(64)}:page` }
|
|
182
|
+
render(<LinkCard link={linkStateFrom(stranger, UNREAD, options())} />)
|
|
183
|
+
expect(screen.getByText('Updated 2h ago')).toBeTruthy()
|
|
184
|
+
cleanup()
|
|
185
|
+
render(<LinkCard link={linkStateFrom({ ...PAGE, kind: 39000, address: `39000:${OTHER}:topic` }, UNREAD, options())} />)
|
|
186
|
+
expect(screen.getByText('Updated 2h ago')).toBeTruthy()
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
it('leaves the person to the owner picker on a file that has one', () => {
|
|
190
|
+
const card = render(<LinkCard link={linkStateFrom({ ...GROUP, children: [] }, UNREAD, options())} />)
|
|
191
|
+
expect(within(card.container).queryByText('PT')).toBeNull()
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('counts minutes, hours and days, then gives the date', () => {
|
|
195
|
+
const at = (gone: number) => {
|
|
196
|
+
cleanup()
|
|
197
|
+
render(<LinkCard link={linkStateFrom({ ...PAGE, address: undefined, changedAt: now - gone }, UNREAD, options())} />)
|
|
198
|
+
return screen.getByText(/^Updated /).textContent
|
|
199
|
+
}
|
|
200
|
+
expect(at(10)).toBe('Updated just now')
|
|
201
|
+
expect(at(5 * 60)).toBe('Updated 5m ago')
|
|
202
|
+
expect(at(3 * 86400)).toBe('Updated 3d ago')
|
|
203
|
+
expect(at(30 * 86400)).not.toMatch(/ago/)
|
|
204
|
+
})
|
|
205
|
+
})
|
|
206
|
+
|
|
155
207
|
describe('a file the reader cannot read', () => {
|
|
156
208
|
it('is not available, and opens in its app only at an https address', () => {
|
|
157
209
|
const stub: LinkedSource = { ...GROUP, unreachable: true, noun: 'group', appName: 'App one', openUrl: 'https://app.example/x' }
|
|
158
210
|
render(<LinkCard link={linkStateFrom(stub, UNREAD, options())} />)
|
|
159
|
-
expect(screen.getByText(/Group
|
|
211
|
+
expect(screen.getByText(/Group not available/)).toBeTruthy()
|
|
160
212
|
expect(screen.getByRole('link', { name: /App one/ }).getAttribute('href')).toBe('https://app.example/x')
|
|
161
213
|
cleanup()
|
|
162
214
|
render(<LinkCard link={linkStateFrom({ ...stub, openUrl: 'javascript:alert(1)' }, UNREAD, options())} />)
|
|
@@ -165,12 +217,12 @@ describe('a file the reader cannot read', () => {
|
|
|
165
217
|
|
|
166
218
|
it('is named by its address when its app gives it no noun', () => {
|
|
167
219
|
render(<LinkCard link={linkStateFrom({ ...GROUP, unreachable: true, appName: 'App one' }, { kind: 'file', noun: 'Record' }, options())} />)
|
|
168
|
-
expect(screen.getByText('Record
|
|
220
|
+
expect(screen.getByText('Record not available')).toBeTruthy()
|
|
169
221
|
})
|
|
170
222
|
|
|
171
223
|
it('reads as the address says while it loads and when nothing came back', () => {
|
|
172
224
|
render(<LinkCard link={linkStateFrom(null, { kind: 'file', noun: 'Record' }, options())} />)
|
|
173
|
-
expect(screen.getByText('Record
|
|
225
|
+
expect(screen.getByText('Record not available')).toBeTruthy()
|
|
174
226
|
})
|
|
175
227
|
})
|
|
176
228
|
|
package/src/linkedFrom.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* words, what an address is before it is read) is the app's, passed in.
|
|
11
11
|
*/
|
|
12
12
|
import { thingKindOf } from './KindIcon'
|
|
13
|
-
import type { LinkState, Linked, LinkedChild, LinkedConversation, LinkedKind, LinkedPicker, StatusColour } from './linked'
|
|
13
|
+
import type { LinkState, Linked, LinkedChild, LinkedConversation, LinkedKind, LinkedPerson, LinkedPicker, StatusColour } from './linked'
|
|
14
14
|
|
|
15
15
|
/** A person as interop names them: a profile, possibly empty. */
|
|
16
16
|
export interface LinkedProfile {
|
|
@@ -80,6 +80,23 @@ export interface LinkedFromOptions<T extends LinkedSource = LinkedSource> {
|
|
|
80
80
|
onAct?: (actionId: string, value: string) => void
|
|
81
81
|
/** What was said about it, when the app has read that. */
|
|
82
82
|
conversation?: LinkedConversation
|
|
83
|
+
/**
|
|
84
|
+
* When it last changed, from interop's `changedAt` (in seconds), in the app's words. Without it a card says it the
|
|
85
|
+
* kit's way, alike in every app: "just now", "5m ago", "2h ago", "3d ago", then the date.
|
|
86
|
+
*/
|
|
87
|
+
whenOf?: (seconds: number) => string
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** How long ago a time in seconds was, as a card says it: "just now", "5m ago", "2h ago", "3d ago", then "12 Oct". */
|
|
91
|
+
function agoOf(seconds: number, now = Date.now()): string {
|
|
92
|
+
const gone = Math.max(0, Math.floor(now / 1000 - seconds))
|
|
93
|
+
if (gone < 60) return 'just now'
|
|
94
|
+
if (gone < 3600) return `${Math.floor(gone / 60)}m ago`
|
|
95
|
+
if (gone < 86400) return `${Math.floor(gone / 3600)}h ago`
|
|
96
|
+
if (gone < 7 * 86400) return `${Math.floor(gone / 86400)}d ago`
|
|
97
|
+
const date = new Date(seconds * 1000)
|
|
98
|
+
const year = date.getFullYear() === new Date(now).getFullYear() ? {} : { year: 'numeric' as const }
|
|
99
|
+
return date.toLocaleDateString(undefined, { day: 'numeric', month: 'short', ...year })
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
/** How many of a file's items its card lists: the most recently changed (Miky, 21 Oct). */
|
|
@@ -226,17 +243,40 @@ function ownerOf(object: LinkedSource, options: Pick<LinkedFromOptions, 'directo
|
|
|
226
243
|
}
|
|
227
244
|
}
|
|
228
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Who made it, when the app can name them: the key its address is signed by (`kind:pubkey:d`). A topic's is its
|
|
248
|
+
* relay's, which names nobody; a file with no address has no key in it.
|
|
249
|
+
*/
|
|
250
|
+
function authorOf(object: LinkedSource, directory: LinkedFromOptions['directory']): LinkedPerson | undefined {
|
|
251
|
+
if (object.kind === KIND_CHANNEL || !object.address) return undefined
|
|
252
|
+
const pubkey = object.address.split(':')[1]
|
|
253
|
+
if (!pubkey || !/^[0-9a-f]{64}$/.test(pubkey)) return undefined
|
|
254
|
+
const profile = object.people?.[pubkey] ?? directory?.[pubkey]
|
|
255
|
+
if (!profile?.displayName) return undefined
|
|
256
|
+
return { name: profile.displayName, ...(profile.picture ? { picture: profile.picture } : {}) }
|
|
257
|
+
}
|
|
258
|
+
|
|
229
259
|
/** The file a reference names, as the kit's chip, row and card draw it. */
|
|
230
260
|
export function linkedFrom<T extends LinkedSource>(object: T, options: LinkedFromOptions<T>): Linked {
|
|
231
261
|
const { slots, people } = object
|
|
232
262
|
const id = idOf(object)
|
|
233
263
|
const href = options.hrefOf(object, true)
|
|
264
|
+
// When it last changed (Katerina, 30 Oct: "no date no person"). A message's is when it was written.
|
|
265
|
+
const updated = object.changedAt !== undefined ? (options.whenOf ?? agoOf)(object.changedAt) : undefined
|
|
234
266
|
if (isMessage(object) && slots.title?.isPubkey) {
|
|
235
267
|
// A message is titled by its author (RIC-11): drawn with their face, then its opening words.
|
|
236
268
|
const person = people?.[slots.title.value]
|
|
237
269
|
const name = person?.displayName ?? '—'
|
|
238
270
|
const body = slots.body?.value ? options.previewText(slots.body.value, people) : ''
|
|
239
|
-
return {
|
|
271
|
+
return {
|
|
272
|
+
id,
|
|
273
|
+
kind: 'message',
|
|
274
|
+
title: name,
|
|
275
|
+
href,
|
|
276
|
+
author: { name, ...(person?.picture ? { picture: person.picture } : {}) },
|
|
277
|
+
...(body ? { body } : {}),
|
|
278
|
+
...(updated ? { updated } : {}),
|
|
279
|
+
}
|
|
240
280
|
}
|
|
241
281
|
const onAct = object.archived ? undefined : options.onAct
|
|
242
282
|
const key = keyOf(object)
|
|
@@ -244,6 +284,8 @@ export function linkedFrom<T extends LinkedSource>(object: T, options: LinkedFro
|
|
|
244
284
|
const owner = ownerOf(object, options, onAct)
|
|
245
285
|
const children = childrenOf(object, options)
|
|
246
286
|
const done = doneOf(object)
|
|
287
|
+
// Who made it, when nothing else on it names a person: an issue's owner already does.
|
|
288
|
+
const author = owner ? undefined : authorOf(object, options.directory)
|
|
247
289
|
return {
|
|
248
290
|
id,
|
|
249
291
|
kind: linkedKindOfKind(object.kind),
|
|
@@ -258,6 +300,8 @@ export function linkedFrom<T extends LinkedSource>(object: T, options: LinkedFro
|
|
|
258
300
|
...(options.conversation ? { conversation: options.conversation } : {}),
|
|
259
301
|
...(children ? { children } : {}),
|
|
260
302
|
...(done ? { done } : {}),
|
|
303
|
+
...(author ? { authors: [author] } : {}),
|
|
304
|
+
...(updated ? { updated } : {}),
|
|
261
305
|
}
|
|
262
306
|
}
|
|
263
307
|
|