@opencode/ui 2.2.6 → 2.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/dist/components/diagram-preview.d.ts +9 -0
- package/dist/components/image-zoom.d.ts +4 -0
- package/dist/components/provider-icon.d.ts +2 -0
- package/dist/data-display/badge/badge.d.ts +1 -1
- package/dist/data-display/diff-changes/diff-changes.d.ts +2 -0
- package/dist/data-display/project-avatar/project-avatar.d.ts +2 -0
- package/dist/feedback/toast/toast.d.ts +2 -0
- package/dist/forms/redirect-paste/redirect-paste.d.ts +23 -0
- package/dist/i18n/am.d.ts +1 -0
- package/dist/i18n/ar.d.ts +1 -0
- package/dist/i18n/az.d.ts +1 -0
- package/dist/i18n/bg.d.ts +1 -0
- package/dist/i18n/bn.d.ts +1 -0
- package/dist/i18n/br.d.ts +1 -0
- package/dist/i18n/bs.d.ts +1 -0
- package/dist/i18n/ca.d.ts +1 -0
- package/dist/i18n/cs.d.ts +1 -0
- package/dist/i18n/da.d.ts +1 -0
- package/dist/i18n/de.d.ts +1 -0
- package/dist/i18n/dv.d.ts +1 -0
- package/dist/i18n/dz.d.ts +1 -0
- package/dist/i18n/el.d.ts +1 -0
- package/dist/i18n/en.d.ts +52 -0
- package/dist/i18n/es.d.ts +1 -0
- package/dist/i18n/et.d.ts +1 -0
- package/dist/i18n/fa.d.ts +1 -0
- package/dist/i18n/fi.d.ts +1 -0
- package/dist/i18n/fo.d.ts +1 -0
- package/dist/i18n/fr.d.ts +1 -0
- package/dist/i18n/he.d.ts +1 -0
- package/dist/i18n/hi.d.ts +1 -0
- package/dist/i18n/hr.d.ts +1 -0
- package/dist/i18n/hu.d.ts +1 -0
- package/dist/i18n/hy.d.ts +1 -0
- package/dist/i18n/id.d.ts +1 -0
- package/dist/i18n/is.d.ts +1 -0
- package/dist/i18n/it.d.ts +1 -0
- package/dist/i18n/ja.d.ts +1 -0
- package/dist/i18n/ka.d.ts +1 -0
- package/dist/i18n/km.d.ts +1 -0
- package/dist/i18n/ko.d.ts +1 -0
- package/dist/i18n/lo.d.ts +1 -0
- package/dist/i18n/lt.d.ts +1 -0
- package/dist/i18n/lv.d.ts +1 -0
- package/dist/i18n/mk.d.ts +1 -0
- package/dist/i18n/mn.d.ts +1 -0
- package/dist/i18n/ms.d.ts +1 -0
- package/dist/i18n/my.d.ts +1 -0
- package/dist/i18n/ne.d.ts +1 -0
- package/dist/i18n/nl.d.ts +1 -0
- package/dist/i18n/pa.d.ts +1 -0
- package/dist/i18n/pl.d.ts +1 -0
- package/dist/i18n/ro.d.ts +1 -0
- package/dist/i18n/ru.d.ts +1 -0
- package/dist/i18n/si.d.ts +1 -0
- package/dist/i18n/sk.d.ts +1 -0
- package/dist/i18n/sl.d.ts +1 -0
- package/dist/i18n/sq.d.ts +1 -0
- package/dist/i18n/sr.d.ts +1 -0
- package/dist/i18n/sv.d.ts +1 -0
- package/dist/i18n/tg.d.ts +1 -0
- package/dist/i18n/th.d.ts +1 -0
- package/dist/i18n/tk.d.ts +1 -0
- package/dist/i18n/tr.d.ts +1 -0
- package/dist/i18n/uk.d.ts +1 -0
- package/dist/i18n/ur.d.ts +1 -0
- package/dist/i18n/uz.d.ts +1 -0
- package/dist/i18n/vi.d.ts +1 -0
- package/dist/i18n/zh.d.ts +1 -0
- package/dist/i18n/zht.d.ts +1 -0
- package/dist/icons/catalog.d.ts +4 -0
- package/package.json +124 -119
- package/src/components/diagram-preview.css +95 -0
- package/src/components/diagram-preview.tsx +332 -0
- package/src/components/image-preview.tsx +6 -20
- package/src/components/image-zoom.ts +18 -0
- package/src/components/provider-icon.tsx +7 -2
- package/src/data-display/badge/badge.css +6 -0
- package/src/data-display/badge/badge.tsx +1 -1
- package/src/data-display/diff-changes/diff-changes.tsx +10 -2
- package/src/data-display/project-avatar/project-avatar.css +13 -0
- package/src/data-display/project-avatar/project-avatar.tsx +14 -1
- package/src/feedback/toast/toast.tsx +11 -1
- package/src/forms/inline-input/inline-input.css +0 -1
- package/src/forms/redirect-paste/redirect-paste.tsx +75 -0
- package/src/forms/search-list/search-list.tsx +14 -6
- package/src/forms/select/select.tsx +7 -1
- package/src/i18n/am.ts +1 -0
- package/src/i18n/ar.ts +1 -0
- package/src/i18n/az.ts +1 -0
- package/src/i18n/bg.ts +1 -0
- package/src/i18n/bn.ts +1 -0
- package/src/i18n/br.ts +1 -0
- package/src/i18n/bs.ts +1 -0
- package/src/i18n/ca.ts +1 -0
- package/src/i18n/cs.ts +1 -0
- package/src/i18n/da.ts +1 -0
- package/src/i18n/de.ts +1 -0
- package/src/i18n/dv.ts +1 -0
- package/src/i18n/dz.ts +1 -0
- package/src/i18n/el.ts +1 -0
- package/src/i18n/en.ts +53 -0
- package/src/i18n/es.ts +1 -0
- package/src/i18n/et.ts +1 -0
- package/src/i18n/fa.ts +1 -0
- package/src/i18n/fi.ts +1 -0
- package/src/i18n/fo.ts +1 -0
- package/src/i18n/fr.ts +1 -0
- package/src/i18n/he.ts +1 -0
- package/src/i18n/hi.ts +1 -0
- package/src/i18n/hr.ts +1 -0
- package/src/i18n/hu.ts +1 -0
- package/src/i18n/hy.ts +1 -0
- package/src/i18n/id.ts +1 -0
- package/src/i18n/is.ts +1 -0
- package/src/i18n/it.ts +1 -0
- package/src/i18n/ja.ts +1 -0
- package/src/i18n/ka.ts +1 -0
- package/src/i18n/km.ts +1 -0
- package/src/i18n/ko.ts +1 -0
- package/src/i18n/lo.ts +1 -0
- package/src/i18n/lt.ts +1 -0
- package/src/i18n/lv.ts +1 -0
- package/src/i18n/mk.ts +1 -0
- package/src/i18n/mn.ts +1 -0
- package/src/i18n/ms.ts +1 -0
- package/src/i18n/my.ts +1 -0
- package/src/i18n/ne.ts +1 -0
- package/src/i18n/nl.ts +1 -0
- package/src/i18n/no.ts +1 -0
- package/src/i18n/pa.ts +1 -0
- package/src/i18n/pl.ts +1 -0
- package/src/i18n/ro.ts +1 -0
- package/src/i18n/ru.ts +1 -0
- package/src/i18n/si.ts +1 -0
- package/src/i18n/sk.ts +1 -0
- package/src/i18n/sl.ts +1 -0
- package/src/i18n/sq.ts +1 -0
- package/src/i18n/sr.ts +1 -0
- package/src/i18n/sv.ts +1 -0
- package/src/i18n/tg.ts +1 -0
- package/src/i18n/th.ts +1 -0
- package/src/i18n/tk.ts +1 -0
- package/src/i18n/tr.ts +1 -0
- package/src/i18n/uk.ts +4 -3
- package/src/i18n/ur.ts +1 -0
- package/src/i18n/uz.ts +1 -0
- package/src/i18n/vi.ts +1 -0
- package/src/i18n/zh.ts +1 -0
- package/src/i18n/zht.ts +1 -0
- package/src/icons/catalog.ts +4 -0
- package/src/icons/icon/additional-icons.ts +4 -2
- package/src/icons/new-icons.ts +0 -1
- package/src/navigation/menu/menu.tsx +3 -0
- package/src/overlays/tooltip/tooltip.tsx +2 -0
- package/src/styles/index.css +1 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { Dialog as Kobalte, useDialogContext } from "@kobalte/core/dialog"
|
|
2
|
+
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
3
|
+
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
4
|
+
import { createMemo, createSignal, onCleanup } from "solid-js"
|
|
5
|
+
import { useI18n } from "../context/i18n"
|
|
6
|
+
import { Button } from "@opencode/ui/button"
|
|
7
|
+
import { Icon } from "@opencode/ui/icon"
|
|
8
|
+
import { IconButton } from "@opencode/ui/icon-button"
|
|
9
|
+
import { frameLoop, prefersReducedMotion, Spring } from "../motion"
|
|
10
|
+
import { FLIGHT_SPRING } from "./image-flight"
|
|
11
|
+
import {
|
|
12
|
+
clampView,
|
|
13
|
+
detailScale,
|
|
14
|
+
FIT_VIEW,
|
|
15
|
+
panBy,
|
|
16
|
+
wheelPixels,
|
|
17
|
+
wheelZoomFactor,
|
|
18
|
+
zoomAt,
|
|
19
|
+
zoomShortcut,
|
|
20
|
+
type ZoomView,
|
|
21
|
+
} from "./image-zoom"
|
|
22
|
+
|
|
23
|
+
export interface DiagramPreviewProps {
|
|
24
|
+
/** The diagram to show, which the preview takes over: pass a copy of one still on the page. */
|
|
25
|
+
svg: SVGSVGElement
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const STEP = Math.SQRT2
|
|
29
|
+
|
|
30
|
+
// How far one arrow key press pans, as a share of the window; Shift pans a whole window.
|
|
31
|
+
const ARROW_PAN = 0.15
|
|
32
|
+
|
|
33
|
+
// How far a diagram zooms in past the size it was drawn at: its labels are crisp at any size, so a few times is enough
|
|
34
|
+
// to read the smallest.
|
|
35
|
+
const MAX_ZOOM = 4
|
|
36
|
+
|
|
37
|
+
// The canvas around the diagram at its natural size, in pixels.
|
|
38
|
+
const PADDING = 24
|
|
39
|
+
|
|
40
|
+
const CENTER = { x: 0, y: 0 }
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A diagram maximized over the page, zoomed and panned like an image preview. The diagram stays a live SVG, so it is
|
|
44
|
+
* redrawn sharp at every zoom and keeps the page's fonts and theme.
|
|
45
|
+
*/
|
|
46
|
+
export function DiagramPreview(props: DiagramPreviewProps) {
|
|
47
|
+
const i18n = useI18n()
|
|
48
|
+
const dialog = useDialogContext()
|
|
49
|
+
let viewport!: HTMLDivElement
|
|
50
|
+
let canvas!: HTMLDivElement
|
|
51
|
+
let close: HTMLButtonElement | undefined
|
|
52
|
+
const [view, setView] = createSignal(FIT_VIEW)
|
|
53
|
+
const [goal, setGoal] = createSignal(FIT_VIEW)
|
|
54
|
+
const [fitRatio, setFitRatio] = createSignal(1)
|
|
55
|
+
const [drag, setDrag] = createSignal<{ id: number; x: number; y: number }>()
|
|
56
|
+
// Whether the press that ends in a click began on the backdrop around the diagram, and whether a pan moved since.
|
|
57
|
+
let backdrop = false
|
|
58
|
+
let panned = false
|
|
59
|
+
const glide = [1, 0, 0].map((value) => Spring.fromDuration(value, FLIGHT_SPRING))
|
|
60
|
+
let gliding: (() => void) | undefined
|
|
61
|
+
|
|
62
|
+
const percent = createMemo(() => new Intl.NumberFormat(i18n.locale(), { style: "percent", maximumFractionDigits: 0 }))
|
|
63
|
+
|
|
64
|
+
const bounds = () => ({
|
|
65
|
+
width: canvas.offsetWidth,
|
|
66
|
+
height: canvas.offsetHeight,
|
|
67
|
+
viewportWidth: viewport.clientWidth,
|
|
68
|
+
viewportHeight: viewport.clientHeight,
|
|
69
|
+
maxScale: Math.max(1, MAX_ZOOM / fitRatio()),
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const show = (next: ZoomView) => {
|
|
73
|
+
setView(next)
|
|
74
|
+
canvas.style.transform = `translate(${next.x}px, ${next.y}px) scale(${next.scale})`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const settle = () => {
|
|
78
|
+
gliding?.()
|
|
79
|
+
gliding = undefined
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
onCleanup(settle)
|
|
83
|
+
|
|
84
|
+
// Pinch, wheel and drag follow the hand directly and take over from an eased zoom mid-flight.
|
|
85
|
+
const follow = (next: ZoomView) => {
|
|
86
|
+
settle()
|
|
87
|
+
setGoal(next)
|
|
88
|
+
show(next)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const ease = (target: ZoomView) => {
|
|
92
|
+
setGoal(target)
|
|
93
|
+
|
|
94
|
+
if (prefersReducedMotion()) return follow(target)
|
|
95
|
+
|
|
96
|
+
if (!gliding) [view().scale, view().x, view().y].forEach((value, index) => glide[index].snap(value))
|
|
97
|
+
;[target.scale, target.x, target.y].forEach((value, index) => glide[index].set(value))
|
|
98
|
+
gliding ??= frameLoop.add((dt) => {
|
|
99
|
+
const [scale, x, y] = glide.map((spring) => spring.step(dt))
|
|
100
|
+
show({ scale, x, y })
|
|
101
|
+
|
|
102
|
+
if (!glide.every((spring) => spring.resting)) return true
|
|
103
|
+
gliding = undefined
|
|
104
|
+
|
|
105
|
+
return false
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const step = (factor: number) => ease(zoomAt(goal(), goal().scale * factor, CENTER, bounds()))
|
|
110
|
+
|
|
111
|
+
// Fits the diagram to the window without enlarging it past the size it was drawn at, keeping the zoom it has. The
|
|
112
|
+
// padding around it shrinks with it.
|
|
113
|
+
const measure = () => {
|
|
114
|
+
const width = props.svg.width.baseVal.value
|
|
115
|
+
const height = props.svg.height.baseVal.value
|
|
116
|
+
|
|
117
|
+
// The window's own padding is where a zoomed diagram fades out, so a fitted one stays inside it.
|
|
118
|
+
const inset = parseFloat(getComputedStyle(viewport).paddingLeft) * 2
|
|
119
|
+
const room = { width: viewport.clientWidth - inset, height: viewport.clientHeight - inset }
|
|
120
|
+
|
|
121
|
+
if (room.width <= 0 || room.height <= 0) return
|
|
122
|
+
const fit = Math.min(1, room.width / (width + PADDING * 2), room.height / (height + PADDING * 2))
|
|
123
|
+
canvas.style.padding = `${PADDING * fit}px`
|
|
124
|
+
props.svg.style.width = `${width * fit}px`
|
|
125
|
+
props.svg.style.height = `${height * fit}px`
|
|
126
|
+
setFitRatio(fit)
|
|
127
|
+
follow(clampView(view(), bounds()))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Pele sizes the inline diagram to its column; here the preview sizes it.
|
|
131
|
+
props.svg.style.maxWidth = "none"
|
|
132
|
+
|
|
133
|
+
createResizeObserver(() => viewport, measure)
|
|
134
|
+
|
|
135
|
+
const point = (event: MouseEvent) => {
|
|
136
|
+
const rect = viewport.getBoundingClientRect()
|
|
137
|
+
|
|
138
|
+
return { x: event.clientX - rect.left - rect.width / 2, y: event.clientY - rect.top - rect.height / 2 }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const detail = (event: MouseEvent) => {
|
|
142
|
+
if (goal().scale > 1) return ease(FIT_VIEW)
|
|
143
|
+
ease(zoomAt(goal(), detailScale(fitRatio()), point(event), bounds()))
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const grab = (event: PointerEvent) => {
|
|
147
|
+
panned = false
|
|
148
|
+
|
|
149
|
+
if (event.button !== 0 || view().scale <= 1) return
|
|
150
|
+
event.preventDefault()
|
|
151
|
+
viewport.setPointerCapture(event.pointerId)
|
|
152
|
+
setDrag({ id: event.pointerId, x: event.clientX, y: event.clientY })
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const pan = (event: PointerEvent) => {
|
|
156
|
+
const current = drag()
|
|
157
|
+
|
|
158
|
+
if (current?.id !== event.pointerId) return
|
|
159
|
+
backdrop = false
|
|
160
|
+
panned = true
|
|
161
|
+
setDrag({ id: current.id, x: event.clientX, y: event.clientY })
|
|
162
|
+
follow(panBy(view(), { x: event.clientX - current.x, y: event.clientY - current.y }, bounds()))
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const release = (event: PointerEvent) => {
|
|
166
|
+
if (drag()?.id === event.pointerId) setDrag(undefined)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// The preview owns zoom gestures while it is open: the page behind must neither scroll nor zoom the whole window.
|
|
170
|
+
makeEventListener(
|
|
171
|
+
window,
|
|
172
|
+
"wheel",
|
|
173
|
+
(event: WheelEvent) => {
|
|
174
|
+
const inside = event.target instanceof Node && viewport.contains(event.target)
|
|
175
|
+
const zoom = event.ctrlKey || event.metaKey
|
|
176
|
+
|
|
177
|
+
if (!inside && !zoom) return
|
|
178
|
+
event.preventDefault()
|
|
179
|
+
event.stopPropagation()
|
|
180
|
+
|
|
181
|
+
if (!inside) return
|
|
182
|
+
const current = view()
|
|
183
|
+
|
|
184
|
+
if (zoom) {
|
|
185
|
+
follow(
|
|
186
|
+
zoomAt(current, current.scale * wheelZoomFactor(wheelPixels(event, event.deltaY)), point(event), bounds()),
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const horizontal = event.shiftKey && event.deltaX === 0
|
|
193
|
+
follow(
|
|
194
|
+
panBy(
|
|
195
|
+
current,
|
|
196
|
+
{
|
|
197
|
+
x: -wheelPixels(event, horizontal ? event.deltaY : event.deltaX),
|
|
198
|
+
y: horizontal ? 0 : -wheelPixels(event, event.deltaY),
|
|
199
|
+
},
|
|
200
|
+
bounds(),
|
|
201
|
+
),
|
|
202
|
+
)
|
|
203
|
+
},
|
|
204
|
+
{ passive: false, capture: true },
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
// Captured ahead of the desktop shell, which zooms the whole window on the same shortcuts.
|
|
208
|
+
makeEventListener(
|
|
209
|
+
window,
|
|
210
|
+
"keydown",
|
|
211
|
+
(event: KeyboardEvent) => {
|
|
212
|
+
const bare = !event.metaKey && !event.ctrlKey && !event.altKey
|
|
213
|
+
const arrow = bare ? arrowDirection(event.key) : undefined
|
|
214
|
+
|
|
215
|
+
if (arrow) {
|
|
216
|
+
event.preventDefault()
|
|
217
|
+
event.stopPropagation()
|
|
218
|
+
const distance = event.shiftKey ? 1 : ARROW_PAN
|
|
219
|
+
|
|
220
|
+
return ease(
|
|
221
|
+
panBy(
|
|
222
|
+
goal(),
|
|
223
|
+
{ x: arrow.x * distance * viewport.clientWidth, y: arrow.y * distance * viewport.clientHeight },
|
|
224
|
+
bounds(),
|
|
225
|
+
),
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const action = bare ? (event.key === "0" ? "fit" : undefined) : event.altKey ? undefined : zoomShortcut(event.key)
|
|
230
|
+
|
|
231
|
+
if (!action) return
|
|
232
|
+
event.preventDefault()
|
|
233
|
+
event.stopPropagation()
|
|
234
|
+
|
|
235
|
+
if (action === "fit") return ease(FIT_VIEW)
|
|
236
|
+
step(action === "in" ? STEP : 1 / STEP)
|
|
237
|
+
},
|
|
238
|
+
{ capture: true },
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<div
|
|
243
|
+
data-component="diagram-preview"
|
|
244
|
+
// Zoomed in, the first Escape zooms back out; the dialog stack leaves it to the preview.
|
|
245
|
+
data-owns-escape={goal().scale > 1 ? "" : undefined}
|
|
246
|
+
>
|
|
247
|
+
<Kobalte.Content
|
|
248
|
+
data-slot="diagram-preview-content"
|
|
249
|
+
aria-label={i18n.t("ui.diagramPreview.label")}
|
|
250
|
+
onOpenAutoFocus={(event) => {
|
|
251
|
+
event.preventDefault()
|
|
252
|
+
close?.focus()
|
|
253
|
+
}}
|
|
254
|
+
onEscapeKeyDown={(event) => {
|
|
255
|
+
if (goal().scale <= 1) return
|
|
256
|
+
event.preventDefault()
|
|
257
|
+
ease(FIT_VIEW)
|
|
258
|
+
}}
|
|
259
|
+
onPointerDown={(event: PointerEvent) => {
|
|
260
|
+
backdrop = event.target === viewport
|
|
261
|
+
}}
|
|
262
|
+
onClick={(event: MouseEvent) => {
|
|
263
|
+
// The preview fills the window, so a click on the backdrop around the diagram lands here.
|
|
264
|
+
if (!backdrop || panned || event.target !== viewport) return
|
|
265
|
+
dialog.close()
|
|
266
|
+
}}
|
|
267
|
+
>
|
|
268
|
+
<div
|
|
269
|
+
ref={viewport}
|
|
270
|
+
data-slot="diagram-preview-body"
|
|
271
|
+
data-zoomed={view().scale > 1 ? "" : undefined}
|
|
272
|
+
data-dragging={drag() ? "" : undefined}
|
|
273
|
+
onDblClick={detail}
|
|
274
|
+
onPointerDown={grab}
|
|
275
|
+
onPointerMove={pan}
|
|
276
|
+
onPointerUp={release}
|
|
277
|
+
onPointerCancel={release}
|
|
278
|
+
>
|
|
279
|
+
<div ref={canvas} data-slot="diagram-preview-canvas">
|
|
280
|
+
{props.svg}
|
|
281
|
+
</div>
|
|
282
|
+
</div>
|
|
283
|
+
<div data-slot="diagram-preview-controls">
|
|
284
|
+
<IconButton
|
|
285
|
+
data-slot="diagram-preview-zoom-out"
|
|
286
|
+
icon={<Icon name="minus" />}
|
|
287
|
+
variant="ghost"
|
|
288
|
+
aria-label={i18n.t("ui.imagePreview.zoomOut")}
|
|
289
|
+
onClick={() => step(1 / STEP)}
|
|
290
|
+
/>
|
|
291
|
+
<Button
|
|
292
|
+
data-slot="diagram-preview-zoom-level"
|
|
293
|
+
variant="ghost-muted"
|
|
294
|
+
size="small"
|
|
295
|
+
aria-label={i18n.t("ui.imagePreview.zoomToFit")}
|
|
296
|
+
title={i18n.t("ui.imagePreview.zoomToFit")}
|
|
297
|
+
onClick={() => ease(FIT_VIEW)}
|
|
298
|
+
>
|
|
299
|
+
{percent().format(view().scale * fitRatio())}
|
|
300
|
+
</Button>
|
|
301
|
+
<IconButton
|
|
302
|
+
data-slot="diagram-preview-zoom-in"
|
|
303
|
+
icon={<Icon name="plus" />}
|
|
304
|
+
variant="ghost"
|
|
305
|
+
aria-label={i18n.t("ui.imagePreview.zoomIn")}
|
|
306
|
+
onClick={() => step(STEP)}
|
|
307
|
+
/>
|
|
308
|
+
<div data-slot="diagram-preview-divider" />
|
|
309
|
+
<Kobalte.CloseButton
|
|
310
|
+
ref={close}
|
|
311
|
+
data-slot="diagram-preview-close"
|
|
312
|
+
as={IconButton}
|
|
313
|
+
icon={<Icon name="close" />}
|
|
314
|
+
variant="ghost"
|
|
315
|
+
aria-label={i18n.t("ui.common.close")}
|
|
316
|
+
/>
|
|
317
|
+
</div>
|
|
318
|
+
</Kobalte.Content>
|
|
319
|
+
</div>
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Arrow keys move the view over the diagram, so the diagram moves the other way.
|
|
324
|
+
function arrowDirection(key: string) {
|
|
325
|
+
if (key === "ArrowLeft") return { x: 1, y: 0 }
|
|
326
|
+
|
|
327
|
+
if (key === "ArrowRight") return { x: -1, y: 0 }
|
|
328
|
+
|
|
329
|
+
if (key === "ArrowUp") return { x: 0, y: 1 }
|
|
330
|
+
|
|
331
|
+
if (key === "ArrowDown") return { x: 0, y: -1 }
|
|
332
|
+
}
|
|
@@ -40,8 +40,10 @@ import {
|
|
|
40
40
|
maxScale,
|
|
41
41
|
panBy,
|
|
42
42
|
viewBox,
|
|
43
|
+
wheelPixels,
|
|
43
44
|
wheelZoomFactor,
|
|
44
45
|
zoomAt,
|
|
46
|
+
zoomShortcut,
|
|
45
47
|
type ZoomView,
|
|
46
48
|
} from "./image-zoom"
|
|
47
49
|
import {
|
|
@@ -657,7 +659,7 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
657
659
|
const current = view()
|
|
658
660
|
|
|
659
661
|
const next = pinch
|
|
660
|
-
? zoomAt(current, current.scale * wheelZoomFactor(
|
|
662
|
+
? zoomAt(current, current.scale * wheelZoomFactor(wheelPixels(event, event.deltaY)), point(event), bounds)
|
|
661
663
|
: panBy(current, wheelPan(event), bounds)
|
|
662
664
|
|
|
663
665
|
follow(next.scale, next.x, next.y)
|
|
@@ -682,7 +684,7 @@ export function ImagePreview(props: ImagePreviewProps) {
|
|
|
682
684
|
return props.video.pause()
|
|
683
685
|
}
|
|
684
686
|
|
|
685
|
-
const action = bare ? (event.key === "0" ? "fit" : undefined) : event.altKey ? undefined :
|
|
687
|
+
const action = bare ? (event.key === "0" ? "fit" : undefined) : event.altKey ? undefined : zoomShortcut(event.key)
|
|
686
688
|
|
|
687
689
|
if (!action) return
|
|
688
690
|
event.preventDefault()
|
|
@@ -895,28 +897,12 @@ function layout(element: HTMLElement, frame: Box, radius: number) {
|
|
|
895
897
|
element.style.borderRadius = `${radius}px`
|
|
896
898
|
}
|
|
897
899
|
|
|
898
|
-
function shortcut(key: string) {
|
|
899
|
-
if (key === "=" || key === "+") return "in"
|
|
900
|
-
|
|
901
|
-
if (key === "-" || key === "_") return "out"
|
|
902
|
-
|
|
903
|
-
if (key === "0") return "fit"
|
|
904
|
-
}
|
|
905
|
-
|
|
906
900
|
// A plain wheel pans; Shift turns a vertical wheel sideways.
|
|
907
901
|
function wheelPan(event: WheelEvent) {
|
|
908
902
|
const horizontal = event.shiftKey && event.deltaX === 0
|
|
909
903
|
|
|
910
904
|
return {
|
|
911
|
-
x: -
|
|
912
|
-
y: horizontal ? 0 : -
|
|
905
|
+
x: -wheelPixels(event, horizontal ? event.deltaY : event.deltaX),
|
|
906
|
+
y: horizontal ? 0 : -wheelPixels(event, event.deltaY),
|
|
913
907
|
}
|
|
914
908
|
}
|
|
915
|
-
|
|
916
|
-
function pixels(event: WheelEvent, delta: number) {
|
|
917
|
-
if (event.deltaMode === WheelEvent.DOM_DELTA_LINE) return delta * 16
|
|
918
|
-
|
|
919
|
-
if (event.deltaMode === WheelEvent.DOM_DELTA_PAGE) return delta * window.innerHeight
|
|
920
|
-
|
|
921
|
-
return delta
|
|
922
|
-
}
|
|
@@ -85,6 +85,24 @@ export function wheelZoomFactor(deltaY: number) {
|
|
|
85
85
|
return Math.exp(-clamp(deltaY, -30, 30) / 100)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/** The zoom a Cmd/Ctrl shortcut asks for, from the key it is pressed with. */
|
|
89
|
+
export function zoomShortcut(key: string) {
|
|
90
|
+
if (key === "=" || key === "+") return "in"
|
|
91
|
+
|
|
92
|
+
if (key === "-" || key === "_") return "out"
|
|
93
|
+
|
|
94
|
+
if (key === "0") return "fit"
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A wheel event's delta in pixels, whether it counts in pixels, lines or pages. */
|
|
98
|
+
export function wheelPixels(event: WheelEvent, delta: number) {
|
|
99
|
+
if (event.deltaMode === WheelEvent.DOM_DELTA_LINE) return delta * 16
|
|
100
|
+
|
|
101
|
+
if (event.deltaMode === WheelEvent.DOM_DELTA_PAGE) return delta * window.innerHeight
|
|
102
|
+
|
|
103
|
+
return delta
|
|
104
|
+
}
|
|
105
|
+
|
|
88
106
|
/** Keeps one axis of a zoomed image of `size` covering a `viewport` it overflows, and centered in one it fits. */
|
|
89
107
|
export function clampAxis(offset: number, size: number, viewport: number) {
|
|
90
108
|
const limit = Math.max(0, (size - viewport) / 2)
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import type { Component, JSX } from "solid-js"
|
|
2
2
|
import { createMemo, splitProps } from "solid-js"
|
|
3
3
|
import sprite from "./provider-icons/sprite.svg"
|
|
4
|
-
import { iconNames
|
|
4
|
+
import { iconNames } from "./provider-icons/types"
|
|
5
5
|
|
|
6
6
|
export type ProviderIconProps = JSX.SVGElementTags["svg"] & {
|
|
7
7
|
id: string
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/** Whether a provider has its own icon. Others fall back to a generic one, which callers may prefer to leave out. */
|
|
11
|
+
export function hasProviderIcon(id: string) {
|
|
12
|
+
return iconNames.some((name) => name === id)
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
export const ProviderIcon: Component<ProviderIconProps> = (props) => {
|
|
11
16
|
const [local, rest] = splitProps(props, ["id", "class", "classList"])
|
|
12
|
-
const resolved = createMemo(() => (
|
|
17
|
+
const resolved = createMemo(() => (hasProviderIcon(local.id) ? local.id : "synthetic"))
|
|
13
18
|
|
|
14
19
|
return (
|
|
15
20
|
<svg
|
|
@@ -32,6 +32,12 @@
|
|
|
32
32
|
color: var(--v2-text-text-contrast);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
[data-component="tag"][data-variant="danger"] {
|
|
36
|
+
border: 0.5px solid var(--v2-state-border-danger);
|
|
37
|
+
background: var(--v2-state-bg-danger);
|
|
38
|
+
color: var(--v2-state-fg-danger);
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
[data-component="tag"][data-variant="subtle"] {
|
|
36
42
|
border: 0;
|
|
37
43
|
background: var(--v2-background-bg-layer-03);
|
|
@@ -3,7 +3,7 @@ import "./badge.css"
|
|
|
3
3
|
|
|
4
4
|
export interface BadgeProps extends ComponentProps<"span"> {
|
|
5
5
|
appearance?: "standard" | "compact"
|
|
6
|
-
variant?: "neutral" | "accent" | "subtle"
|
|
6
|
+
variant?: "neutral" | "accent" | "subtle" | "danger"
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function Badge(props: BadgeProps) {
|
|
@@ -4,6 +4,8 @@ import "./diff-changes.css"
|
|
|
4
4
|
export function DiffChanges(props: {
|
|
5
5
|
class?: string
|
|
6
6
|
appearance?: "standard" | "compact"
|
|
7
|
+
/** Marks a side with no changes `data-empty`, so a page can hide it. */
|
|
8
|
+
markEmpty?: boolean
|
|
7
9
|
changes: { additions: number; deletions: number } | { additions: number; deletions: number }[]
|
|
8
10
|
}) {
|
|
9
11
|
const additions = createMemo(() =>
|
|
@@ -27,8 +29,14 @@ export function DiffChanges(props: {
|
|
|
27
29
|
data-appearance={props.appearance ?? "compact"}
|
|
28
30
|
classList={{ [props.class ?? ""]: true }}
|
|
29
31
|
>
|
|
30
|
-
<span
|
|
31
|
-
|
|
32
|
+
<span
|
|
33
|
+
data-slot="diff-changes-additions"
|
|
34
|
+
data-empty={props.markEmpty && !additions() ? "" : undefined}
|
|
35
|
+
>{`+${additions()}`}</span>
|
|
36
|
+
<span
|
|
37
|
+
data-slot="diff-changes-deletions"
|
|
38
|
+
data-empty={props.markEmpty && !deletions() ? "" : undefined}
|
|
39
|
+
>{`-${deletions()}`}</span>
|
|
32
40
|
</div>
|
|
33
41
|
</Show>
|
|
34
42
|
)
|
|
@@ -88,6 +88,19 @@
|
|
|
88
88
|
text-shadow: none;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
[data-slot="project-avatar-surface"] [data-slot="project-avatar-label"] {
|
|
92
|
+
position: absolute;
|
|
93
|
+
inset: 0;
|
|
94
|
+
display: flex;
|
|
95
|
+
align-items: center;
|
|
96
|
+
justify-content: center;
|
|
97
|
+
visibility: hidden;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
[data-slot="project-avatar-surface"]:is([data-has-image], [data-generated]) [data-slot="project-avatar-label"] {
|
|
101
|
+
background: var(--project-avatar-bg);
|
|
102
|
+
}
|
|
103
|
+
|
|
91
104
|
[data-slot="project-avatar-surface"][data-generated] {
|
|
92
105
|
background: none;
|
|
93
106
|
box-shadow: none;
|
|
@@ -147,6 +147,8 @@ export interface ProjectAvatarProps extends ComponentProps<"div"> {
|
|
|
147
147
|
unread?: boolean
|
|
148
148
|
/** Seeds the generated default avatar shown when there is no image; see getProjectAvatarGenerated. */
|
|
149
149
|
generated?: string
|
|
150
|
+
/** Text stacked over the avatar, hidden until the caller's CSS reveals `[data-slot="project-avatar-label"]`. */
|
|
151
|
+
label?: string
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
export function ProjectAvatar(props: ProjectAvatarProps) {
|
|
@@ -156,6 +158,7 @@ export function ProjectAvatar(props: ProjectAvatarProps) {
|
|
|
156
158
|
"variant",
|
|
157
159
|
"unread",
|
|
158
160
|
"generated",
|
|
161
|
+
"label",
|
|
159
162
|
"class",
|
|
160
163
|
"classList",
|
|
161
164
|
"style",
|
|
@@ -184,13 +187,23 @@ export function ProjectAvatar(props: ProjectAvatarProps) {
|
|
|
184
187
|
<Show
|
|
185
188
|
when={split.src}
|
|
186
189
|
fallback={
|
|
187
|
-
<Show
|
|
190
|
+
<Show
|
|
191
|
+
when={generated()}
|
|
192
|
+
fallback={<span data-slot="project-avatar-initial">{first(split.fallback)}</span>}
|
|
193
|
+
>
|
|
188
194
|
{(key) => <GeneratedAvatar seed={key()} />}
|
|
189
195
|
</Show>
|
|
190
196
|
}
|
|
191
197
|
>
|
|
192
198
|
{(value) => <img src={value()} draggable={false} data-slot="project-avatar-image" />}
|
|
193
199
|
</Show>
|
|
200
|
+
<Show when={split.label}>
|
|
201
|
+
{(label) => (
|
|
202
|
+
<span data-slot="project-avatar-label" aria-hidden="true">
|
|
203
|
+
{label()}
|
|
204
|
+
</span>
|
|
205
|
+
)}
|
|
206
|
+
</Show>
|
|
194
207
|
</div>
|
|
195
208
|
<Show when={split.unread}>
|
|
196
209
|
<span data-slot="project-avatar-unread-dot" aria-hidden="true" />
|
|
@@ -25,6 +25,10 @@ function ToastRegion(props: ToastRegionProps) {
|
|
|
25
25
|
// The Portal's container holds the toast region whenever it exists. Watching the container, not the whole body,
|
|
26
26
|
// keeps every DOM change elsewhere in the page (each streamed delta, each mounted row) from scanning the document.
|
|
27
27
|
const observe = (container: HTMLDivElement) => {
|
|
28
|
+
// A modal dialog hides what's outside it from assistive tech. The region is in the Portal's own div, so that div,
|
|
29
|
+
// rather than the toaster, is what the dialog would hide.
|
|
30
|
+
container.setAttribute("data-kb-top-layer", "")
|
|
31
|
+
|
|
28
32
|
const sync = () => {
|
|
29
33
|
container.querySelectorAll<HTMLElement>(".toast-v2-region .toast-v2").forEach((element) => {
|
|
30
34
|
const hidden = element.dataset.visible === "false"
|
|
@@ -179,6 +183,8 @@ export interface ToastAction {
|
|
|
179
183
|
}
|
|
180
184
|
|
|
181
185
|
export interface ToastOptions {
|
|
186
|
+
/** Called when the user closes or swipes away the toast. */
|
|
187
|
+
onDismiss?: () => void
|
|
182
188
|
title?: string
|
|
183
189
|
description?: string
|
|
184
190
|
/** An element, or a render function the toast calls under its own owner, for icons created from imperative code. */
|
|
@@ -250,7 +256,11 @@ function publishToast(id: number, options: ToastOptions) {
|
|
|
250
256
|
className: `toast-v2 toast-v2--${options.variant ?? "default"}`,
|
|
251
257
|
testId: `toast-v2-${id}`,
|
|
252
258
|
unstyled: true,
|
|
253
|
-
onDismiss:
|
|
259
|
+
onDismiss: () => {
|
|
260
|
+
const current = selectToastOptions(registry, id)
|
|
261
|
+
release()
|
|
262
|
+
current?.onDismiss?.()
|
|
263
|
+
},
|
|
254
264
|
onAutoClose: release,
|
|
255
265
|
})
|
|
256
266
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createUniqueId, onMount, Show } from "solid-js"
|
|
2
|
+
import { Button } from "@opencode/ui/button"
|
|
3
|
+
import { TextInput } from "@opencode/ui/text-input"
|
|
4
|
+
import { useI18n } from "../../context/i18n"
|
|
5
|
+
|
|
6
|
+
/** Why the last paste was not taken: the field was empty, or the server rejected the URL with `message`. */
|
|
7
|
+
export type RedirectPasteError = { readonly type: "required" } | { readonly type: "rejected"; readonly message: string }
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The field of a browser sign-in that takes the URL the browser was redirected to, for when the browser cannot reach
|
|
11
|
+
* the machine running the server (SSH, a remote desktop connection, a container).
|
|
12
|
+
*/
|
|
13
|
+
export function RedirectPasteForm(props: {
|
|
14
|
+
value: string
|
|
15
|
+
error: RedirectPasteError | undefined
|
|
16
|
+
/** Takes no edits or submits: a paste is in flight, or the server took one and is finishing the sign-in. */
|
|
17
|
+
locked: boolean
|
|
18
|
+
/** A paste is in flight. */
|
|
19
|
+
submitting: boolean
|
|
20
|
+
/** Focuses the field on mount, for a dialog where pasting is the main action. */
|
|
21
|
+
autofocus?: boolean
|
|
22
|
+
onInput: (value: string) => void
|
|
23
|
+
onSubmit: () => void
|
|
24
|
+
}) {
|
|
25
|
+
const i18n = useI18n()
|
|
26
|
+
const errorID = createUniqueId()
|
|
27
|
+
let input: HTMLInputElement | undefined
|
|
28
|
+
|
|
29
|
+
const error = () => {
|
|
30
|
+
if (!props.error) return
|
|
31
|
+
|
|
32
|
+
return props.error.type === "rejected" ? props.error.message : i18n.t("ui.redirectPaste.required")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
onMount(() => {
|
|
36
|
+
if (props.autofocus) input?.focus({ preventScroll: true })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<form
|
|
41
|
+
onSubmit={(event) => {
|
|
42
|
+
event.preventDefault()
|
|
43
|
+
props.onSubmit()
|
|
44
|
+
}}
|
|
45
|
+
class="flex flex-col items-start gap-5 self-stretch"
|
|
46
|
+
>
|
|
47
|
+
<label class="flex w-full flex-col gap-2 font-[530] leading-4 text-v2-text-text-base">
|
|
48
|
+
{i18n.t("ui.redirectPaste.label")}
|
|
49
|
+
<TextInput
|
|
50
|
+
ref={input}
|
|
51
|
+
class="!w-full"
|
|
52
|
+
name="redirect"
|
|
53
|
+
placeholder={i18n.t("ui.redirectPaste.placeholder")}
|
|
54
|
+
value={props.value}
|
|
55
|
+
readOnly={props.locked}
|
|
56
|
+
invalid={error() !== undefined}
|
|
57
|
+
aria-describedby={error() ? errorID : undefined}
|
|
58
|
+
autocomplete="off"
|
|
59
|
+
spellcheck={false}
|
|
60
|
+
onInput={(event) => props.onInput(event.currentTarget.value)}
|
|
61
|
+
/>
|
|
62
|
+
</label>
|
|
63
|
+
<Show when={error()}>
|
|
64
|
+
{(message) => (
|
|
65
|
+
<div id={errorID} role="alert" class="-mt-4 text-xs text-v2-state-fg-danger">
|
|
66
|
+
{message()}
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
</Show>
|
|
70
|
+
<Button type="submit" variant="contrast" disabled={props.locked} aria-busy={props.submitting}>
|
|
71
|
+
{i18n.t("ui.common.continue")}
|
|
72
|
+
</Button>
|
|
73
|
+
</form>
|
|
74
|
+
)
|
|
75
|
+
}
|