@justanarthur/modo-ui-notch 0.2.0 → 0.4.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 (148) hide show
  1. package/README.md +11 -11
  2. package/blocks/activities/agenda/examples.mdx +29 -5
  3. package/blocks/activities/agenda/index.tsx +438 -181
  4. package/blocks/activities/clock/examples.mdx +89 -0
  5. package/blocks/activities/clock/index.tsx +917 -0
  6. package/blocks/activities/now-playing/examples.mdx +40 -13
  7. package/blocks/activities/now-playing/index.tsx +399 -120
  8. package/blocks/activities/weather/examples.mdx +123 -0
  9. package/blocks/activities/weather/index.tsx +863 -0
  10. package/blocks/app/expanded-island/examples.mdx +8 -7
  11. package/blocks/app/expanded-island/index.tsx +22 -4
  12. package/blocks/app/settings-window/examples.mdx +14 -2
  13. package/blocks/app/settings-window/index.tsx +33 -10
  14. package/blocks/system/clipboard/examples.mdx +91 -0
  15. package/blocks/system/clipboard/index.tsx +773 -0
  16. package/blocks/system/recent-files/examples.mdx +80 -0
  17. package/blocks/system/recent-files/index.tsx +627 -0
  18. package/blocks/system/system-stats/examples.mdx +46 -9
  19. package/blocks/system/system-stats/index.tsx +445 -104
  20. package/components/indicators/media-scrubber/examples.mdx +8 -0
  21. package/components/indicators/media-scrubber/index.tsx +37 -13
  22. package/components/island/island/examples.mdx +4 -4
  23. package/components/island/island/index.tsx +2 -2
  24. package/components/island/island-flash/examples.mdx +15 -18
  25. package/components/island/island-flash/index.tsx +4 -4
  26. package/components/island/island-tabs/examples.mdx +5 -5
  27. package/components/island/widget/examples.mdx +76 -0
  28. package/components/island/widget/index.tsx +465 -0
  29. package/dist/blocks/activities/agenda/index.d.ts +2 -1
  30. package/dist/blocks/activities/agenda/index.js +3 -3
  31. package/dist/blocks/activities/clock/index.d.ts +3 -0
  32. package/dist/blocks/activities/clock/index.js +25 -0
  33. package/dist/blocks/activities/now-playing/index.d.ts +4 -2
  34. package/dist/blocks/activities/now-playing/index.js +5 -3
  35. package/dist/blocks/activities/weather/index.d.ts +3 -0
  36. package/dist/blocks/activities/weather/index.js +21 -0
  37. package/dist/blocks/app/expanded-island/index.d.ts +1 -1
  38. package/dist/blocks/app/expanded-island/index.js +4 -3
  39. package/dist/blocks/app/settings-window/index.d.ts +1 -1
  40. package/dist/blocks/app/settings-window/index.js +1 -1
  41. package/dist/blocks/system/clipboard/index.d.ts +3 -0
  42. package/dist/blocks/system/clipboard/index.js +17 -0
  43. package/dist/blocks/system/recent-files/index.d.ts +3 -0
  44. package/dist/blocks/system/recent-files/index.js +19 -0
  45. package/dist/blocks/system/system-stats/index.d.ts +3 -2
  46. package/dist/blocks/system/system-stats/index.js +4 -1
  47. package/dist/components/indicators/media-scrubber/index.d.ts +1 -1
  48. package/dist/components/indicators/media-scrubber/index.js +1 -1
  49. package/dist/components/island/island/index.d.ts +1 -1
  50. package/dist/components/island/island/index.js +2 -2
  51. package/dist/components/island/island-flash/index.d.ts +1 -1
  52. package/dist/components/island/island-flash/index.js +1 -1
  53. package/dist/components/island/island-tabs/index.js +2 -2
  54. package/dist/components/island/widget/index.d.ts +2 -0
  55. package/dist/components/island/widget/index.js +32 -0
  56. package/dist/index.d.ts +15 -15
  57. package/dist/index.js +104 -58
  58. package/dist/lib/artwork.d.ts +2 -0
  59. package/dist/lib/artwork.js +8 -0
  60. package/dist/lib/geometry.js +1 -1
  61. package/dist/shared/{chunk-yngkkxz2.d.ts → chunk-0ym9mcqc.d.ts} +10 -6
  62. package/dist/shared/chunk-2b6gpn8k.js +444 -0
  63. package/dist/shared/chunk-3hcnf4yx.js +481 -0
  64. package/dist/shared/chunk-42wab62s.d.ts +197 -0
  65. package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
  66. package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-6tnq6p89.d.ts} +9 -1
  67. package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
  68. package/dist/shared/chunk-93dtpjz7.js +789 -0
  69. package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
  70. package/dist/shared/chunk-a6njb8db.d.ts +129 -0
  71. package/dist/shared/chunk-ab8mdg0n.d.ts +149 -0
  72. package/dist/shared/chunk-evqpf92s.d.ts +168 -0
  73. package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
  74. package/dist/shared/chunk-gcyspvgr.js +582 -0
  75. package/dist/shared/chunk-gejenfap.d.ts +25 -0
  76. package/dist/shared/chunk-gkj0hjrn.d.ts +136 -0
  77. package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
  78. package/dist/shared/chunk-n739am8j.d.ts +112 -0
  79. package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
  80. package/dist/shared/chunk-nwzpekvy.js +774 -0
  81. package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
  82. package/dist/shared/chunk-sbrtesdg.d.ts +138 -0
  83. package/dist/shared/chunk-swc7dqpw.d.ts +115 -0
  84. package/dist/shared/chunk-t9wqhgzt.js +765 -0
  85. package/dist/shared/chunk-w5h6ay93.js +72 -0
  86. package/dist/shared/{chunk-mp1nx0ez.js → chunk-wayv5rhr.js} +15 -4
  87. package/dist/shared/chunk-wf0jtzhs.js +295 -0
  88. package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
  89. package/dist/shared/chunk-yq5svpk7.js +524 -0
  90. package/dist/shared/{chunk-s33y1pcq.js → chunk-z3tj1ydg.js} +23 -10
  91. package/dist/styles.css +151 -49
  92. package/index.ts +7 -6
  93. package/lib/artwork.ts +112 -0
  94. package/lib/geometry.ts +1 -1
  95. package/mock/activities.tsx +9 -32
  96. package/mock/artwork.tsx +13 -1
  97. package/mock/clipboard.tsx +113 -0
  98. package/mock/clock.tsx +77 -0
  99. package/mock/data.ts +78 -44
  100. package/mock/files.tsx +83 -0
  101. package/mock/island-content.tsx +79 -122
  102. package/mock/screen.tsx +76 -0
  103. package/mock/settings.tsx +370 -91
  104. package/mock/system.ts +49 -0
  105. package/mock/weather.tsx +135 -0
  106. package/package.json +7 -2
  107. package/blocks/activities/shelf/examples.mdx +0 -33
  108. package/blocks/activities/shelf/index.tsx +0 -289
  109. package/blocks/activities/timer/examples.mdx +0 -52
  110. package/blocks/activities/timer/index.tsx +0 -292
  111. package/blocks/system/controls/examples.mdx +0 -34
  112. package/blocks/system/controls/index.tsx +0 -167
  113. package/blocks/system/devices/examples.mdx +0 -25
  114. package/blocks/system/devices/index.tsx +0 -172
  115. package/blocks/system/power-alert/examples.mdx +0 -32
  116. package/blocks/system/power-alert/index.tsx +0 -89
  117. package/components/indicators/battery-glyph/examples.mdx +0 -22
  118. package/components/indicators/battery-glyph/index.tsx +0 -91
  119. package/dist/blocks/activities/shelf/index.d.ts +0 -2
  120. package/dist/blocks/activities/shelf/index.js +0 -14
  121. package/dist/blocks/activities/timer/index.d.ts +0 -2
  122. package/dist/blocks/activities/timer/index.js +0 -19
  123. package/dist/blocks/system/controls/index.d.ts +0 -2
  124. package/dist/blocks/system/controls/index.js +0 -10
  125. package/dist/blocks/system/devices/index.d.ts +0 -2
  126. package/dist/blocks/system/devices/index.js +0 -12
  127. package/dist/blocks/system/power-alert/index.d.ts +0 -2
  128. package/dist/blocks/system/power-alert/index.js +0 -9
  129. package/dist/components/indicators/battery-glyph/index.d.ts +0 -2
  130. package/dist/components/indicators/battery-glyph/index.js +0 -9
  131. package/dist/shared/chunk-2qpcsv5h.d.ts +0 -45
  132. package/dist/shared/chunk-45gytfr1.d.ts +0 -84
  133. package/dist/shared/chunk-50ffk4r7.d.ts +0 -69
  134. package/dist/shared/chunk-5w0yck07.d.ts +0 -32
  135. package/dist/shared/chunk-7hr53mby.js +0 -116
  136. package/dist/shared/chunk-b8jb1w72.js +0 -145
  137. package/dist/shared/chunk-cpewy6yg.js +0 -178
  138. package/dist/shared/chunk-e3e4s4ds.d.ts +0 -77
  139. package/dist/shared/chunk-enm6td0p.js +0 -280
  140. package/dist/shared/chunk-fvedaas2.d.ts +0 -33
  141. package/dist/shared/chunk-gex38j8x.d.ts +0 -82
  142. package/dist/shared/chunk-hwtxpzg0.js +0 -69
  143. package/dist/shared/chunk-phb53x1f.js +0 -252
  144. package/dist/shared/chunk-r8esmjfs.d.ts +0 -42
  145. package/dist/shared/chunk-rcp1g9ca.js +0 -70
  146. package/dist/shared/chunk-rx9sphz2.js +0 -266
  147. package/dist/shared/chunk-xdeek16r.d.ts +0 -58
  148. package/dist/shared/chunk-xkzjk1tq.js +0 -206
@@ -0,0 +1,773 @@
1
+ /*!
2
+ * Local addition: a notch app's clipboard history, the latest clip as the
3
+ * hero and the ones before it beside it, pinned ones on top. Presentational:
4
+ * the clips and what to do with them come in as props.
5
+ */
6
+
7
+ 'use client'
8
+
9
+ import Button from '@justanarthur/modo-ui/components/actions/button'
10
+ import Input from '@justanarthur/modo-ui/components/inputs/input'
11
+ import type { IconComponent } from '@justanarthur/modo-ui/lib/icon-context'
12
+ import type { SizeVariant } from '@justanarthur/modo-ui/lib/size-context'
13
+ import { SURFACE_BG } from '@justanarthur/modo-ui/lib/surface-classes'
14
+ import { useLift } from '@justanarthur/modo-ui/lib/surface-context'
15
+ import { useControllableState } from '@justanarthur/modo-ui/lib/use-controllable-state'
16
+ import { cn } from '@justanarthur/modo-ui/lib/utils'
17
+ import FluidHover from '@justanarthur/modo-ui/primitives/systems/fluid-hover'
18
+ import { ClipboardList, Copy, File, Image, Link2, Palette, Pause, Pin, Play, Search, Trash2, Type } from 'lucide-react'
19
+ import type { KeyboardEvent, ReactNode } from 'react'
20
+ import IslandFlash from '../../../components/island/island-flash'
21
+ import Widget, { type WidgetLayout } from '../../../components/island/widget'
22
+ import { MINUTE, useEdgeClock } from '../../../lib/clock'
23
+
24
+ type ClipboardClipKind = 'text' | 'link' | 'image' | 'color' | 'file'
25
+
26
+ interface ClipboardClip {
27
+ /** What tells it apart. */
28
+ id: string
29
+ /** What was copied: it picks the glyph and how the clip previews. */
30
+ kind: ClipboardClipKind
31
+ /** The clip as text: the text, the URL, the color as copied (`#5B8DEF`), the file's or image's name. */
32
+ content: string
33
+ /** One line more: a link's page title, an image's size, a color in another notation, a file's size. */
34
+ detail?: string
35
+ /** A picture: an image's thumbnail or a link's favicon, as a URL or any element. */
36
+ preview?: string | ReactNode
37
+ /** A color clip's paint, any CSS color; defaults to `content`. */
38
+ color?: string
39
+ /** The app it was copied from. */
40
+ app?: string
41
+ /** When it was copied, in epoch ms. */
42
+ copiedAt: number
43
+ }
44
+
45
+ interface ClipboardHistoryProps {
46
+ /** The clips, in any order: pinned ones list first, the rest newest first. */
47
+ clips: ClipboardClip[]
48
+ /** The selected clip's id, shown as the hero (controlled). */
49
+ value?: string
50
+ /** The selected clip at first (uncontrolled). Defaults to the first in the list. */
51
+ defaultValue?: string
52
+ /** Called with a clip's id when it is picked, by a press or the arrow keys. */
53
+ onValueChange?: (id: string) => void
54
+ /** The pinned clips' ids (controlled). */
55
+ pinned?: string[]
56
+ /** The pinned clips at first (uncontrolled). Defaults to `[]`. */
57
+ defaultPinned?: string[]
58
+ /** Called with the new ids when a clip is pinned or unpinned. */
59
+ onPinnedChange?: (pinned: string[]) => void
60
+ /** The search (controlled): clips whose text, detail or app hold it stay. */
61
+ query?: string
62
+ /** The search at first (uncontrolled). Defaults to `''`. */
63
+ defaultQuery?: string
64
+ /** Called with the search as it is typed. */
65
+ onQueryChange?: (query: string) => void
66
+ /** Copying is not recorded (controlled). */
67
+ paused?: boolean
68
+ /** Copying is not recorded at first (uncontrolled). Defaults to `false`. */
69
+ defaultPaused?: boolean
70
+ /** Called with the new state when pause or resume is pressed. */
71
+ onPausedChange?: (paused: boolean) => void
72
+ /** The frontmost app, when it is one whose copies are never kept (a password manager): a chip says so. */
73
+ ignoredApp?: string
74
+ /** Called by Copy, a row's double-click or Enter, with the clip to put back on the clipboard. */
75
+ onCopy?: (clip: ClipboardClip) => void
76
+ /** Called by Delete with the clip to drop from the history. */
77
+ onDelete?: (clip: ClipboardClip) => void
78
+ /** The moment the times are read at, in epoch ms. Defaults to now, re-read on each minute. */
79
+ now?: number
80
+ /** `tall` is the open island's tall snap: the search across the top, every clip as a two-line row with its picture, and the selected clip in full beside them with its actions. Defaults to `'fit'`. */
81
+ layout?: WidgetLayout
82
+ /** Step on the size ladder. Omitted, it follows the surrounding SizeProvider. */
83
+ size?: SizeVariant
84
+ /** Classes for the root, which fills its container. */
85
+ className?: string
86
+ }
87
+
88
+ /** Rows the list shows before it says how many more. */
89
+ const ROWS = 3
90
+
91
+ const KIND_ICON: Record<ClipboardClipKind, IconComponent> = {
92
+ text: Type,
93
+ link: Link2,
94
+ image: Image,
95
+ color: Palette,
96
+ file: File,
97
+ }
98
+
99
+ const KIND_LABEL: Record<ClipboardClipKind, string> = {
100
+ text: 'Text',
101
+ link: 'Link',
102
+ image: 'Image',
103
+ color: 'Color',
104
+ file: 'File',
105
+ }
106
+
107
+ /** How long ago, as a phrase: `just now`, `2 min ago`, `3 h ago`, `2 d ago`. */
108
+ function ago(ms: number) {
109
+ const minutes = Math.floor(ms / MINUTE)
110
+ if (minutes < 1) return 'just now'
111
+ if (minutes < 60) return `${minutes} min ago`
112
+ if (minutes < 24 * 60) return `${Math.floor(minutes / 60)} h ago`
113
+ return `${Math.floor(minutes / (24 * 60))} d ago`
114
+ }
115
+
116
+ /** How long ago, as a row's end: `now`, `2m`, `3h`, `2d`. */
117
+ function short(ms: number) {
118
+ const minutes = Math.floor(ms / MINUTE)
119
+ if (minutes < 1) return 'now'
120
+ if (minutes < 60) return `${minutes}m`
121
+ if (minutes < 24 * 60) return `${Math.floor(minutes / 60)}h`
122
+ return `${Math.floor(minutes / (24 * 60))}d`
123
+ }
124
+
125
+ /** A link's host without `www.`, else the text as given. */
126
+ function domain(url: string) {
127
+ try {
128
+ return new URL(url).hostname.replace(/^www\./, '')
129
+ } catch {
130
+ return url
131
+ }
132
+ }
133
+
134
+ /** A link's path and query, the part the domain leaves out. */
135
+ function path(url: string) {
136
+ try {
137
+ const { pathname, search } = new URL(url)
138
+ return `${pathname}${search}`.replace(/^\/$/, '')
139
+ } catch {
140
+ return ''
141
+ }
142
+ }
143
+
144
+ const paint = (clip: ClipboardClip) => clip.color ?? clip.content
145
+
146
+ function Picture({ preview, className }: { preview: string | ReactNode; className?: string }) {
147
+ return (
148
+ <span className={cn('relative block shrink-0 overflow-hidden', className)}>
149
+ {typeof preview === 'string' ? (
150
+ <img alt="" src={preview} draggable={false} className="size-full object-cover" />
151
+ ) : (
152
+ preview
153
+ )}
154
+ <span
155
+ aria-hidden
156
+ className="pointer-events-none absolute inset-0 rounded-[inherit] ring-1 ring-border ring-inset"
157
+ />
158
+ </span>
159
+ )
160
+ }
161
+
162
+ /** The clip's mark at a row's start: a swatch, a thumbnail or favicon, else its kind's glyph. */
163
+ function Mark({ clip }: { clip: ClipboardClip }) {
164
+ if (clip.kind === 'color')
165
+ return <span aria-hidden className="size-3.5 shrink-0 rounded-full" style={{ backgroundColor: paint(clip) }} />
166
+ if (clip.preview != null) return <Picture preview={clip.preview} className="size-4 rounded-sm" />
167
+ const Icon = KIND_ICON[clip.kind]
168
+ return <Icon size={14} strokeWidth={1.5} className="shrink-0 text-muted-foreground" />
169
+ }
170
+
171
+ const hasMedia = (clip: ClipboardClip) => clip.kind === 'image' || clip.kind === 'color' || clip.kind === 'file'
172
+
173
+ /** The clip's picture beside the hero: an image's thumbnail, a color's swatch, a file's glyph on a tile. */
174
+ function Media({ clip }: { clip: ClipboardClip }) {
175
+ const level = useLift(1)
176
+ if (clip.kind === 'image' && clip.preview != null)
177
+ return <Picture preview={clip.preview} className="h-24 w-36 rounded-xl" />
178
+ if (clip.kind === 'color')
179
+ return (
180
+ <span
181
+ aria-hidden
182
+ className="size-24 shrink-0 rounded-xl ring-1 ring-border ring-inset"
183
+ style={{ backgroundColor: paint(clip) }}
184
+ />
185
+ )
186
+ if (clip.kind === 'file' || clip.kind === 'image')
187
+ return (
188
+ <span
189
+ className={cn('flex size-24 items-center justify-center rounded-xl text-muted-foreground', SURFACE_BG[level])}
190
+ >
191
+ {clip.kind === 'file' ? <File size={28} strokeWidth={1.25} /> : <Image size={28} strokeWidth={1.25} />}
192
+ </span>
193
+ )
194
+ return null
195
+ }
196
+
197
+ /** The clip as the hero: the text over two lines, a link's domain, a name. */
198
+ function Body({ clip }: { clip: ClipboardClip }) {
199
+ if (clip.kind === 'text')
200
+ return <p className="line-clamp-2 min-w-0 text-title weight-medium break-words text-foreground">{clip.content}</p>
201
+ if (clip.kind === 'link')
202
+ return (
203
+ <div className="flex min-w-0 flex-col gap-0.5">
204
+ <Widget.Title
205
+ leading={clip.preview != null && <Picture preview={clip.preview} className="size-4 rounded-sm" />}
206
+ >
207
+ {domain(clip.content)}
208
+ </Widget.Title>
209
+ {clip.detail && <Widget.Subtitle>{clip.detail}</Widget.Subtitle>}
210
+ </div>
211
+ )
212
+ return (
213
+ <div className="flex min-w-0 flex-col gap-0.5">
214
+ <Widget.Title className={cn(clip.kind === 'color' && 'font-mono')}>{clip.content}</Widget.Title>
215
+ {clip.detail && <Widget.Subtitle>{clip.detail}</Widget.Subtitle>}
216
+ </div>
217
+ )
218
+ }
219
+
220
+ /** What the line under the hero says: the text's length, a link's path, else nothing beyond the detail. */
221
+ function fact(clip: ClipboardClip) {
222
+ if (clip.kind === 'text') return `${clip.content.length} characters`
223
+ if (clip.kind === 'link') return path(clip.content)
224
+ return undefined
225
+ }
226
+
227
+ interface HeroProps {
228
+ clip: ClipboardClip
229
+ pinned: boolean
230
+ onPin: () => void
231
+ onCopy?: (clip: ClipboardClip) => void
232
+ onDelete?: (clip: ClipboardClip) => void
233
+ }
234
+
235
+ /** Pin, Delete and Copy for the selected clip. */
236
+ function Actions({ clip, pinned, onPin, onCopy, onDelete }: HeroProps) {
237
+ return (
238
+ <div className="-mr-1 flex shrink-0 items-center gap-0.5">
239
+ <Widget.Action icon={Pin} label={pinned ? 'Unpin' : 'Pin'} pressed={pinned} onClick={onPin} />
240
+ {onDelete && <Widget.Action icon={Trash2} label="Delete" onClick={() => onDelete(clip)} />}
241
+ <Button variant="primary" size="compact" leadingIcon={Copy} className="ml-1.5" onClick={() => onCopy?.(clip)}>
242
+ Copy
243
+ </Button>
244
+ </div>
245
+ )
246
+ }
247
+
248
+ function Hero(props: HeroProps) {
249
+ const { clip } = props
250
+ const line = fact(clip)
251
+ return (
252
+ <div className="flex min-w-0 flex-col gap-2">
253
+ <Body clip={clip} />
254
+ <div className="flex min-w-0 items-center justify-between gap-3">
255
+ <Widget.Meta>{line && <Widget.MetaItem icon={KIND_ICON[clip.kind]}>{line}</Widget.MetaItem>}</Widget.Meta>
256
+ <Actions {...props} />
257
+ </div>
258
+ </div>
259
+ )
260
+ }
261
+
262
+ interface ListProps {
263
+ order: ClipboardClip[]
264
+ selected: number
265
+ pinned: string[]
266
+ now: number
267
+ searching: boolean
268
+ onPick: (id: string) => void
269
+ onCopy?: (clip: ClipboardClip) => void
270
+ }
271
+
272
+ /** The clips around the selected one, pinned first, three at most, the selected one lit one surface up. */
273
+ function List({ order, selected, pinned, now, searching, onPick, onCopy }: ListProps) {
274
+ const level = useLift(1)
275
+ if (!order.length)
276
+ return <span className="flex h-7 items-center text-body text-muted-foreground">No clips match</span>
277
+
278
+ const start = Math.max(0, Math.min(selected - ROWS + 1, order.length - ROWS))
279
+ const shown = order.slice(start, start + ROWS)
280
+ const more = order.length - start - shown.length
281
+ const groups = [
282
+ { label: 'Pinned', clips: shown.filter(clip => pinned.includes(clip.id)) },
283
+ { label: searching ? 'Matches' : 'Recent', clips: shown.filter(clip => !pinned.includes(clip.id)) },
284
+ ].filter(group => group.clips.length)
285
+
286
+ return (
287
+ <FluidHover className="-mx-2 flex flex-col gap-0" role="listbox" aria-label="Clipboard history">
288
+ {groups.map((group, g) => (
289
+ <div key={group.label} role="presentation" className="flex min-w-0 flex-col">
290
+ <div className="flex h-6 items-center justify-between px-2 text-caption text-muted-foreground">
291
+ <span>{group.label}</span>
292
+ {g === groups.length - 1 && more > 0 && <span className="tabular-nums">{more} more</span>}
293
+ </div>
294
+ {group.clips.map(clip => {
295
+ const index = order.indexOf(clip)
296
+ const current = index === selected
297
+ return (
298
+ <FluidHover.Item
299
+ key={clip.id}
300
+ index={index - start}
301
+ role="option"
302
+ aria-selected={current}
303
+ tabIndex={-1}
304
+ className={cn('h-7 px-2', current && SURFACE_BG[level])}
305
+ onClick={() => onPick(clip.id)}
306
+ onDoubleClick={() => onCopy?.(clip)}
307
+ >
308
+ <Widget.Row
309
+ className="w-full"
310
+ trailing={
311
+ <>
312
+ {pinned.includes(clip.id) && <Pin size={11} strokeWidth={1.5} aria-label="Pinned" />}
313
+ <span className="w-6 text-right tabular-nums">{short(now - clip.copiedAt)}</span>
314
+ </>
315
+ }
316
+ >
317
+ <span className="flex min-w-0 items-center gap-2">
318
+ <Mark clip={clip} />
319
+ <span className="min-w-0 truncate">
320
+ {clip.kind === 'link' ? domain(clip.content) : clip.content}
321
+ </span>
322
+ </span>
323
+ </Widget.Row>
324
+ </FluidHover.Item>
325
+ )
326
+ })}
327
+ </div>
328
+ ))}
329
+ </FluidHover>
330
+ )
331
+ }
332
+
333
+ /** A tall row's picture: a swatch, a thumbnail or favicon, else its kind's glyph, on a tile one surface up. */
334
+ function Tile({ clip }: { clip: ClipboardClip }) {
335
+ const level = useLift(1)
336
+ if (clip.kind === 'color')
337
+ return (
338
+ <span
339
+ aria-hidden
340
+ className="size-8 shrink-0 rounded-lg ring-1 ring-border ring-inset"
341
+ style={{ backgroundColor: paint(clip) }}
342
+ />
343
+ )
344
+ if (clip.kind === 'image' && clip.preview != null)
345
+ return <Picture preview={clip.preview} className="size-8 rounded-lg" />
346
+ const Icon = KIND_ICON[clip.kind]
347
+ return (
348
+ <span
349
+ className={cn(
350
+ 'flex size-8 shrink-0 items-center justify-center rounded-lg text-muted-foreground',
351
+ SURFACE_BG[level],
352
+ )}
353
+ >
354
+ {clip.kind === 'link' && clip.preview != null ? (
355
+ <Picture preview={clip.preview} className="size-4 rounded-sm" />
356
+ ) : (
357
+ <Icon size={15} strokeWidth={1.5} />
358
+ )}
359
+ </span>
360
+ )
361
+ }
362
+
363
+ /** Every clip as a two-line row: its picture, its text, where and when; pinned first, the selected one lit one surface up. */
364
+ function SheetList({ order, selected, pinned, now, searching, onPick, onCopy }: ListProps) {
365
+ const level = useLift(1)
366
+ if (!order.length)
367
+ return <span className="flex h-12 items-center text-body text-muted-foreground">No clips match</span>
368
+
369
+ const groups = [
370
+ { label: 'Pinned', clips: order.filter(clip => pinned.includes(clip.id)) },
371
+ { label: searching ? 'Matches' : 'Recent', clips: order.filter(clip => !pinned.includes(clip.id)) },
372
+ ].filter(group => group.clips.length)
373
+
374
+ return (
375
+ <FluidHover className="-mx-2 flex flex-col gap-0" role="listbox" aria-label="Clipboard history">
376
+ {groups.map(group => (
377
+ <div key={group.label} role="presentation" className="flex min-w-0 flex-col">
378
+ <div className="flex h-7 items-end justify-between px-2 pb-1 text-caption text-muted-foreground">
379
+ <span>{group.label}</span>
380
+ <span className="tabular-nums">{group.clips.length}</span>
381
+ </div>
382
+ {group.clips.map(clip => {
383
+ const index = order.indexOf(clip)
384
+ const current = index === selected
385
+ return (
386
+ <FluidHover.Item
387
+ key={clip.id}
388
+ index={index}
389
+ role="option"
390
+ aria-selected={current}
391
+ tabIndex={-1}
392
+ className={cn('h-12 px-2', current && SURFACE_BG[level])}
393
+ onClick={() => onPick(clip.id)}
394
+ onDoubleClick={() => onCopy?.(clip)}
395
+ >
396
+ <span className="flex w-full min-w-0 items-center gap-3">
397
+ <Tile clip={clip} />
398
+ <span className="flex min-w-0 flex-1 flex-col">
399
+ <span className="truncate text-body text-foreground">
400
+ {clip.kind === 'link' ? (clip.detail ?? domain(clip.content)) : clip.content}
401
+ </span>
402
+ <span className="truncate text-caption text-muted-foreground">
403
+ {[
404
+ clip.kind === 'link' ? domain(clip.content) : (clip.app ?? KIND_LABEL[clip.kind]),
405
+ short(now - clip.copiedAt),
406
+ ].join(' · ')}
407
+ </span>
408
+ </span>
409
+ {pinned.includes(clip.id) && (
410
+ <Pin size={12} strokeWidth={1.5} aria-label="Pinned" className="shrink-0 text-muted-foreground" />
411
+ )}
412
+ </span>
413
+ </FluidHover.Item>
414
+ )
415
+ })}
416
+ </div>
417
+ ))}
418
+ </FluidHover>
419
+ )
420
+ }
421
+
422
+ /** The selected clip in full: the whole text, the link with its title and address, the image or the color large, the file on a tile. */
423
+ function Full({ clip }: { clip: ClipboardClip }) {
424
+ const level = useLift(1)
425
+ if (clip.kind === 'text')
426
+ return (
427
+ <p className="line-clamp-8 min-w-0 whitespace-pre-wrap text-title weight-medium break-words text-foreground">
428
+ {clip.content}
429
+ </p>
430
+ )
431
+ if (clip.kind === 'link')
432
+ return (
433
+ <div className="flex min-w-0 flex-col gap-1">
434
+ <Widget.Title
435
+ leading={clip.preview != null && <Picture preview={clip.preview} className="size-5 rounded-md" />}
436
+ >
437
+ {clip.detail ?? domain(clip.content)}
438
+ </Widget.Title>
439
+ <span className="min-w-0 text-body break-all text-muted-foreground">{clip.content}</span>
440
+ </div>
441
+ )
442
+
443
+ const picture =
444
+ clip.kind === 'color' ? (
445
+ <span
446
+ aria-hidden
447
+ className="block h-36 w-full rounded-2xl ring-1 ring-border ring-inset"
448
+ style={{ backgroundColor: paint(clip) }}
449
+ />
450
+ ) : clip.kind === 'image' && clip.preview != null ? (
451
+ <Picture preview={clip.preview} className="aspect-[16/10] w-full rounded-2xl" />
452
+ ) : (
453
+ <span
454
+ className={cn(
455
+ 'flex h-36 w-full items-center justify-center rounded-2xl text-muted-foreground',
456
+ SURFACE_BG[level],
457
+ )}
458
+ >
459
+ {clip.kind === 'file' ? <File size={40} strokeWidth={1.25} /> : <Image size={40} strokeWidth={1.25} />}
460
+ </span>
461
+ )
462
+ return (
463
+ <div className="flex min-w-0 flex-col gap-3">
464
+ {picture}
465
+ <div className="flex min-w-0 flex-col gap-0.5">
466
+ <Widget.Title className={cn(clip.kind === 'color' && 'font-mono')}>{clip.content}</Widget.Title>
467
+ {clip.detail && <Widget.Subtitle>{clip.detail}</Widget.Subtitle>}
468
+ </div>
469
+ </div>
470
+ )
471
+ }
472
+
473
+ /** The facts under the full clip: its kind, its length or a link's domain, the time it was copied. */
474
+ function Facts({ clip }: { clip: ClipboardClip }) {
475
+ const words = clip.content.trim().split(/\s+/).length
476
+ return (
477
+ <Widget.Meta>
478
+ <Widget.MetaItem icon={KIND_ICON[clip.kind]}>{KIND_LABEL[clip.kind]}</Widget.MetaItem>
479
+ {clip.kind === 'text' && (
480
+ <Widget.MetaItem>
481
+ {words} {words === 1 ? 'word' : 'words'} · {clip.content.length} characters
482
+ </Widget.MetaItem>
483
+ )}
484
+ {clip.kind === 'link' && <Widget.MetaItem>{domain(clip.content)}</Widget.MetaItem>}
485
+ <Widget.MetaItem>
486
+ Copied {new Date(clip.copiedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
487
+ </Widget.MetaItem>
488
+ </Widget.Meta>
489
+ )
490
+ }
491
+
492
+ /** The selected clip beside the list, held in view as the list scrolls: where it came from, the clip in full, its facts and actions. */
493
+ function Detail(props: HeroProps & { now: number }) {
494
+ const { clip, now } = props
495
+ return (
496
+ <div className="sticky top-0 flex min-w-0 flex-col gap-3">
497
+ <Widget.Header icon={KIND_ICON[clip.kind]}>
498
+ {[clip.app ?? KIND_LABEL[clip.kind], ago(now - clip.copiedAt)].join(' · ')}
499
+ </Widget.Header>
500
+ <Full clip={clip} />
501
+ <Facts clip={clip} />
502
+ <div className="flex justify-end pt-1">
503
+ <Actions {...props} />
504
+ </div>
505
+ </div>
506
+ )
507
+ }
508
+
509
+ /** The compact island's left wing: the clipboard glyph. */
510
+ function ClipboardHistoryLeading() {
511
+ return <ClipboardList size={16} strokeWidth={1.5} className="text-foreground" />
512
+ }
513
+
514
+ /** The compact island's right wing: how many clips came in since the island was last open. */
515
+ function ClipboardHistoryTrailing({ count }: { count: number }) {
516
+ return (
517
+ <span className="text-caption weight-semibold tabular-nums text-foreground">
518
+ {count}
519
+ <span className="sr-only"> new clips</span>
520
+ </span>
521
+ )
522
+ }
523
+
524
+ interface CopiedProps {
525
+ /** The clip that was copied. */
526
+ clip: ClipboardClip
527
+ /** Called by Pin; without it the button hides. */
528
+ onPin?: (clip: ClipboardClip) => void
529
+ }
530
+
531
+ /** The island's flash when something is copied: the clip's picture or glyph, `Copied`, its preview and Pin. */
532
+ function ClipboardHistoryCopied({ clip, onPin }: CopiedProps) {
533
+ const level = useLift(1)
534
+ const Icon = KIND_ICON[clip.kind]
535
+ const tile =
536
+ clip.kind === 'color' ? (
537
+ <span
538
+ aria-hidden
539
+ className="size-9 rounded-lg ring-1 ring-border ring-inset"
540
+ style={{ backgroundColor: paint(clip) }}
541
+ />
542
+ ) : clip.kind === 'image' && clip.preview != null ? (
543
+ <Picture preview={clip.preview} className="size-9 rounded-lg" />
544
+ ) : (
545
+ <span
546
+ className={cn('flex size-9 items-center justify-center rounded-lg text-muted-foreground', SURFACE_BG[level])}
547
+ >
548
+ <Icon size={16} strokeWidth={1.5} />
549
+ </span>
550
+ )
551
+ return (
552
+ <IslandFlash
553
+ icon={tile}
554
+ title={`Copied ${KIND_LABEL[clip.kind].toLowerCase()}`}
555
+ caption={clip.kind === 'link' ? domain(clip.content) : clip.content}
556
+ action={
557
+ onPin && (
558
+ <Button variant="secondary" size="compact" leadingIcon={Pin} onClick={() => onPin(clip)}>
559
+ Pin
560
+ </Button>
561
+ )
562
+ }
563
+ />
564
+ )
565
+ }
566
+
567
+ /**
568
+ * A notch app's clipboard history: the latest clip as the hero, the ones
569
+ * before it beside it, pinned ones on top.
570
+ *
571
+ * The hero is the selected clip, the newest until another is picked, shown
572
+ * as what it is: text over two lines, a link as its domain with the page's
573
+ * title, an image as its thumbnail, a color as a swatch with its value, a
574
+ * file as a tile with its name and size. The context line says where it was
575
+ * copied and how long ago; under the hero, its length or a link's path,
576
+ * Pin, Delete and Copy.
577
+ *
578
+ * Beside it, past a hairline, a search over the history and the clips
579
+ * themselves: pinned ones first, then the rest newest first, each a row of
580
+ * its swatch, thumbnail or glyph, its text and how long ago. Three show at
581
+ * a time, around the selected one, with a count of the rest. The arrow keys
582
+ * move the selection from anywhere in the widget (the search included),
583
+ * Enter copies it, and a double-click copies a row. The selection, the pins
584
+ * and the search each work both ways (`value`, `pinned`, `query`, with
585
+ * their `default…` and `on…Change`).
586
+ *
587
+ * Recording pauses from the context line (`paused`), and an app whose
588
+ * copies are never kept, such as a password manager, shows as a chip
589
+ * (`ignoredApp`). With no clips it says what will show up here, or that
590
+ * the history is paused.
591
+ *
592
+ * At the open island's tall snap (`layout="tall"`) it becomes a sheet: the
593
+ * search across the top with the pause and the chips beside it, then a
594
+ * master and detail split. On the left every clip, not three, as a row of
595
+ * two lines: its swatch, thumbnail or glyph on a tile, its text (a link's
596
+ * page title), and where and when it was copied, pinned ones first. On the
597
+ * right, past a hairline and held in view as the list scrolls, the
598
+ * selected clip in full: the whole text over up to eight lines, a link's
599
+ * title with its whole address, an image or a color large, a file on a
600
+ * tile; under it its kind, its length in words and characters, the time
601
+ * it was copied, and Pin, Delete and Copy. The keys work as in the fit
602
+ * layout.
603
+ *
604
+ * `ClipboardHistory.Leading` and `ClipboardHistory.Trailing` show the
605
+ * glyph and the count of new clips in the compact island's wings, and
606
+ * `ClipboardHistory.Copied` is the flash when something is copied.
607
+ *
608
+ * @example {@include ./examples.mdx}
609
+ */
610
+ const ClipboardHistory = Object.assign(
611
+ function ClipboardHistory({
612
+ clips,
613
+ value: valueProp,
614
+ defaultValue,
615
+ onValueChange,
616
+ pinned: pinnedProp,
617
+ defaultPinned = [],
618
+ onPinnedChange,
619
+ query: queryProp,
620
+ defaultQuery = '',
621
+ onQueryChange,
622
+ paused: pausedProp,
623
+ defaultPaused = false,
624
+ onPausedChange,
625
+ ignoredApp,
626
+ onCopy,
627
+ onDelete,
628
+ now: nowProp,
629
+ layout = 'fit',
630
+ size,
631
+ className,
632
+ }: ClipboardHistoryProps) {
633
+ const ticking = useEdgeClock(0, nowProp === undefined, MINUTE)
634
+ const now = nowProp ?? ticking
635
+ const [value, setValue] = useControllableState<string | undefined>(valueProp, defaultValue, onValueChange)
636
+ const [pinned, setPinned] = useControllableState(pinnedProp, defaultPinned, onPinnedChange)
637
+ const [query, setQuery] = useControllableState(queryProp, defaultQuery, onQueryChange)
638
+ const [paused, setPaused] = useControllableState(pausedProp, defaultPaused, onPausedChange)
639
+
640
+ const status = (
641
+ <>
642
+ {paused ? <Widget.Chip>Paused</Widget.Chip> : ignoredApp && <Widget.Chip>Ignoring {ignoredApp}</Widget.Chip>}
643
+ <Widget.Action
644
+ icon={paused ? Play : Pause}
645
+ label={paused ? 'Resume history' : 'Pause history'}
646
+ onClick={() => setPaused(!paused)}
647
+ />
648
+ </>
649
+ )
650
+
651
+ if (!clips.length)
652
+ return (
653
+ <Widget.Message
654
+ icon={paused ? Pause : ClipboardList}
655
+ title={paused ? 'Clipboard history is paused' : 'Copy something'}
656
+ description={
657
+ paused
658
+ ? 'Nothing you copy is kept until you resume.'
659
+ : 'Text, links, images and colors you copy show up here, newest first.'
660
+ }
661
+ actions={
662
+ paused && (
663
+ <Button variant="secondary" size="compact" leadingIcon={Play} onClick={() => setPaused(false)}>
664
+ Resume
665
+ </Button>
666
+ )
667
+ }
668
+ className={className}
669
+ />
670
+ )
671
+
672
+ const needle = query.trim().toLowerCase()
673
+ const matches = needle
674
+ ? clips.filter(clip => [clip.content, clip.detail, clip.app].some(s => s?.toLowerCase().includes(needle)))
675
+ : clips
676
+ const newest = [...matches].sort((a, b) => b.copiedAt - a.copiedAt)
677
+ const order = [
678
+ ...newest.filter(clip => pinned.includes(clip.id)),
679
+ ...newest.filter(clip => !pinned.includes(clip.id)),
680
+ ]
681
+ const found = order.findIndex(clip => clip.id === value)
682
+ const selected = found < 0 ? Math.max(0, order.indexOf(newest[0]!)) : found
683
+ const hero = order[selected] ?? clips[0]!
684
+ const heroPinned = pinned.includes(hero.id)
685
+ const togglePin = () => setPinned(heroPinned ? pinned.filter(id => id !== hero.id) : [...pinned, hero.id])
686
+
687
+ const onKeyDown = (event: KeyboardEvent) => {
688
+ const step = event.key === 'ArrowDown' ? 1 : event.key === 'ArrowUp' ? -1 : 0
689
+ if (step) {
690
+ event.preventDefault()
691
+ const next = order[Math.max(0, Math.min(order.length - 1, selected + step))]
692
+ if (next) setValue(next.id)
693
+ return
694
+ }
695
+ if (event.key === 'Enter' && order[selected]) {
696
+ event.preventDefault()
697
+ onCopy?.(order[selected])
698
+ }
699
+ }
700
+
701
+ const search = (
702
+ <Input
703
+ size="compact"
704
+ icon={Search}
705
+ placeholder="Search clips"
706
+ aria-label="Search clips"
707
+ value={query}
708
+ onValueChange={setQuery}
709
+ />
710
+ )
711
+ const listProps = { order, selected, pinned, now, searching: !!needle, onPick: setValue, onCopy }
712
+
713
+ if (layout === 'tall')
714
+ return (
715
+ // biome-ignore lint/a11y/noStaticElementInteractions: the keys bubble up from the search and the rows
716
+ <div className={cn('flex min-w-0 flex-col', className)} onKeyDown={onKeyDown}>
717
+ <Widget.Sheet size={size} className="gap-4">
718
+ <div className="flex min-w-0 items-center gap-3">
719
+ <div className="min-w-0 flex-1">{search}</div>
720
+ <span className="-mr-1 flex shrink-0 items-center gap-1.5">{status}</span>
721
+ </div>
722
+ <div className="flex min-w-0 items-stretch gap-5">
723
+ <div className="w-[46%] min-w-0 shrink-0">
724
+ <SheetList {...listProps} />
725
+ </div>
726
+ <div className="min-w-0 flex-1 border-l border-border pl-5">
727
+ <Detail
728
+ clip={hero}
729
+ pinned={heroPinned}
730
+ onPin={togglePin}
731
+ onCopy={onCopy}
732
+ onDelete={onDelete}
733
+ now={now}
734
+ />
735
+ </div>
736
+ </div>
737
+ </Widget.Sheet>
738
+ </div>
739
+ )
740
+
741
+ return (
742
+ // biome-ignore lint/a11y/noStaticElementInteractions: the keys bubble up from the search and the rows
743
+ <div className={cn('flex min-h-0 flex-col', className)} onKeyDown={onKeyDown}>
744
+ <Widget
745
+ size={size}
746
+ className="flex-1"
747
+ aside={
748
+ <div className="flex min-w-0 flex-col gap-1">
749
+ {search}
750
+ <List {...listProps} />
751
+ </div>
752
+ }
753
+ media={hasMedia(hero) && <Media clip={hero} />}
754
+ >
755
+ <Widget.Header icon={KIND_ICON[hero.kind]} trailing={status}>
756
+ {[hero.app ?? KIND_LABEL[hero.kind], ago(now - hero.copiedAt)].join(' · ')}
757
+ </Widget.Header>
758
+ <Hero clip={hero} pinned={heroPinned} onPin={togglePin} onCopy={onCopy} onDelete={onDelete} />
759
+ </Widget>
760
+ </div>
761
+ )
762
+ },
763
+ {
764
+ Leading: ClipboardHistoryLeading,
765
+ Trailing: ClipboardHistoryTrailing,
766
+ Copied: ClipboardHistoryCopied,
767
+ },
768
+ )
769
+
770
+ export default ClipboardHistory
771
+
772
+ export type { ClipboardClip, ClipboardClipKind, ClipboardHistoryProps }
773
+ export { ClipboardHistory, ClipboardHistoryCopied, ClipboardHistoryLeading, ClipboardHistoryTrailing }