@estiva-app/ui 0.74.1 → 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.
Files changed (87) hide show
  1. package/dist/CardUnder.d.ts +10 -0
  2. package/dist/CardUnder.d.ts.map +1 -0
  3. package/dist/CommentBox.d.ts +119 -0
  4. package/dist/CommentBox.d.ts.map +1 -0
  5. package/dist/ComposeBox.d.ts +2 -0
  6. package/dist/ComposeBox.d.ts.map +1 -1
  7. package/dist/InlineChip.d.ts +2 -0
  8. package/dist/InlineChip.d.ts.map +1 -1
  9. package/dist/LinkCard.d.ts +17 -0
  10. package/dist/LinkCard.d.ts.map +1 -0
  11. package/dist/LinkChip.d.ts +8 -0
  12. package/dist/LinkChip.d.ts.map +1 -0
  13. package/dist/LinkParts.d.ts +45 -0
  14. package/dist/LinkParts.d.ts.map +1 -0
  15. package/dist/LinkPreview.d.ts +21 -0
  16. package/dist/LinkPreview.d.ts.map +1 -0
  17. package/dist/LinkRow.d.ts +24 -0
  18. package/dist/LinkRow.d.ts.map +1 -0
  19. package/dist/PartCard.d.ts +32 -0
  20. package/dist/PartCard.d.ts.map +1 -0
  21. package/dist/ReactionRow.d.ts +44 -0
  22. package/dist/ReactionRow.d.ts.map +1 -0
  23. package/dist/Skeleton.d.ts +12 -2
  24. package/dist/Skeleton.d.ts.map +1 -1
  25. package/dist/editor.d.ts +1 -0
  26. package/dist/editor.d.ts.map +1 -1
  27. package/dist/editor.js +2340 -2043
  28. package/dist/editor.js.map +4 -4
  29. package/dist/eslint/index.js +1 -0
  30. package/dist/eslint/index.js.map +2 -2
  31. package/dist/eslint/no-restyled-part.d.ts.map +1 -1
  32. package/dist/index.d.ts +9 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +546 -72
  35. package/dist/index.js.map +4 -4
  36. package/dist/linked.d.ts +168 -0
  37. package/dist/linked.d.ts.map +1 -0
  38. package/dist/linked.examples.d.ts +27 -0
  39. package/dist/linked.examples.d.ts.map +1 -0
  40. package/package.json +6 -2
  41. package/registry.json +1129 -37
  42. package/src/CardUnder.mdx +53 -0
  43. package/src/CardUnder.stories.tsx +45 -0
  44. package/src/CardUnder.test.tsx +40 -0
  45. package/src/CardUnder.tsx +45 -0
  46. package/src/CommentBox.mdx +83 -0
  47. package/src/CommentBox.stories.tsx +218 -0
  48. package/src/CommentBox.test.tsx +265 -0
  49. package/src/CommentBox.tsx +472 -0
  50. package/src/ComposeBox.tsx +5 -4
  51. package/src/InlineChip.tsx +2 -0
  52. package/src/LinkCard.mdx +58 -0
  53. package/src/LinkCard.stories.tsx +68 -0
  54. package/src/LinkCard.test.tsx +103 -0
  55. package/src/LinkCard.tsx +209 -0
  56. package/src/LinkChip.mdx +51 -0
  57. package/src/LinkChip.stories.tsx +40 -0
  58. package/src/LinkChip.test.tsx +83 -0
  59. package/src/LinkChip.tsx +51 -0
  60. package/src/LinkParts.mdx +49 -0
  61. package/src/LinkParts.stories.tsx +61 -0
  62. package/src/LinkParts.tsx +147 -0
  63. package/src/LinkPreview.mdx +47 -0
  64. package/src/LinkPreview.stories.tsx +38 -0
  65. package/src/LinkPreview.tsx +55 -0
  66. package/src/LinkRow.mdx +47 -0
  67. package/src/LinkRow.stories.tsx +49 -0
  68. package/src/LinkRow.test.tsx +38 -0
  69. package/src/LinkRow.tsx +107 -0
  70. package/src/PartCard.mdx +43 -0
  71. package/src/PartCard.stories.tsx +35 -0
  72. package/src/PartCard.test.tsx +30 -0
  73. package/src/PartCard.tsx +59 -0
  74. package/src/ReactionRow.mdx +50 -0
  75. package/src/ReactionRow.stories.tsx +91 -0
  76. package/src/ReactionRow.test.tsx +68 -0
  77. package/src/ReactionRow.tsx +118 -0
  78. package/src/Skeleton.tsx +7 -3
  79. package/src/editor.ts +11 -0
  80. package/src/eslint/no-native-title.test.ts +3 -2
  81. package/src/eslint/no-restyled-part.ts +1 -0
  82. package/src/index.ts +26 -0
  83. package/src/linked.examples.ts +107 -0
  84. package/src/linked.test.ts +58 -0
  85. package/src/linked.ts +217 -0
  86. package/src/registry/registry.test.ts +8 -8
  87. package/stories/Choosing.mdx +10 -1
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A part of something longer, shared live: its blocks as they are now, under
3
+ * the header of what it is part of (why:
4
+ * https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-shared-part-of-a-page-is-a-selected-run-of-blocks.md).
5
+ * There is no row or card choice for a part: it draws itself. The app draws
6
+ * the blocks and passes them as `children`.
7
+ */
8
+ import type { ReactNode } from 'react'
9
+ import { Card } from './Card'
10
+ import { Link } from './Link'
11
+ import { LinkCardLoading } from './LinkCard'
12
+ import type { LinkedKind } from './linked'
13
+ import { LinkedIcon, LinkKey } from './LinkParts'
14
+ import { LinkUnavailable } from './LinkRow'
15
+
16
+ export interface PartCardProps {
17
+ /** Where its lookup stands. Default `ready`. */
18
+ state?: 'ready' | 'loading' | 'unavailable'
19
+ /** What it is part of, by its icon. */
20
+ kind: LinkedKind
21
+ /** The title of what it is part of. */
22
+ heading?: string
23
+ /** Opens what it is part of, at the part. */
24
+ href?: string
25
+ /** The key of what it is part of: "ABC-2". */
26
+ partKey?: string
27
+ /** What it is part of, in a word, for "A part of this item — not available.". */
28
+ noun?: string
29
+ /** Where it may still open, for someone who can, when it is not available. */
30
+ openIn?: { app: string; href: string }
31
+ /** The part's blocks, drawn by the app. */
32
+ children?: ReactNode
33
+ }
34
+
35
+ export function PartCard({ state = 'ready', kind, heading, href, partKey, noun = 'Item', openIn, children }: PartCardProps) {
36
+ if (state === 'loading') return <LinkCardLoading kind={kind} shape={{ summary: true, rows: 0, footer: 'none' }} />
37
+ if (state === 'unavailable') return <LinkUnavailable kind={kind} noun={`A part of this ${noun.toLowerCase()}`} openIn={openIn} />
38
+ const header = (
39
+ <>
40
+ <LinkedIcon kind={kind} />
41
+ {partKey && <LinkKey>{partKey}</LinkKey>}
42
+ <span className="truncate">{heading}</span>
43
+ </>
44
+ )
45
+ return (
46
+ <Card fill="inset" className="flex flex-col gap-2 p-3">
47
+ <span className="flex min-w-0 items-center gap-2 text-body-2-strong text-text-primary">
48
+ {href ? (
49
+ <Link href={href} variant="quiet" className="flex min-w-0 items-center gap-2">
50
+ {header}
51
+ </Link>
52
+ ) : (
53
+ header
54
+ )}
55
+ </span>
56
+ <div className="border-l-2 border-border-default pl-3">{children}</div>
57
+ </Card>
58
+ )
59
+ }
@@ -0,0 +1,50 @@
1
+ import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
+ import * as ReactionRowStories from './ReactionRow.stories'
3
+
4
+ <Meta of={ReactionRowStories} />
5
+
6
+ # ReactionRow
7
+
8
+ The one row of reactions under a comment or a line, in every app: **Reaction** pills in the order first chosen, yours lit, who reacted on hover, and the add button with **ReactionPicker**.
9
+
10
+ <Canvas of={ReactionRowStories.Default} />
11
+
12
+ ## When
13
+
14
+ - **Under anything people react to**, in every app.
15
+ - `onToggle` absent where nobody can react (read-only, signed out): the pills show, disabled, and there is no add button.
16
+ - **AddReactionButton** alone where nobody has reacted yet: the row draws nothing, and the button sits with the other actions.
17
+
18
+ <Canvas of={ReactionRowStories.ManyPeople} />
19
+
20
+ ## When not
21
+
22
+ - Choosing an emoji anywhere else → **ReactionPicker**, the row of choices on its own.
23
+ - One count on its own → **Reaction**.
24
+
25
+ ## How
26
+
27
+ ```tsx
28
+ import { ReactionRow, AddReactionButton } from '@estiva-app/ui'
29
+
30
+ // groupReactions and REACTION_EMOJI: @estiva-app/conversation, which this package does not depend on.
31
+ const options = REACTION_EMOJI.map(({ emoji, name }) => ({ emoji, label: name }))
32
+ const reactions = groupReactions(decorations.byId[id].reactions, me)[id] ?? []
33
+
34
+ <ReactionRow reactions={reactions} options={options} nameOf={nameOf} viewer={me} onToggle={(emoji) => toggle(id, emoji)} />
35
+ ```
36
+
37
+ - **The counts are the app's to read**, by SPEC §6.6, through `@estiva-app/conversation`: `decorationsOf` and `groupReactions`. The row draws what it is given.
38
+ - **`onToggle` is yours on or off**: the app writes the reaction, or its retraction.
39
+ - `nameOf` names each reactor for "who reacted"; past eight names the rest are counted.
40
+
41
+ ## What it owns
42
+
43
+ | It does | So you never write |
44
+ |---|---|
45
+ | No row when nobody reacted | an empty check |
46
+ | "Person one, Person two and you reacted with Makes sense" on hover | the sentence |
47
+ | The picker over the add button, closing on a pick | a popover |
48
+ | Disabled pills and no add button without `onToggle` | a read-only branch |
49
+
50
+ <Controls />
@@ -0,0 +1,91 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { useState } from 'react'
3
+ import { AddReactionButton, ReactionRow, type ReactionCount } from './ReactionRow'
4
+
5
+ /**
6
+ * The one reaction row under a comment or a line. Live: press a pill to take
7
+ * yours back or add it, and the add button for another. Hover a pill for who
8
+ * reacted.
9
+ */
10
+ const meta = {
11
+ title: 'Primitives/ReactionRow',
12
+ component: ReactionRow,
13
+ parameters: { layout: 'padded' },
14
+ } satisfies Meta<typeof ReactionRow>
15
+
16
+ export default meta
17
+ type Story = StoryObj
18
+
19
+ const OPTIONS = [
20
+ { emoji: '👍', label: 'Makes sense' },
21
+ { emoji: '💯', label: 'Agree' },
22
+ { emoji: '🙏', label: 'Thank you' },
23
+ { emoji: '🎉', label: 'Celebrate' },
24
+ { emoji: '👀', label: 'Looking' },
25
+ ]
26
+
27
+ const ME = 'me'
28
+ const NAMES: Record<string, string> = { me: 'Me', a: 'Person one', b: 'Person two', c: 'Person three', d: 'Person four', e: 'Person five' }
29
+ const nameOf = (id: string) => NAMES[id] ?? 'Someone'
30
+
31
+ /** Yours on or off, as the relay would count it. */
32
+ const toggled = (reactions: ReactionCount[], emoji: string): ReactionCount[] => {
33
+ const found = reactions.find((r) => r.emoji === emoji)
34
+ if (!found) return [...reactions, { emoji, by: [ME] }]
35
+ return reactions
36
+ .map((r) => (r.emoji !== emoji ? r : { ...r, by: r.by.includes(ME) ? r.by.filter((id) => id !== ME) : [...r.by, ME] }))
37
+ .filter((r) => r.by.length > 0)
38
+ }
39
+
40
+ function Live({ start, readOnly }: { start: ReactionCount[]; readOnly?: boolean }) {
41
+ const [reactions, setReactions] = useState(start)
42
+ return (
43
+ <ReactionRow
44
+ reactions={reactions}
45
+ options={OPTIONS}
46
+ nameOf={nameOf}
47
+ viewer={ME}
48
+ onToggle={readOnly ? undefined : (emoji) => setReactions((all) => toggled(all, emoji))}
49
+ />
50
+ )
51
+ }
52
+
53
+ /** A few reactions, yours lit. */
54
+ export const Default: Story = {
55
+ render: () => (
56
+ <Live
57
+ start={[
58
+ { emoji: '👍', by: ['a', ME] },
59
+ { emoji: '🙏', by: ['b'] },
60
+ ]}
61
+ />
62
+ ),
63
+ }
64
+
65
+ /** Many people on one emoji: the count, and who on hover. */
66
+ export const ManyPeople: Story = {
67
+ render: () => (
68
+ <Live
69
+ start={[
70
+ { emoji: '👍', by: ['a', 'b', 'c', 'd', 'e', ME] },
71
+ { emoji: '🎉', by: ['c', 'd'] },
72
+ { emoji: '👀', by: ['e'] },
73
+ ]}
74
+ />
75
+ ),
76
+ }
77
+
78
+ /** Read-only: the pills show, and nothing can be added or taken back. */
79
+ export const ReadOnly: Story = { render: () => <Live readOnly start={[{ emoji: '👍', by: ['a', 'b'] }]} /> }
80
+
81
+ /** Nobody reacted: no row; the add button sits with the other actions. */
82
+ export const NoReactions: Story = {
83
+ render: function NoReactions() {
84
+ const [reactions, setReactions] = useState<ReactionCount[]>([])
85
+ return reactions.length > 0 ? (
86
+ <ReactionRow reactions={reactions} options={OPTIONS} nameOf={nameOf} viewer={ME} onToggle={(emoji) => setReactions((all) => toggled(all, emoji))} />
87
+ ) : (
88
+ <AddReactionButton options={OPTIONS} onPick={(emoji) => setReactions((all) => toggled(all, emoji))} />
89
+ )
90
+ },
91
+ }
@@ -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/Skeleton.tsx CHANGED
@@ -10,10 +10,14 @@ import { cn } from './cn'
10
10
  * A list reveals after 150ms (`animate-skeleton-in`, in the preset) so a
11
11
  * fast load never flashes a skeleton — Peek's rule.
12
12
  */
13
+ const SKELETON_SHAPE = { bar: 'rounded-sm', round: 'rounded-full', control: 'rounded-md' } as const
14
+
13
15
  /** One pulsing bar at the inset colour: the piece every placeholder here is
14
- * built from. It draws nothing of its own — give it a width and a height. */
15
- export function SkeletonBar({ className, style }: { className?: string; style?: CSSProperties }) {
16
- return <div className={cn('bg-bg-inset rounded-sm animate-pulse', className)} style={style} />
16
+ * built from. It draws nothing of its own — give it a width and a height.
17
+ * `on="inset"` on an inset card, where the inset colour would vanish;
18
+ * `shape` for a line of words, a face or a ring, or a control. */
19
+ export function SkeletonBar({ className, style, on = 'surface', shape = 'bar' }: { className?: string; style?: CSSProperties; on?: 'surface' | 'inset'; shape?: keyof typeof SKELETON_SHAPE }) {
20
+ return <div className={cn('animate-pulse', SKELETON_SHAPE[shape], on === 'inset' ? 'bg-bg-active' : 'bg-bg-inset', className)} style={style} />
17
21
  }
18
22
 
19
23
  const ROW_BAR_WIDTHS = [150, 100, 170, 120, 90, 140, 110, 160]
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,
@@ -60,8 +60,9 @@ tester.run('no-native-title', noNativeTitle, {
60
60
 
61
61
  describe('PARTS_WITH_A_TITLE', () => {
62
62
  it('is every part the catalogue says takes a title of its own, and no other', () => {
63
- const registry = JSON.parse(readFileSync(new URL('../../registry.json', import.meta.url), 'utf8')) as { entries: { name: string; props?: { name: string }[] | null }[] }
64
- const declared = registry.entries.filter((entry) => entry.props?.some((prop) => prop.name === 'title')).map((entry) => entry.name).sort()
63
+ const registry = JSON.parse(readFileSync(new URL('../../registry.json', import.meta.url), 'utf8')) as { entries: { name: string; kind: string; props?: { name: string }[] | null }[] }
64
+ // A part is a component: a helper whose argument has a `title` field (`loadingShapeOf`) is not drawn with one.
65
+ const declared = registry.entries.filter((entry) => entry.kind === 'component' && entry.props?.some((prop) => prop.name === 'title')).map((entry) => entry.name).sort()
65
66
  expect([...PARTS_WITH_A_TITLE].sort()).toEqual(declared)
66
67
  })
67
68
  })
@@ -132,6 +132,7 @@ export const PART_LOOK_PROPS: Record<string, string[]> = {
132
132
  Checkbox: ['row'],
133
133
  Chip: ['type'],
134
134
  KindIcon: ['tone'],
135
+ LinkedIcon: ['tone'],
135
136
  CollapsibleSection: ['look'],
136
137
  Divider: ['tone', 'orientation'],
137
138
  EmptyState: ['scope'],
package/src/index.ts CHANGED
@@ -84,6 +84,31 @@ export { ShowMore, type ShowMoreProps } from './ShowMore'
84
84
  export { ReactionPicker, type ReactionOption, type ReactionPickerProps } from './ReactionPicker'
85
85
  export { Toolbar, ToolbarButton, ToolbarInput, ToolbarLink, ToolbarSeparator, type ToolbarProps, type ToolbarButtonProps, type ToolbarInputProps, type ToolbarLinkProps } from './Toolbar'
86
86
  export { PreviewCard, type PreviewCardProps } from './PreviewCard'
87
+ // How a link draws, wherever it sits: one kit for every app (Widgets 2).
88
+ export {
89
+ chosenOf,
90
+ loadingShapeOf,
91
+ unavailableMemory,
92
+ type Linked,
93
+ type LinkedChild,
94
+ type LinkedConversation,
95
+ type LinkedKind,
96
+ type LinkedPerson,
97
+ type LinkedPicker,
98
+ type LinkedStatus,
99
+ type LinkState,
100
+ type LoadingShape,
101
+ type PickerOption,
102
+ type StatusColour,
103
+ type UnavailableMemory,
104
+ } from './linked'
105
+ export { CommentCount, LinkedIcon, LinkKey, LinkPickers, ProgressRing, StatusMark, type LinkPickersProps } from './LinkParts'
106
+ export { LinkChip, type LinkChipProps } from './LinkChip'
107
+ export { LinkRow, LinkUnavailable, type LinkRowProps, type LinkUnavailableProps } from './LinkRow'
108
+ export { LinkCard, LinkCardLoading, type LinkCardProps, type LinkCardLoadingProps } from './LinkCard'
109
+ export { LinkPreview, LinkPreviewOpen, useCanHover, type LinkPreviewProps } from './LinkPreview'
110
+ export { CardUnder, type CardUnderProps } from './CardUnder'
111
+ export { PartCard, type PartCardProps } from './PartCard'
87
112
  export { Person, type PersonProps } from './Person'
88
113
  export { Rail, type RailProps } from './Rail'
89
114
  export { RailItem, type RailItemProps } from './RailItem'
@@ -92,6 +117,7 @@ export { TopBar, type TopBarProps } from './TopBar'
92
117
  export { PersonTrigger, type PersonTriggerProps } from './PersonTrigger'
93
118
  export { Property, type PropertyProps } from './Property'
94
119
  export { Reaction, type ReactionProps } from './Reaction'
120
+ export { ReactionRow, AddReactionButton, whoReacted, type ReactionRowProps, type AddReactionButtonProps, type ReactionCount } from './ReactionRow'
95
121
  export { SearchInput, type SearchInputProps } from './SearchInput'
96
122
  export { SectionHeader, type SectionAction, type SectionHeaderProps } from './SectionHeader'
97
123
  export { ContainerHeader, type ContainerHeaderProps } from './ContainerHeader'
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Placeholder links for the link widgets' stories and tests: neutral words,
3
+ * every field one of the widgets draws. Not exported from the package.
4
+ */
5
+ import type { Linked, LinkedPicker, LinkState, PickerOption } from './linked'
6
+
7
+ const noop = () => {}
8
+
9
+ export const STATUS_OPTIONS: PickerOption[] = [
10
+ { value: 'todo', label: 'Todo', colour: 'neutral' },
11
+ { value: 'doing', label: 'In progress', colour: 'blue' },
12
+ { value: 'done', label: 'Done', colour: 'green' },
13
+ { value: 'dropped', label: 'Cancelled', colour: 'muted' },
14
+ ]
15
+
16
+ export const PEOPLE: PickerOption[] = [
17
+ { value: 'a', label: 'Person one' },
18
+ { value: 'b', label: 'Person two' },
19
+ { value: 'c', label: 'Person three' },
20
+ ]
21
+
22
+ const picker = (value: string | undefined, options: PickerOption[], mayChange = true): LinkedPicker => ({ value, options, onChange: mayChange ? noop : undefined })
23
+
24
+ const SUMMARY = 'A one-sentence summary of what this is for.'
25
+
26
+ /** A tracked item: a key, a status and an owner the reader may change, and a conversation. */
27
+ export const ITEM: Linked = {
28
+ id: 'example:item',
29
+ kind: 'issue',
30
+ title: 'Item one, with a title long enough to be cut short',
31
+ href: '#item',
32
+ key: 'ABC-2',
33
+ subtitle: 'Group one',
34
+ summary: SUMMARY,
35
+ status: picker('doing', STATUS_OPTIONS),
36
+ owner: picker('a', PEOPLE),
37
+ ownerLabel: 'Owner',
38
+ conversation: { count: 4, href: '#item-conversation' },
39
+ }
40
+
41
+ /** The same item, to a reader who may not change it. */
42
+ export const ITEM_READ_ONLY: Linked = { ...ITEM, status: picker('doing', STATUS_OPTIONS, false), owner: picker('a', PEOPLE, false) }
43
+
44
+ /** The same item with something unread in its conversation, as a member sees it. */
45
+ export const ITEM_UNREAD: Linked = { ...ITEM, conversation: { count: 5, href: '#item-conversation', unread: true } }
46
+
47
+ /** An item with no summary: its card shows the title alone. */
48
+ export const ITEM_NO_SUMMARY: Linked = { ...ITEM, id: 'example:item-2', title: 'Item two', key: 'ABC-3', summary: undefined, owner: picker(undefined, PEOPLE) }
49
+
50
+ /** A group of items: its progress, its owner, and the items inside it. */
51
+ export const GROUP: Linked = {
52
+ id: 'example:group',
53
+ kind: 'project',
54
+ title: 'Group one',
55
+ href: '#group',
56
+ summary: SUMMARY,
57
+ status: picker('doing', STATUS_OPTIONS),
58
+ owner: picker('b', PEOPLE),
59
+ ownerLabel: 'Lead',
60
+ done: { done: 2, total: 5 },
61
+ conversation: { count: 2, href: '#group-conversation' },
62
+ children: [
63
+ { id: 'example:c1', title: 'Item one', href: '#c1', key: 'ABC-1', status: { label: 'Done', colour: 'green' }, owner: { name: 'Person one' } },
64
+ { id: 'example:c2', title: 'Item two', href: '#c2', key: 'ABC-2', status: { label: 'In progress', colour: 'blue' }, owner: { name: 'Person two' } },
65
+ { id: 'example:c3', title: 'Item three', href: '#c3', key: 'ABC-3', status: { label: 'Todo', colour: 'neutral' } },
66
+ ],
67
+ }
68
+
69
+ /** A place people talk: its members, when it last moved, and its newest conversation. */
70
+ export const PLACE: Linked = {
71
+ id: 'example:place',
72
+ kind: 'topic',
73
+ title: 'Place one',
74
+ href: '#place',
75
+ summary: SUMMARY,
76
+ members: [{ name: 'Person one' }, { name: 'Person two' }, { name: 'Person three' }],
77
+ updated: '2h ago',
78
+ conversation: { count: 12, href: '#place-conversations', noun: 'conversations' },
79
+ latest: { author: { name: 'Person two' }, body: 'A few words someone wrote, long enough to need a second line before the card cuts them short.', at: '2h ago' },
80
+ }
81
+
82
+ /** A page of text: who wrote it, and when it last changed. */
83
+ export const PAGE: Linked = {
84
+ id: 'example:page',
85
+ kind: 'page',
86
+ title: 'Page one',
87
+ href: '#page',
88
+ subtitle: 'Shelf one',
89
+ summary: SUMMARY,
90
+ authors: [{ name: 'Person one' }, { name: 'Person three' }],
91
+ updated: 'Yesterday',
92
+ }
93
+
94
+ /** Words a person wrote, linked as themselves. */
95
+ export const SAID: Linked = {
96
+ id: 'example:said',
97
+ kind: 'message',
98
+ title: 'A few words someone wrote',
99
+ href: '#said',
100
+ author: { name: 'Person one' },
101
+ body: 'A few words someone wrote, linked from somewhere else. Long enough to wrap onto a second line.',
102
+ updated: '10:42',
103
+ }
104
+
105
+ export const ready = (linked: Linked): LinkState => ({ state: 'ready', linked })
106
+ export const LOADING: LinkState = { state: 'loading', kind: 'issue' }
107
+ export const UNAVAILABLE: LinkState = { state: 'unavailable', kind: 'issue', noun: 'Item', openIn: { app: 'App one', href: '#elsewhere' } }
@@ -0,0 +1,58 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * The device's memory of links it could not show: kept across a reload, so
4
+ * the next open draws "not available." from the first paint, and forgotten
5
+ * when the link can be read again or at sign-out.
6
+ */
7
+ import { afterEach, describe, expect, it } from 'vitest'
8
+ import { unavailableMemory } from './linked'
9
+
10
+ afterEach(() => localStorage.clear())
11
+
12
+ describe('unavailableMemory', () => {
13
+ it('remembers a link it could not show across a reload', () => {
14
+ unavailableMemory('test.unavailable').note('a', false)
15
+ // A new page: a fresh memory reads what the last one wrote.
16
+ expect(unavailableMemory('test.unavailable').has('a')).toBe(true)
17
+ expect(unavailableMemory('test.unavailable').has('b')).toBe(false)
18
+ })
19
+
20
+ it('forgets it once it can be read again', () => {
21
+ const memory = unavailableMemory('test.unavailable')
22
+ memory.note('a', false)
23
+ memory.note('a', true)
24
+ expect(unavailableMemory('test.unavailable').has('a')).toBe(false)
25
+ })
26
+
27
+ it('keeps what another memory on the same key wrote since it was read', () => {
28
+ const one = unavailableMemory('test.unavailable')
29
+ const two = unavailableMemory('test.unavailable')
30
+ expect(two.has('a')).toBe(false)
31
+ one.note('a', false)
32
+ two.note('b', false)
33
+ const next = unavailableMemory('test.unavailable')
34
+ expect([next.has('a'), next.has('b')]).toEqual([true, true])
35
+ })
36
+
37
+ it('keeps each app’s memory apart', () => {
38
+ unavailableMemory('one.unavailable').note('a', false)
39
+ expect(unavailableMemory('two.unavailable').has('a')).toBe(false)
40
+ })
41
+
42
+ it('forgets everything at sign-out', () => {
43
+ const memory = unavailableMemory('test.unavailable')
44
+ memory.note('a', false)
45
+ memory.clear()
46
+ expect(memory.has('a')).toBe(false)
47
+ expect(unavailableMemory('test.unavailable').has('a')).toBe(false)
48
+ })
49
+
50
+ it('keeps only the newest, up to its limit', () => {
51
+ const memory = unavailableMemory('test.unavailable', 2)
52
+ memory.note('a', false)
53
+ memory.note('b', false)
54
+ memory.note('c', false)
55
+ const next = unavailableMemory('test.unavailable', 2)
56
+ expect([next.has('a'), next.has('b'), next.has('c')]).toEqual([false, true, true])
57
+ })
58
+ })