@opencode/ui 0.0.0-dev-398 → 0.0.0-dev-406
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.
|
@@ -35,5 +35,14 @@ export interface LineCommentEditorProps extends Omit<ComponentProps<"div">, "chi
|
|
|
35
35
|
/** Submit an empty value too, such as to clear a comment that exists (default: false). Compact empty actions otherwise cancel. */
|
|
36
36
|
allowEmpty?: boolean;
|
|
37
37
|
mention?: LineCommentEditorMention;
|
|
38
|
+
/** Compact editor action on Mod+Enter or modifier-click. */
|
|
39
|
+
alternateSubmit?: {
|
|
40
|
+
label: string;
|
|
41
|
+
keys: string[];
|
|
42
|
+
disabled?: boolean;
|
|
43
|
+
onSubmit: (value: string) => void;
|
|
44
|
+
};
|
|
45
|
+
/** Keep the draft read-only and prevent duplicate actions while its submission settles. */
|
|
46
|
+
submitting?: boolean;
|
|
38
47
|
}
|
|
39
48
|
export declare function LineCommentEditor(props: LineCommentEditorProps): JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencode/ui",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-406",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -288,7 +288,7 @@
|
|
|
288
288
|
"dependencies": {
|
|
289
289
|
"@kitlangton/solid-motion": "0.2.2",
|
|
290
290
|
"@kobalte/core": "0.13.13",
|
|
291
|
-
"@opencode/util": "0.0.0-dev-
|
|
291
|
+
"@opencode/util": "0.0.0-dev-406",
|
|
292
292
|
"@pierre/diffs": "1.6.1",
|
|
293
293
|
"@pierre/highlights": "0.2.0",
|
|
294
294
|
"@solid-primitives/event-listener": "2.4.6",
|
|
@@ -18,6 +18,8 @@ import { Icon } from "@opencode/ui/icon"
|
|
|
18
18
|
import { IconButton } from "@opencode/ui/icon-button"
|
|
19
19
|
import { Keybind } from "@opencode/ui/keybind"
|
|
20
20
|
import { Tooltip } from "@opencode/ui/tooltip"
|
|
21
|
+
import { Loader } from "@opencode/ui/loader"
|
|
22
|
+
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
21
23
|
import check from "./quote-check.svg"
|
|
22
24
|
import "./line-comment.css"
|
|
23
25
|
|
|
@@ -100,6 +102,15 @@ export interface LineCommentEditorProps extends Omit<ComponentProps<"div">, "chi
|
|
|
100
102
|
/** Submit an empty value too, such as to clear a comment that exists (default: false). Compact empty actions otherwise cancel. */
|
|
101
103
|
allowEmpty?: boolean
|
|
102
104
|
mention?: LineCommentEditorMention
|
|
105
|
+
/** Compact editor action on Mod+Enter or modifier-click. */
|
|
106
|
+
alternateSubmit?: {
|
|
107
|
+
label: string
|
|
108
|
+
keys: string[]
|
|
109
|
+
disabled?: boolean
|
|
110
|
+
onSubmit: (value: string) => void
|
|
111
|
+
}
|
|
112
|
+
/** Keep the draft read-only and prevent duplicate actions while its submission settles. */
|
|
113
|
+
submitting?: boolean
|
|
103
114
|
}
|
|
104
115
|
|
|
105
116
|
function pathFilename(path: string) {
|
|
@@ -119,6 +130,8 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
119
130
|
let textareaRef: HTMLTextAreaElement | undefined
|
|
120
131
|
const [mentionOpen, setMentionOpen] = createSignal(false)
|
|
121
132
|
|
|
133
|
+
const [alternate, setAlternate] = createSignal(false)
|
|
134
|
+
|
|
122
135
|
const [local, rest] = splitProps(props, [
|
|
123
136
|
"label",
|
|
124
137
|
"value",
|
|
@@ -134,6 +147,8 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
134
147
|
"autofocus",
|
|
135
148
|
"allowEmpty",
|
|
136
149
|
"mention",
|
|
150
|
+
"alternateSubmit",
|
|
151
|
+
"submitting",
|
|
137
152
|
"class",
|
|
138
153
|
"classList",
|
|
139
154
|
])
|
|
@@ -141,10 +156,25 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
141
156
|
const canSubmit = () => !!local.allowEmpty || local.value.trim().length > 0
|
|
142
157
|
const compactCancel = () => !canSubmit()
|
|
143
158
|
|
|
159
|
+
const alternateActive = () => !!local.alternateSubmit && alternate()
|
|
160
|
+
|
|
144
161
|
const compactLabel = () =>
|
|
145
|
-
|
|
146
|
-
?
|
|
147
|
-
: (
|
|
162
|
+
alternateActive()
|
|
163
|
+
? local.alternateSubmit!.label
|
|
164
|
+
: compactCancel()
|
|
165
|
+
? (local.cancelLabel ?? i18n.t("ui.lineComment.cancel"))
|
|
166
|
+
: (local.submitLabel ?? i18n.t("ui.lineComment.submit"))
|
|
167
|
+
|
|
168
|
+
createEffect(() => {
|
|
169
|
+
if (local.variant !== "compact" || !local.alternateSubmit) return
|
|
170
|
+
|
|
171
|
+
const update = (event: KeyboardEvent) => setAlternate(modified(event))
|
|
172
|
+
|
|
173
|
+
// Capture modifier releases; the textarea stops key propagation.
|
|
174
|
+
makeEventListener(document, "keydown", update, { capture: true })
|
|
175
|
+
makeEventListener(document, "keyup", update, { capture: true })
|
|
176
|
+
makeEventListener(window, "blur", () => setAlternate(false))
|
|
177
|
+
})
|
|
148
178
|
|
|
149
179
|
const closeMention = () => {
|
|
150
180
|
setMentionOpen(false)
|
|
@@ -228,10 +258,18 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
228
258
|
selectMention(items.find((item) => item.path === active) ?? items[0])
|
|
229
259
|
}
|
|
230
260
|
|
|
231
|
-
const submit = () => {
|
|
261
|
+
const submit = (alternate = false) => {
|
|
262
|
+
if (local.submitting) return
|
|
232
263
|
const v = local.value.trim()
|
|
233
264
|
|
|
234
265
|
if (!v && !local.allowEmpty) return
|
|
266
|
+
|
|
267
|
+
if (alternate && local.alternateSubmit) {
|
|
268
|
+
if (!local.alternateSubmit.disabled) local.alternateSubmit.onSubmit(v)
|
|
269
|
+
|
|
270
|
+
return
|
|
271
|
+
}
|
|
272
|
+
|
|
235
273
|
local.onSubmit(v)
|
|
236
274
|
}
|
|
237
275
|
|
|
@@ -278,6 +316,7 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
278
316
|
data-component="line-comment-v2"
|
|
279
317
|
data-variant="editor"
|
|
280
318
|
data-layout={local.variant ?? "default"}
|
|
319
|
+
aria-busy={local.submitting || undefined}
|
|
281
320
|
classList={{
|
|
282
321
|
...local.classList,
|
|
283
322
|
[local.class ?? ""]: !!local.class,
|
|
@@ -300,6 +339,7 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
300
339
|
rows={local.rows ?? (local.variant === "compact" ? 1 : 4)}
|
|
301
340
|
placeholder={local.placeholder ?? i18n.t("ui.lineComment.contextPlaceholder")}
|
|
302
341
|
value={local.value}
|
|
342
|
+
readOnly={local.submitting}
|
|
303
343
|
style={{ "unicode-bidi": "plaintext", "text-align": "start" }}
|
|
304
344
|
onInput={(e) => {
|
|
305
345
|
local.onInput(e.currentTarget.value)
|
|
@@ -312,7 +352,7 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
312
352
|
|
|
313
353
|
if (e.isComposing || e.keyCode === 229) return
|
|
314
354
|
|
|
315
|
-
if (mentionOpen()) {
|
|
355
|
+
if (mentionOpen() && !local.submitting) {
|
|
316
356
|
if (e.key === "Escape") {
|
|
317
357
|
e.preventDefault()
|
|
318
358
|
closeMention()
|
|
@@ -343,6 +383,8 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
343
383
|
|
|
344
384
|
if (e.key === "Escape") {
|
|
345
385
|
e.preventDefault()
|
|
386
|
+
|
|
387
|
+
if (local.submitting) return
|
|
346
388
|
e.currentTarget.blur()
|
|
347
389
|
local.onCancel()
|
|
348
390
|
|
|
@@ -351,11 +393,13 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
351
393
|
|
|
352
394
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
353
395
|
e.preventDefault()
|
|
354
|
-
|
|
396
|
+
|
|
397
|
+
if (e.repeat) return
|
|
398
|
+
submit(modified(e))
|
|
355
399
|
}
|
|
356
400
|
}}
|
|
357
401
|
/>
|
|
358
|
-
<Show when={mentionOpen() && mention.flat().length > 0}>
|
|
402
|
+
<Show when={!local.submitting && mentionOpen() && mention.flat().length > 0}>
|
|
359
403
|
<div data-slot="line-comment-v2-mention-list">
|
|
360
404
|
<For each={mention.flat().slice(0, 10)}>
|
|
361
405
|
{(item) => {
|
|
@@ -388,9 +432,21 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
388
432
|
<Show when={local.variant === "compact"}>
|
|
389
433
|
<Tooltip
|
|
390
434
|
value={
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
435
|
+
<div class="flex flex-col gap-1.5">
|
|
436
|
+
<div class="flex items-center gap-1.5">
|
|
437
|
+
{compactLabel()}
|
|
438
|
+
<Keybind
|
|
439
|
+
keys={alternateActive() ? local.alternateSubmit!.keys : [compactCancel() ? "Esc" : "⏎"]}
|
|
440
|
+
variant="neutral"
|
|
441
|
+
/>
|
|
442
|
+
</div>
|
|
443
|
+
<Show when={local.alternateSubmit && !alternateActive()}>
|
|
444
|
+
<div class="flex items-center gap-1.5">
|
|
445
|
+
{local.alternateSubmit!.label}
|
|
446
|
+
<Keybind keys={local.alternateSubmit!.keys} variant="neutral" />
|
|
447
|
+
</div>
|
|
448
|
+
</Show>
|
|
449
|
+
</div>
|
|
394
450
|
}
|
|
395
451
|
placement="top"
|
|
396
452
|
>
|
|
@@ -398,9 +454,16 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
398
454
|
data-slot="line-comment-v2-submit"
|
|
399
455
|
type="button"
|
|
400
456
|
size="small"
|
|
401
|
-
variant={
|
|
457
|
+
variant={
|
|
458
|
+
alternateActive() || local.submitting ? "submit" : local.value.trim() ? "neutral" : "ghost-muted"
|
|
459
|
+
}
|
|
460
|
+
disabled={local.submitting || (alternateActive() && local.alternateSubmit?.disabled)}
|
|
402
461
|
icon={
|
|
403
|
-
|
|
462
|
+
local.submitting ? (
|
|
463
|
+
<Loader />
|
|
464
|
+
) : alternateActive() ? (
|
|
465
|
+
<Icon name="arrow-up" />
|
|
466
|
+
) : compactCancel() ? (
|
|
404
467
|
<Icon name="close" />
|
|
405
468
|
) : (
|
|
406
469
|
<span
|
|
@@ -411,12 +474,30 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
411
474
|
)
|
|
412
475
|
}
|
|
413
476
|
aria-label={compactLabel()}
|
|
414
|
-
|
|
477
|
+
onPointerEnter={(event) => {
|
|
478
|
+
if (modified(event)) setAlternate(true)
|
|
479
|
+
}}
|
|
480
|
+
onClick={(event) => {
|
|
481
|
+
if (compactCancel() && !alternateActive()) return local.onCancel()
|
|
482
|
+
submit(alternateActive() || modified(event))
|
|
483
|
+
}}
|
|
415
484
|
onKeyDown={(event) => {
|
|
416
|
-
if (event.
|
|
485
|
+
if (event.isComposing) return
|
|
486
|
+
|
|
487
|
+
if (event.key === "Enter" && modified(event) && local.alternateSubmit) {
|
|
488
|
+
event.preventDefault()
|
|
489
|
+
event.stopPropagation()
|
|
490
|
+
|
|
491
|
+
if (!event.repeat) submit(true)
|
|
492
|
+
|
|
493
|
+
return
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (event.key !== "Escape") return
|
|
417
497
|
event.preventDefault()
|
|
418
498
|
event.stopPropagation()
|
|
419
|
-
|
|
499
|
+
|
|
500
|
+
if (!local.submitting) local.onCancel()
|
|
420
501
|
}}
|
|
421
502
|
/>
|
|
422
503
|
</Tooltip>
|
|
@@ -441,3 +522,7 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
|
|
|
441
522
|
</div>
|
|
442
523
|
)
|
|
443
524
|
}
|
|
525
|
+
|
|
526
|
+
function modified(event: Pick<KeyboardEvent, "metaKey" | "ctrlKey" | "altKey" | "shiftKey">) {
|
|
527
|
+
return (event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey
|
|
528
|
+
}
|