@justanarthur/modo-ui-notch 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +75 -2
- package/blocks/activities/agenda/examples.mdx +74 -0
- package/blocks/activities/agenda/index.tsx +441 -0
- package/blocks/activities/clock/examples.mdx +73 -0
- package/blocks/activities/clock/index.tsx +619 -0
- package/blocks/activities/now-playing/examples.mdx +68 -0
- package/blocks/activities/now-playing/index.tsx +411 -0
- package/blocks/activities/weather/examples.mdx +115 -0
- package/blocks/activities/weather/index.tsx +634 -0
- package/blocks/app/expanded-island/examples.mdx +46 -0
- package/blocks/app/expanded-island/index.tsx +143 -0
- package/blocks/app/settings-window/examples.mdx +34 -0
- package/blocks/app/settings-window/index.tsx +375 -0
- package/blocks/system/clipboard/examples.mdx +83 -0
- package/blocks/system/clipboard/index.tsx +563 -0
- package/blocks/system/recent-files/examples.mdx +66 -0
- package/blocks/system/recent-files/index.tsx +542 -0
- package/blocks/system/system-stats/examples.mdx +52 -0
- package/blocks/system/system-stats/index.tsx +312 -0
- package/components/indicators/countdown/examples.mdx +25 -0
- package/components/indicators/countdown/index.tsx +83 -0
- package/components/indicators/equalizer/examples.mdx +20 -0
- package/components/indicators/equalizer/index.tsx +116 -0
- package/components/indicators/media-scrubber/examples.mdx +29 -0
- package/components/indicators/media-scrubber/index.tsx +122 -0
- package/components/island/island/examples.mdx +57 -0
- package/components/island/island/index.tsx +415 -0
- package/components/island/island-flash/examples.mdx +52 -0
- package/components/island/island-flash/index.tsx +79 -0
- package/components/island/island-tabs/examples.mdx +53 -0
- package/components/island/island-tabs/index.tsx +285 -0
- package/components/island/widget/examples.mdx +76 -0
- package/components/island/widget/index.tsx +431 -0
- package/dist/blocks/activities/agenda/index.d.ts +2 -0
- package/dist/blocks/activities/agenda/index.js +21 -0
- package/dist/blocks/activities/clock/index.d.ts +2 -0
- package/dist/blocks/activities/clock/index.js +25 -0
- package/dist/blocks/activities/now-playing/index.d.ts +3 -0
- package/dist/blocks/activities/now-playing/index.js +24 -0
- package/dist/blocks/activities/weather/index.d.ts +2 -0
- package/dist/blocks/activities/weather/index.js +21 -0
- package/dist/blocks/app/expanded-island/index.d.ts +3 -0
- package/dist/blocks/app/expanded-island/index.js +11 -0
- package/dist/blocks/app/settings-window/index.d.ts +2 -0
- package/dist/blocks/app/settings-window/index.js +7 -0
- package/dist/blocks/system/clipboard/index.d.ts +2 -0
- package/dist/blocks/system/clipboard/index.js +17 -0
- package/dist/blocks/system/recent-files/index.d.ts +2 -0
- package/dist/blocks/system/recent-files/index.js +19 -0
- package/dist/blocks/system/system-stats/index.d.ts +2 -0
- package/dist/blocks/system/system-stats/index.js +15 -0
- package/dist/components/indicators/countdown/index.d.ts +2 -0
- package/dist/components/indicators/countdown/index.js +8 -0
- package/dist/components/indicators/equalizer/index.d.ts +2 -0
- package/dist/components/indicators/equalizer/index.js +7 -0
- package/dist/components/indicators/media-scrubber/index.d.ts +2 -0
- package/dist/components/indicators/media-scrubber/index.js +8 -0
- package/dist/components/island/island/index.d.ts +3 -0
- package/dist/components/island/island/index.js +10 -0
- package/dist/components/island/island-flash/index.d.ts +2 -0
- package/dist/components/island/island-flash/index.js +7 -0
- package/dist/components/island/island-tabs/index.d.ts +2 -0
- package/dist/components/island/island-tabs/index.js +9 -0
- package/dist/components/island/widget/index.d.ts +2 -0
- package/dist/components/island/widget/index.js +30 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +195 -0
- package/dist/lib/artwork.d.ts +2 -0
- package/dist/lib/artwork.js +8 -0
- package/dist/lib/clock.d.ts +2 -0
- package/dist/lib/clock.js +14 -0
- package/dist/lib/geometry.d.ts +2 -0
- package/dist/lib/geometry.js +24 -0
- package/dist/lib/island-context.d.ts +3 -0
- package/dist/lib/island-context.js +8 -0
- package/dist/lib/motion.d.ts +21 -0
- package/dist/lib/motion.js +16 -0
- package/dist/shared/chunk-152gpyq3.d.ts +13 -0
- package/dist/shared/chunk-2818esrq.d.ts +140 -0
- package/dist/shared/chunk-2f7zxrbk.js +65 -0
- package/dist/shared/chunk-2m5dz8nf.d.ts +88 -0
- package/dist/shared/chunk-2s4q6mt0.js +27 -0
- package/dist/shared/chunk-3thgcfcq.d.ts +151 -0
- package/dist/shared/chunk-416tsgbc.d.ts +175 -0
- package/dist/shared/chunk-502rmtap.js +54 -0
- package/dist/shared/chunk-52gb3g6r.d.ts +12 -0
- package/dist/shared/chunk-5en5aaj1.d.ts +33 -0
- package/dist/shared/chunk-61t2dfte.js +63 -0
- package/dist/shared/chunk-7fvnrtz4.d.ts +105 -0
- package/dist/shared/chunk-81fpptwp.d.ts +75 -0
- package/dist/shared/chunk-9c7ewvkk.js +381 -0
- package/dist/shared/chunk-9m0xbg5v.js +112 -0
- package/dist/shared/chunk-9xtcv3sy.js +88 -0
- package/dist/shared/chunk-bvtyjcce.d.ts +123 -0
- package/dist/shared/chunk-cc9nwbtf.js +315 -0
- package/dist/shared/chunk-cfzmfnyh.d.ts +63 -0
- package/dist/shared/chunk-d5qm9cps.js +10 -0
- package/dist/shared/chunk-da177e8r.d.ts +114 -0
- package/dist/shared/chunk-fexwzycv.d.ts +36 -0
- package/dist/shared/chunk-gb56m10p.js +39 -0
- package/dist/shared/chunk-gejenfap.d.ts +25 -0
- package/dist/shared/chunk-hrpxbqmx.d.ts +28 -0
- package/dist/shared/chunk-j755a1a5.d.ts +41 -0
- package/dist/shared/chunk-j77cx8dp.js +498 -0
- package/dist/shared/chunk-mt0k6v8x.js +474 -0
- package/dist/shared/chunk-ndf79pv5.js +58 -0
- package/dist/shared/chunk-pfhy5e4q.d.ts +53 -0
- package/dist/shared/chunk-qdzemt2v.js +477 -0
- package/dist/shared/chunk-r471sknr.js +209 -0
- package/dist/shared/chunk-s2jeqqan.js +243 -0
- package/dist/shared/chunk-t0hcxh89.d.ts +124 -0
- package/dist/shared/chunk-w48eyvfr.d.ts +56 -0
- package/dist/shared/chunk-w5h6ay93.js +72 -0
- package/dist/shared/chunk-wkg17nxs.d.ts +101 -0
- package/dist/shared/chunk-x7f3g82r.js +285 -0
- package/dist/shared/chunk-xq5hc5gv.js +333 -0
- package/dist/shared/chunk-y0188bbn.js +331 -0
- package/dist/shared/chunk-ym0xbses.js +518 -0
- package/dist/styles.css +264 -0
- package/index.ts +22 -0
- package/lib/artwork.ts +112 -0
- package/lib/clock.ts +53 -0
- package/lib/geometry.ts +130 -0
- package/lib/island-context.tsx +24 -0
- package/lib/motion.ts +42 -0
- package/mock/activities.tsx +77 -0
- package/mock/artwork.tsx +37 -0
- package/mock/clipboard.tsx +79 -0
- package/mock/clock.tsx +77 -0
- package/mock/data.ts +139 -0
- package/mock/desktop.tsx +83 -0
- package/mock/files.tsx +70 -0
- package/mock/fit.ts +26 -0
- package/mock/island-content.tsx +142 -0
- package/mock/scene.tsx +52 -0
- package/mock/screen.tsx +76 -0
- package/mock/settings.tsx +489 -0
- package/mock/system.ts +46 -0
- package/mock/weather.tsx +105 -0
- package/package.json +122 -4
|
@@ -0,0 +1,563 @@
|
|
|
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 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
|
+
/** Step on the size ladder. Omitted, it follows the surrounding SizeProvider. */
|
|
81
|
+
size?: SizeVariant
|
|
82
|
+
/** Classes for the root, which fills its container. */
|
|
83
|
+
className?: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Rows the list shows before it says how many more. */
|
|
87
|
+
const ROWS = 3
|
|
88
|
+
|
|
89
|
+
const KIND_ICON: Record<ClipboardClipKind, IconComponent> = {
|
|
90
|
+
text: Type,
|
|
91
|
+
link: Link2,
|
|
92
|
+
image: Image,
|
|
93
|
+
color: Palette,
|
|
94
|
+
file: File,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const KIND_LABEL: Record<ClipboardClipKind, string> = {
|
|
98
|
+
text: 'Text',
|
|
99
|
+
link: 'Link',
|
|
100
|
+
image: 'Image',
|
|
101
|
+
color: 'Color',
|
|
102
|
+
file: 'File',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** How long ago, as a phrase: `just now`, `2 min ago`, `3 h ago`, `2 d ago`. */
|
|
106
|
+
function ago(ms: number) {
|
|
107
|
+
const minutes = Math.floor(ms / MINUTE)
|
|
108
|
+
if (minutes < 1) return 'just now'
|
|
109
|
+
if (minutes < 60) return `${minutes} min ago`
|
|
110
|
+
if (minutes < 24 * 60) return `${Math.floor(minutes / 60)} h ago`
|
|
111
|
+
return `${Math.floor(minutes / (24 * 60))} d ago`
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** How long ago, as a row's end: `now`, `2m`, `3h`, `2d`. */
|
|
115
|
+
function short(ms: number) {
|
|
116
|
+
const minutes = Math.floor(ms / MINUTE)
|
|
117
|
+
if (minutes < 1) return 'now'
|
|
118
|
+
if (minutes < 60) return `${minutes}m`
|
|
119
|
+
if (minutes < 24 * 60) return `${Math.floor(minutes / 60)}h`
|
|
120
|
+
return `${Math.floor(minutes / (24 * 60))}d`
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** A link's host without `www.`, else the text as given. */
|
|
124
|
+
function domain(url: string) {
|
|
125
|
+
try {
|
|
126
|
+
return new URL(url).hostname.replace(/^www\./, '')
|
|
127
|
+
} catch {
|
|
128
|
+
return url
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A link's path and query, the part the domain leaves out. */
|
|
133
|
+
function path(url: string) {
|
|
134
|
+
try {
|
|
135
|
+
const { pathname, search } = new URL(url)
|
|
136
|
+
return `${pathname}${search}`.replace(/^\/$/, '')
|
|
137
|
+
} catch {
|
|
138
|
+
return ''
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const paint = (clip: ClipboardClip) => clip.color ?? clip.content
|
|
143
|
+
|
|
144
|
+
function Picture({ preview, className }: { preview: string | ReactNode; className?: string }) {
|
|
145
|
+
return (
|
|
146
|
+
<span className={cn('relative block shrink-0 overflow-hidden', className)}>
|
|
147
|
+
{typeof preview === 'string' ? (
|
|
148
|
+
<img alt="" src={preview} draggable={false} className="size-full object-cover" />
|
|
149
|
+
) : (
|
|
150
|
+
preview
|
|
151
|
+
)}
|
|
152
|
+
<span
|
|
153
|
+
aria-hidden
|
|
154
|
+
className="pointer-events-none absolute inset-0 rounded-[inherit] ring-1 ring-border ring-inset"
|
|
155
|
+
/>
|
|
156
|
+
</span>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The clip's mark at a row's start: a swatch, a thumbnail or favicon, else its kind's glyph. */
|
|
161
|
+
function Mark({ clip }: { clip: ClipboardClip }) {
|
|
162
|
+
if (clip.kind === 'color')
|
|
163
|
+
return <span aria-hidden className="size-3.5 shrink-0 rounded-full" style={{ backgroundColor: paint(clip) }} />
|
|
164
|
+
if (clip.preview != null) return <Picture preview={clip.preview} className="size-4 rounded-sm" />
|
|
165
|
+
const Icon = KIND_ICON[clip.kind]
|
|
166
|
+
return <Icon size={14} strokeWidth={1.5} className="shrink-0 text-muted-foreground" />
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const hasMedia = (clip: ClipboardClip) => clip.kind === 'image' || clip.kind === 'color' || clip.kind === 'file'
|
|
170
|
+
|
|
171
|
+
/** The clip's picture beside the hero: an image's thumbnail, a color's swatch, a file's glyph on a tile. */
|
|
172
|
+
function Media({ clip }: { clip: ClipboardClip }) {
|
|
173
|
+
const level = useLift(1)
|
|
174
|
+
if (clip.kind === 'image' && clip.preview != null)
|
|
175
|
+
return <Picture preview={clip.preview} className="h-24 w-36 rounded-xl" />
|
|
176
|
+
if (clip.kind === 'color')
|
|
177
|
+
return (
|
|
178
|
+
<span
|
|
179
|
+
aria-hidden
|
|
180
|
+
className="size-24 shrink-0 rounded-xl ring-1 ring-border ring-inset"
|
|
181
|
+
style={{ backgroundColor: paint(clip) }}
|
|
182
|
+
/>
|
|
183
|
+
)
|
|
184
|
+
if (clip.kind === 'file' || clip.kind === 'image')
|
|
185
|
+
return (
|
|
186
|
+
<span
|
|
187
|
+
className={cn('flex size-24 items-center justify-center rounded-xl text-muted-foreground', SURFACE_BG[level])}
|
|
188
|
+
>
|
|
189
|
+
{clip.kind === 'file' ? <File size={28} strokeWidth={1.25} /> : <Image size={28} strokeWidth={1.25} />}
|
|
190
|
+
</span>
|
|
191
|
+
)
|
|
192
|
+
return null
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The clip as the hero: the text over two lines, a link's domain, a name. */
|
|
196
|
+
function Body({ clip }: { clip: ClipboardClip }) {
|
|
197
|
+
if (clip.kind === 'text')
|
|
198
|
+
return <p className="line-clamp-2 min-w-0 text-title weight-medium break-words text-foreground">{clip.content}</p>
|
|
199
|
+
if (clip.kind === 'link')
|
|
200
|
+
return (
|
|
201
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
202
|
+
<Widget.Title
|
|
203
|
+
leading={clip.preview != null && <Picture preview={clip.preview} className="size-4 rounded-sm" />}
|
|
204
|
+
>
|
|
205
|
+
{domain(clip.content)}
|
|
206
|
+
</Widget.Title>
|
|
207
|
+
{clip.detail && <Widget.Subtitle>{clip.detail}</Widget.Subtitle>}
|
|
208
|
+
</div>
|
|
209
|
+
)
|
|
210
|
+
return (
|
|
211
|
+
<div className="flex min-w-0 flex-col gap-0.5">
|
|
212
|
+
<Widget.Title className={cn(clip.kind === 'color' && 'font-mono')}>{clip.content}</Widget.Title>
|
|
213
|
+
{clip.detail && <Widget.Subtitle>{clip.detail}</Widget.Subtitle>}
|
|
214
|
+
</div>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** What the line under the hero says: the text's length, a link's path, else nothing beyond the detail. */
|
|
219
|
+
function fact(clip: ClipboardClip) {
|
|
220
|
+
if (clip.kind === 'text') return `${clip.content.length} characters`
|
|
221
|
+
if (clip.kind === 'link') return path(clip.content)
|
|
222
|
+
return undefined
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
interface HeroProps {
|
|
226
|
+
clip: ClipboardClip
|
|
227
|
+
pinned: boolean
|
|
228
|
+
onPin: () => void
|
|
229
|
+
onCopy?: (clip: ClipboardClip) => void
|
|
230
|
+
onDelete?: (clip: ClipboardClip) => void
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function Hero({ clip, pinned, onPin, onCopy, onDelete }: HeroProps) {
|
|
234
|
+
const line = fact(clip)
|
|
235
|
+
return (
|
|
236
|
+
<div className="flex min-w-0 flex-col gap-2">
|
|
237
|
+
<Body clip={clip} />
|
|
238
|
+
<div className="flex min-w-0 items-center justify-between gap-3">
|
|
239
|
+
<Widget.Meta>{line && <Widget.MetaItem icon={KIND_ICON[clip.kind]}>{line}</Widget.MetaItem>}</Widget.Meta>
|
|
240
|
+
<div className="-mr-1 flex shrink-0 items-center gap-0.5">
|
|
241
|
+
<Widget.Action icon={Pin} label={pinned ? 'Unpin' : 'Pin'} pressed={pinned} onClick={onPin} />
|
|
242
|
+
{onDelete && <Widget.Action icon={Trash2} label="Delete" onClick={() => onDelete(clip)} />}
|
|
243
|
+
<Button variant="primary" size="compact" leadingIcon={Copy} className="ml-1.5" onClick={() => onCopy?.(clip)}>
|
|
244
|
+
Copy
|
|
245
|
+
</Button>
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
</div>
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
interface ListProps {
|
|
253
|
+
order: ClipboardClip[]
|
|
254
|
+
selected: number
|
|
255
|
+
pinned: string[]
|
|
256
|
+
now: number
|
|
257
|
+
searching: boolean
|
|
258
|
+
onPick: (id: string) => void
|
|
259
|
+
onCopy?: (clip: ClipboardClip) => void
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The clips around the selected one, pinned first, three at most, the selected one lit one surface up. */
|
|
263
|
+
function List({ order, selected, pinned, now, searching, onPick, onCopy }: ListProps) {
|
|
264
|
+
const level = useLift(1)
|
|
265
|
+
if (!order.length)
|
|
266
|
+
return <span className="flex h-7 items-center text-body text-muted-foreground">No clips match</span>
|
|
267
|
+
|
|
268
|
+
const start = Math.max(0, Math.min(selected - ROWS + 1, order.length - ROWS))
|
|
269
|
+
const shown = order.slice(start, start + ROWS)
|
|
270
|
+
const more = order.length - start - shown.length
|
|
271
|
+
const groups = [
|
|
272
|
+
{ label: 'Pinned', clips: shown.filter(clip => pinned.includes(clip.id)) },
|
|
273
|
+
{ label: searching ? 'Matches' : 'Recent', clips: shown.filter(clip => !pinned.includes(clip.id)) },
|
|
274
|
+
].filter(group => group.clips.length)
|
|
275
|
+
|
|
276
|
+
return (
|
|
277
|
+
<FluidHover className="-mx-2 flex flex-col gap-0" role="listbox" aria-label="Clipboard history">
|
|
278
|
+
{groups.map((group, g) => (
|
|
279
|
+
<div key={group.label} role="presentation" className="flex min-w-0 flex-col">
|
|
280
|
+
<div className="flex h-6 items-center justify-between px-2 text-caption text-muted-foreground">
|
|
281
|
+
<span>{group.label}</span>
|
|
282
|
+
{g === groups.length - 1 && more > 0 && <span className="tabular-nums">{more} more</span>}
|
|
283
|
+
</div>
|
|
284
|
+
{group.clips.map(clip => {
|
|
285
|
+
const index = order.indexOf(clip)
|
|
286
|
+
const current = index === selected
|
|
287
|
+
return (
|
|
288
|
+
<FluidHover.Item
|
|
289
|
+
key={clip.id}
|
|
290
|
+
index={index - start}
|
|
291
|
+
role="option"
|
|
292
|
+
aria-selected={current}
|
|
293
|
+
tabIndex={-1}
|
|
294
|
+
className={cn('h-7 px-2', current && SURFACE_BG[level])}
|
|
295
|
+
onClick={() => onPick(clip.id)}
|
|
296
|
+
onDoubleClick={() => onCopy?.(clip)}
|
|
297
|
+
>
|
|
298
|
+
<Widget.Row
|
|
299
|
+
className="w-full"
|
|
300
|
+
trailing={
|
|
301
|
+
<>
|
|
302
|
+
{pinned.includes(clip.id) && <Pin size={11} strokeWidth={1.5} aria-label="Pinned" />}
|
|
303
|
+
<span className="w-6 text-right tabular-nums">{short(now - clip.copiedAt)}</span>
|
|
304
|
+
</>
|
|
305
|
+
}
|
|
306
|
+
>
|
|
307
|
+
<span className="flex min-w-0 items-center gap-2">
|
|
308
|
+
<Mark clip={clip} />
|
|
309
|
+
<span className="min-w-0 truncate">
|
|
310
|
+
{clip.kind === 'link' ? domain(clip.content) : clip.content}
|
|
311
|
+
</span>
|
|
312
|
+
</span>
|
|
313
|
+
</Widget.Row>
|
|
314
|
+
</FluidHover.Item>
|
|
315
|
+
)
|
|
316
|
+
})}
|
|
317
|
+
</div>
|
|
318
|
+
))}
|
|
319
|
+
</FluidHover>
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** The compact island's left wing: the clipboard glyph. */
|
|
324
|
+
function ClipboardHistoryLeading() {
|
|
325
|
+
return <ClipboardList size={16} strokeWidth={1.5} className="text-foreground" />
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** The compact island's right wing: how many clips came in since the island was last open. */
|
|
329
|
+
function ClipboardHistoryTrailing({ count }: { count: number }) {
|
|
330
|
+
return (
|
|
331
|
+
<span className="text-caption weight-semibold tabular-nums text-foreground">
|
|
332
|
+
{count}
|
|
333
|
+
<span className="sr-only"> new clips</span>
|
|
334
|
+
</span>
|
|
335
|
+
)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
interface CopiedProps {
|
|
339
|
+
/** The clip that was copied. */
|
|
340
|
+
clip: ClipboardClip
|
|
341
|
+
/** Called by Pin; without it the button hides. */
|
|
342
|
+
onPin?: (clip: ClipboardClip) => void
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** The island's flash when something is copied: the clip's picture or glyph, `Copied`, its preview and Pin. */
|
|
346
|
+
function ClipboardHistoryCopied({ clip, onPin }: CopiedProps) {
|
|
347
|
+
const level = useLift(1)
|
|
348
|
+
const Icon = KIND_ICON[clip.kind]
|
|
349
|
+
const tile =
|
|
350
|
+
clip.kind === 'color' ? (
|
|
351
|
+
<span
|
|
352
|
+
aria-hidden
|
|
353
|
+
className="size-9 rounded-lg ring-1 ring-border ring-inset"
|
|
354
|
+
style={{ backgroundColor: paint(clip) }}
|
|
355
|
+
/>
|
|
356
|
+
) : clip.kind === 'image' && clip.preview != null ? (
|
|
357
|
+
<Picture preview={clip.preview} className="size-9 rounded-lg" />
|
|
358
|
+
) : (
|
|
359
|
+
<span
|
|
360
|
+
className={cn('flex size-9 items-center justify-center rounded-lg text-muted-foreground', SURFACE_BG[level])}
|
|
361
|
+
>
|
|
362
|
+
<Icon size={16} strokeWidth={1.5} />
|
|
363
|
+
</span>
|
|
364
|
+
)
|
|
365
|
+
return (
|
|
366
|
+
<IslandFlash
|
|
367
|
+
icon={tile}
|
|
368
|
+
title={`Copied ${KIND_LABEL[clip.kind].toLowerCase()}`}
|
|
369
|
+
caption={clip.kind === 'link' ? domain(clip.content) : clip.content}
|
|
370
|
+
action={
|
|
371
|
+
onPin && (
|
|
372
|
+
<Button variant="secondary" size="compact" leadingIcon={Pin} onClick={() => onPin(clip)}>
|
|
373
|
+
Pin
|
|
374
|
+
</Button>
|
|
375
|
+
)
|
|
376
|
+
}
|
|
377
|
+
/>
|
|
378
|
+
)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* A notch app's clipboard history: the latest clip as the hero, the ones
|
|
383
|
+
* before it beside it, pinned ones on top.
|
|
384
|
+
*
|
|
385
|
+
* The hero is the selected clip, the newest until another is picked, shown
|
|
386
|
+
* as what it is: text over two lines, a link as its domain with the page's
|
|
387
|
+
* title, an image as its thumbnail, a color as a swatch with its value, a
|
|
388
|
+
* file as a tile with its name and size. The context line says where it was
|
|
389
|
+
* copied and how long ago; under the hero, its length or a link's path,
|
|
390
|
+
* Pin, Delete and Copy.
|
|
391
|
+
*
|
|
392
|
+
* Beside it, past a hairline, a search over the history and the clips
|
|
393
|
+
* themselves: pinned ones first, then the rest newest first, each a row of
|
|
394
|
+
* its swatch, thumbnail or glyph, its text and how long ago. Three show at
|
|
395
|
+
* a time, around the selected one, with a count of the rest. The arrow keys
|
|
396
|
+
* move the selection from anywhere in the widget (the search included),
|
|
397
|
+
* Enter copies it, and a double-click copies a row. The selection, the pins
|
|
398
|
+
* and the search each work both ways (`value`, `pinned`, `query`, with
|
|
399
|
+
* their `default…` and `on…Change`).
|
|
400
|
+
*
|
|
401
|
+
* Recording pauses from the context line (`paused`), and an app whose
|
|
402
|
+
* copies are never kept, such as a password manager, shows as a chip
|
|
403
|
+
* (`ignoredApp`). With no clips it says what will show up here, or that
|
|
404
|
+
* the history is paused.
|
|
405
|
+
*
|
|
406
|
+
* `ClipboardHistory.Leading` and `ClipboardHistory.Trailing` show the
|
|
407
|
+
* glyph and the count of new clips in the compact island's wings, and
|
|
408
|
+
* `ClipboardHistory.Copied` is the flash when something is copied.
|
|
409
|
+
*
|
|
410
|
+
* @example {@include ./examples.mdx}
|
|
411
|
+
*/
|
|
412
|
+
const ClipboardHistory = Object.assign(
|
|
413
|
+
function ClipboardHistory({
|
|
414
|
+
clips,
|
|
415
|
+
value: valueProp,
|
|
416
|
+
defaultValue,
|
|
417
|
+
onValueChange,
|
|
418
|
+
pinned: pinnedProp,
|
|
419
|
+
defaultPinned = [],
|
|
420
|
+
onPinnedChange,
|
|
421
|
+
query: queryProp,
|
|
422
|
+
defaultQuery = '',
|
|
423
|
+
onQueryChange,
|
|
424
|
+
paused: pausedProp,
|
|
425
|
+
defaultPaused = false,
|
|
426
|
+
onPausedChange,
|
|
427
|
+
ignoredApp,
|
|
428
|
+
onCopy,
|
|
429
|
+
onDelete,
|
|
430
|
+
now: nowProp,
|
|
431
|
+
size,
|
|
432
|
+
className,
|
|
433
|
+
}: ClipboardHistoryProps) {
|
|
434
|
+
const ticking = useEdgeClock(0, nowProp === undefined, MINUTE)
|
|
435
|
+
const now = nowProp ?? ticking
|
|
436
|
+
const [value, setValue] = useControllableState<string | undefined>(valueProp, defaultValue, onValueChange)
|
|
437
|
+
const [pinned, setPinned] = useControllableState(pinnedProp, defaultPinned, onPinnedChange)
|
|
438
|
+
const [query, setQuery] = useControllableState(queryProp, defaultQuery, onQueryChange)
|
|
439
|
+
const [paused, setPaused] = useControllableState(pausedProp, defaultPaused, onPausedChange)
|
|
440
|
+
|
|
441
|
+
const resume = (
|
|
442
|
+
<Widget.Action
|
|
443
|
+
icon={paused ? Play : Pause}
|
|
444
|
+
label={paused ? 'Resume history' : 'Pause history'}
|
|
445
|
+
onClick={() => setPaused(!paused)}
|
|
446
|
+
/>
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
if (!clips.length)
|
|
450
|
+
return (
|
|
451
|
+
<Widget.Message
|
|
452
|
+
icon={paused ? Pause : ClipboardList}
|
|
453
|
+
title={paused ? 'Clipboard history is paused' : 'Copy something'}
|
|
454
|
+
description={
|
|
455
|
+
paused
|
|
456
|
+
? 'Nothing you copy is kept until you resume.'
|
|
457
|
+
: 'Text, links, images and colors you copy show up here, newest first.'
|
|
458
|
+
}
|
|
459
|
+
actions={
|
|
460
|
+
paused && (
|
|
461
|
+
<Button variant="secondary" size="compact" leadingIcon={Play} onClick={() => setPaused(false)}>
|
|
462
|
+
Resume
|
|
463
|
+
</Button>
|
|
464
|
+
)
|
|
465
|
+
}
|
|
466
|
+
className={className}
|
|
467
|
+
/>
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
const needle = query.trim().toLowerCase()
|
|
471
|
+
const matches = needle
|
|
472
|
+
? clips.filter(clip => [clip.content, clip.detail, clip.app].some(s => s?.toLowerCase().includes(needle)))
|
|
473
|
+
: clips
|
|
474
|
+
const newest = [...matches].sort((a, b) => b.copiedAt - a.copiedAt)
|
|
475
|
+
const order = [
|
|
476
|
+
...newest.filter(clip => pinned.includes(clip.id)),
|
|
477
|
+
...newest.filter(clip => !pinned.includes(clip.id)),
|
|
478
|
+
]
|
|
479
|
+
const found = order.findIndex(clip => clip.id === value)
|
|
480
|
+
const selected = found < 0 ? Math.max(0, order.indexOf(newest[0]!)) : found
|
|
481
|
+
const hero = order[selected] ?? clips[0]!
|
|
482
|
+
const heroPinned = pinned.includes(hero.id)
|
|
483
|
+
|
|
484
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
485
|
+
const step = event.key === 'ArrowDown' ? 1 : event.key === 'ArrowUp' ? -1 : 0
|
|
486
|
+
if (step) {
|
|
487
|
+
event.preventDefault()
|
|
488
|
+
const next = order[Math.max(0, Math.min(order.length - 1, selected + step))]
|
|
489
|
+
if (next) setValue(next.id)
|
|
490
|
+
return
|
|
491
|
+
}
|
|
492
|
+
if (event.key === 'Enter' && order[selected]) {
|
|
493
|
+
event.preventDefault()
|
|
494
|
+
onCopy?.(order[selected])
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return (
|
|
499
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: the keys bubble up from the search and the rows
|
|
500
|
+
<div className={cn('flex min-h-0 flex-col', className)} onKeyDown={onKeyDown}>
|
|
501
|
+
<Widget
|
|
502
|
+
size={size}
|
|
503
|
+
className="flex-1"
|
|
504
|
+
aside={
|
|
505
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
506
|
+
<Input
|
|
507
|
+
size="compact"
|
|
508
|
+
icon={Search}
|
|
509
|
+
placeholder="Search clips"
|
|
510
|
+
aria-label="Search clips"
|
|
511
|
+
value={query}
|
|
512
|
+
onValueChange={setQuery}
|
|
513
|
+
/>
|
|
514
|
+
<List
|
|
515
|
+
order={order}
|
|
516
|
+
selected={selected}
|
|
517
|
+
pinned={pinned}
|
|
518
|
+
now={now}
|
|
519
|
+
searching={!!needle}
|
|
520
|
+
onPick={setValue}
|
|
521
|
+
onCopy={onCopy}
|
|
522
|
+
/>
|
|
523
|
+
</div>
|
|
524
|
+
}
|
|
525
|
+
media={hasMedia(hero) && <Media clip={hero} />}
|
|
526
|
+
>
|
|
527
|
+
<Widget.Header
|
|
528
|
+
icon={KIND_ICON[hero.kind]}
|
|
529
|
+
trailing={
|
|
530
|
+
<>
|
|
531
|
+
{paused ? (
|
|
532
|
+
<Widget.Chip>Paused</Widget.Chip>
|
|
533
|
+
) : (
|
|
534
|
+
ignoredApp && <Widget.Chip>Ignoring {ignoredApp}</Widget.Chip>
|
|
535
|
+
)}
|
|
536
|
+
{resume}
|
|
537
|
+
</>
|
|
538
|
+
}
|
|
539
|
+
>
|
|
540
|
+
{[hero.app ?? KIND_LABEL[hero.kind], ago(now - hero.copiedAt)].join(' · ')}
|
|
541
|
+
</Widget.Header>
|
|
542
|
+
<Hero
|
|
543
|
+
clip={hero}
|
|
544
|
+
pinned={heroPinned}
|
|
545
|
+
onPin={() => setPinned(heroPinned ? pinned.filter(id => id !== hero.id) : [...pinned, hero.id])}
|
|
546
|
+
onCopy={onCopy}
|
|
547
|
+
onDelete={onDelete}
|
|
548
|
+
/>
|
|
549
|
+
</Widget>
|
|
550
|
+
</div>
|
|
551
|
+
)
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
Leading: ClipboardHistoryLeading,
|
|
555
|
+
Trailing: ClipboardHistoryTrailing,
|
|
556
|
+
Copied: ClipboardHistoryCopied,
|
|
557
|
+
},
|
|
558
|
+
)
|
|
559
|
+
|
|
560
|
+
export default ClipboardHistory
|
|
561
|
+
|
|
562
|
+
export type { ClipboardClip, ClipboardClipKind, ClipboardHistoryProps }
|
|
563
|
+
export { ClipboardHistory, ClipboardHistoryCopied, ClipboardHistoryLeading, ClipboardHistoryTrailing }
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import RecentFiles from './index'
|
|
2
|
+
import { FlashIsland, PLAYING, WidgetIsland, WingsIsland } from '../../../mock/island-content'
|
|
3
|
+
import { DOWNLOAD, DOWNLOADS, FILES_NOW, RECENT_FILES, SCREENSHOTS } from '../../../mock/files'
|
|
4
|
+
import NowPlaying from '../../activities/now-playing'
|
|
5
|
+
|
|
6
|
+
# Downloads
|
|
7
|
+
|
|
8
|
+
The newest download as the hero, ready to open, reveal, copy or drag out; the ones before it as rows beside it.
|
|
9
|
+
|
|
10
|
+
<WidgetIsland tab="files">
|
|
11
|
+
<RecentFiles files={RECENT_FILES} now={FILES_NOW} onReveal={() => {}} onCopy={() => {}} onDelete={() => {}} onClear={() => {}} onDragStart={() => {}} />
|
|
12
|
+
</WidgetIsland>
|
|
13
|
+
|
|
14
|
+
# Screenshots
|
|
15
|
+
|
|
16
|
+
On Screenshots the ones before the newest are image tiles: a screenshot is found by its look.
|
|
17
|
+
|
|
18
|
+
<WidgetIsland tab="files">
|
|
19
|
+
<RecentFiles files={RECENT_FILES} defaultValue="screenshots" now={FILES_NOW} onReveal={() => {}} onCopy={() => {}} onDelete={() => {}} onClear={() => {}} />
|
|
20
|
+
</WidgetIsland>
|
|
21
|
+
|
|
22
|
+
# Downloading
|
|
23
|
+
|
|
24
|
+
A `download` under way takes the hero: its progress, how much is in, the speed and the time left.
|
|
25
|
+
|
|
26
|
+
<WidgetIsland tab="files">
|
|
27
|
+
<RecentFiles files={RECENT_FILES} download={DOWNLOAD} now={FILES_NOW} onCancelDownload={() => {}} />
|
|
28
|
+
</WidgetIsland>
|
|
29
|
+
|
|
30
|
+
# Nothing yet
|
|
31
|
+
|
|
32
|
+
Each folder says when it is empty; the switch stays.
|
|
33
|
+
|
|
34
|
+
<WidgetIsland tab="files">
|
|
35
|
+
<RecentFiles files={SCREENSHOTS} />
|
|
36
|
+
</WidgetIsland>
|
|
37
|
+
|
|
38
|
+
# Compact
|
|
39
|
+
|
|
40
|
+
`RecentFiles.Leading` and `RecentFiles.Trailing`: the download's progress in the wings.
|
|
41
|
+
|
|
42
|
+
<WingsIsland leading={<RecentFiles.Leading />} trailing={<RecentFiles.Trailing download={DOWNLOAD} />} />
|
|
43
|
+
|
|
44
|
+
# Minimal
|
|
45
|
+
|
|
46
|
+
`RecentFiles.Minimal`, the progress as a ring in the split island's bubble, music in the wings.
|
|
47
|
+
|
|
48
|
+
<WingsIsland
|
|
49
|
+
leading={<NowPlaying.Leading track={PLAYING} />}
|
|
50
|
+
trailing={<NowPlaying.Trailing track={PLAYING} />}
|
|
51
|
+
minimal={<RecentFiles.Minimal download={DOWNLOAD} />}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
# Downloaded
|
|
55
|
+
|
|
56
|
+
`RecentFiles.Saved`, the flash when a download lands, with Open.
|
|
57
|
+
|
|
58
|
+
<FlashIsland>
|
|
59
|
+
<RecentFiles.Saved file={DOWNLOADS[0]} onOpen={() => {}} />
|
|
60
|
+
</FlashIsland>
|
|
61
|
+
|
|
62
|
+
# Screenshot saved
|
|
63
|
+
|
|
64
|
+
<FlashIsland>
|
|
65
|
+
<RecentFiles.Saved file={SCREENSHOTS[0]} onOpen={() => {}} />
|
|
66
|
+
</FlashIsland>
|