@opencode/ui 2.2.4 → 2.2.6

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 (127) hide show
  1. package/dist/actions/button/button.d.ts +2 -2
  2. package/dist/actions/icon-button/icon-button.d.ts +1 -1
  3. package/dist/components/animated-number-machine.d.ts +95 -0
  4. package/dist/components/file-icon-machine.d.ts +40 -0
  5. package/dist/components/file-icon.d.ts +0 -2
  6. package/dist/components/file-icons/choose-icon-name.d.ts +2 -0
  7. package/dist/components/image-flight-machine.d.ts +135 -0
  8. package/dist/components/image-zoom-machine.d.ts +95 -0
  9. package/dist/components/image-zoom.d.ts +6 -3
  10. package/dist/components/list.d.ts +2 -6
  11. package/dist/components/menu-scroll.d.ts +12 -0
  12. package/dist/components/popover-machine.d.ts +96 -0
  13. package/dist/components/popover.d.ts +2 -2
  14. package/dist/components/resize-handle-machine.d.ts +71 -0
  15. package/dist/components/resize-handle.d.ts +2 -0
  16. package/dist/components/scroll-view-machine.d.ts +68 -0
  17. package/dist/components/scroll-view.d.ts +2 -2
  18. package/dist/components/spinner.d.ts +11 -3
  19. package/dist/components/text-field-machine.d.ts +62 -0
  20. package/dist/components/text-reveal-machine.d.ts +90 -0
  21. package/dist/components/typewriter-machine.d.ts +62 -0
  22. package/dist/context/dialog-machine.d.ts +125 -0
  23. package/dist/context/dialog.d.ts +17 -16
  24. package/dist/data-display/line-comment/line-comment.d.ts +9 -0
  25. package/dist/data-display/line-comment/machine.d.ts +157 -0
  26. package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
  27. package/dist/data-display/project-avatar/animation.d.ts +1 -1
  28. package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
  29. package/dist/feedback/toast/machine.d.ts +57 -0
  30. package/dist/feedback/toast/toast.d.ts +1 -1
  31. package/dist/forms/checkbox/checkbox.d.ts +6 -1
  32. package/dist/forms/select/machine.d.ts +45 -0
  33. package/dist/forms/select/select.d.ts +4 -0
  34. package/dist/forms/text-input/text-input.d.ts +4 -2
  35. package/dist/forms/textarea/textarea.d.ts +1 -0
  36. package/dist/forms/typeahead/machine.d.ts +85 -0
  37. package/dist/hooks/auto-scroll-machine.d.ts +89 -0
  38. package/dist/hooks/create-auto-scroll.d.ts +1 -1
  39. package/dist/hooks/list-machine.d.ts +150 -0
  40. package/dist/hooks/use-filtered-list.d.ts +21 -35
  41. package/dist/i18n/en.d.ts +5 -0
  42. package/dist/icons/catalog.d.ts +8 -0
  43. package/dist/navigation/menu/machine.d.ts +49 -0
  44. package/dist/navigation/menu/menu.d.ts +5 -3
  45. package/dist/navigation/segmented-control/machine.d.ts +46 -0
  46. package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
  47. package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
  48. package/dist/overlays/tooltip/machine.d.ts +146 -0
  49. package/dist/theme/context.d.ts +38 -14
  50. package/dist/theme/machine.d.ts +174 -0
  51. package/dist/typography/text-shimmer/machine.d.ts +48 -0
  52. package/package.json +19 -3
  53. package/src/actions/button/button.tsx +11 -6
  54. package/src/actions/icon-button/icon-button.tsx +17 -4
  55. package/src/components/animated-number-machine.ts +214 -0
  56. package/src/components/animated-number.tsx +134 -83
  57. package/src/components/file-icon-machine.ts +78 -0
  58. package/src/components/file-icon.tsx +96 -579
  59. package/src/components/file-icons/choose-icon-name.ts +574 -0
  60. package/src/components/image-flight-machine.ts +247 -0
  61. package/src/components/image-preview.css +5 -2
  62. package/src/components/image-preview.tsx +390 -252
  63. package/src/components/image-zoom-machine.ts +191 -0
  64. package/src/components/image-zoom.ts +22 -14
  65. package/src/components/list.tsx +46 -137
  66. package/src/components/menu-scroll.css +70 -0
  67. package/src/components/menu-scroll.tsx +161 -0
  68. package/src/components/popover-machine.ts +198 -0
  69. package/src/components/popover.tsx +157 -89
  70. package/src/components/resize-handle-machine.ts +174 -0
  71. package/src/components/resize-handle.tsx +116 -67
  72. package/src/components/scroll-view-machine.ts +244 -0
  73. package/src/components/scroll-view.tsx +163 -116
  74. package/src/components/spinner.css +18 -5
  75. package/src/components/spinner.tsx +28 -14
  76. package/src/components/text-field-machine.ts +102 -0
  77. package/src/components/text-field.tsx +78 -24
  78. package/src/components/text-reveal-machine.ts +184 -0
  79. package/src/components/text-reveal.tsx +96 -93
  80. package/src/components/typewriter-machine.ts +134 -0
  81. package/src/components/typewriter.tsx +50 -39
  82. package/src/context/dialog-machine.ts +280 -0
  83. package/src/context/dialog.tsx +168 -177
  84. package/src/data-display/line-comment/line-comment.tsx +196 -132
  85. package/src/data-display/line-comment/machine.ts +391 -0
  86. package/src/data-display/project-avatar/animation-machine.ts +182 -0
  87. package/src/data-display/project-avatar/animation.ts +67 -38
  88. package/src/feedback/activity-ring/activity-ring.tsx +1 -1
  89. package/src/feedback/toast/machine.ts +115 -0
  90. package/src/feedback/toast/toast.tsx +55 -59
  91. package/src/forms/checkbox/checkbox-compact.css +169 -0
  92. package/src/forms/checkbox/checkbox.tsx +93 -31
  93. package/src/forms/search-list/search-list.css +5 -1
  94. package/src/forms/search-list/search-list.tsx +4 -4
  95. package/src/forms/select/machine.ts +81 -0
  96. package/src/forms/select/select.css +59 -17
  97. package/src/forms/select/select.tsx +67 -31
  98. package/src/forms/text-input/text-input.css +30 -16
  99. package/src/forms/text-input/text-input.tsx +6 -2
  100. package/src/forms/textarea/textarea.css +13 -8
  101. package/src/forms/textarea/textarea.tsx +3 -1
  102. package/src/forms/typeahead/machine.ts +253 -0
  103. package/src/forms/typeahead/typeahead.tsx +75 -66
  104. package/src/hooks/auto-scroll-machine.ts +261 -0
  105. package/src/hooks/create-auto-scroll.tsx +110 -205
  106. package/src/hooks/list-machine.ts +359 -0
  107. package/src/hooks/use-filtered-list.tsx +101 -112
  108. package/src/i18n/en.ts +6 -1
  109. package/src/icons/catalog.ts +8 -0
  110. package/src/navigation/menu/machine.ts +109 -0
  111. package/src/navigation/menu/menu.tsx +130 -22
  112. package/src/navigation/segmented-control/machine.ts +72 -0
  113. package/src/navigation/segmented-control/segmented-control.tsx +46 -46
  114. package/src/overlays/dialog/dialog.tsx +7 -1
  115. package/src/overlays/mcp-sign-in/machine.ts +343 -0
  116. package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
  117. package/src/overlays/tooltip/machine.ts +303 -0
  118. package/src/overlays/tooltip/tooltip.tsx +157 -92
  119. package/src/styles/theme.css +10 -2
  120. package/src/styles/tokens/theme.css +13 -0
  121. package/src/theme/context.tsx +192 -269
  122. package/src/theme/machine.ts +508 -0
  123. package/src/theme/themes/oc-2.json +2 -0
  124. package/src/theme/v2/mapping.ts +12 -8
  125. package/src/typography/text-shimmer/machine.ts +90 -0
  126. package/src/typography/text-shimmer/text-shimmer.css +71 -39
  127. package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
@@ -1,23 +1,37 @@
1
1
  import {
2
2
  For,
3
3
  Show,
4
+ createComputed,
4
5
  createEffect,
6
+ createMemo,
5
7
  createSignal,
6
8
  on,
7
9
  onCleanup,
8
10
  onMount,
9
11
  splitProps,
12
+ untrack,
10
13
  type ComponentProps,
11
14
  type JSX,
12
15
  } from "solid-js"
13
16
  import { FileIcon } from "@opencode/ui/file-icon"
14
17
  import { useI18n } from "../../context/i18n"
15
- import { useFilteredList } from "../../hooks"
16
18
  import { Button } from "@opencode/ui/button"
17
19
  import { Icon } from "@opencode/ui/icon"
18
20
  import { IconButton } from "@opencode/ui/icon-button"
19
21
  import { Keybind } from "@opencode/ui/keybind"
20
22
  import { Tooltip } from "@opencode/ui/tooltip"
23
+ import { Loader } from "@opencode/ui/loader"
24
+ import { makeEventListener } from "@solid-primitives/event-listener"
25
+ import {
26
+ createLineCommentEditorState,
27
+ MENTION_TIMEOUT_MS,
28
+ parseMentionToken,
29
+ transitionLineCommentEditor,
30
+ viewLineCommentEditor,
31
+ type LineCommentEditorConfig,
32
+ type LineCommentEditorEffect,
33
+ type LineCommentEditorEvent,
34
+ } from "./machine"
21
35
  import check from "./quote-check.svg"
22
36
  import "./line-comment.css"
23
37
 
@@ -100,6 +114,15 @@ export interface LineCommentEditorProps extends Omit<ComponentProps<"div">, "chi
100
114
  /** Submit an empty value too, such as to clear a comment that exists (default: false). Compact empty actions otherwise cancel. */
101
115
  allowEmpty?: boolean
102
116
  mention?: LineCommentEditorMention
117
+ /** Compact editor action on Mod+Enter or modifier-click. */
118
+ alternateSubmit?: {
119
+ label: string
120
+ keys: string[]
121
+ disabled?: boolean
122
+ onSubmit: (value: string) => void
123
+ }
124
+ /** Keep the draft read-only and prevent duplicate actions while its submission settles. */
125
+ submitting?: boolean
103
126
  }
104
127
 
105
128
  function pathFilename(path: string) {
@@ -117,7 +140,8 @@ function pathDirectory(path: string) {
117
140
  export function LineCommentEditor(props: LineCommentEditorProps) {
118
141
  const i18n = useI18n()
119
142
  let textareaRef: HTMLTextAreaElement | undefined
120
- const [mentionOpen, setMentionOpen] = createSignal(false)
143
+ let mentionTimer: ReturnType<typeof setTimeout> | undefined
144
+ const [editorState, setEditorState] = createSignal(createLineCommentEditorState())
121
145
 
122
146
  const [local, rest] = splitProps(props, [
123
147
  "label",
@@ -134,106 +158,139 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
134
158
  "autofocus",
135
159
  "allowEmpty",
136
160
  "mention",
161
+ "alternateSubmit",
162
+ "submitting",
137
163
  "class",
138
164
  "classList",
139
165
  ])
140
166
 
141
- const canSubmit = () => !!local.allowEmpty || local.value.trim().length > 0
142
- const compactCancel = () => !canSubmit()
167
+ const readConfig = (): LineCommentEditorConfig => ({
168
+ value: local.value,
169
+ allowEmpty: !!local.allowEmpty,
170
+ variant: local.variant ?? "default",
171
+ alternateSubmit: local.alternateSubmit ? { disabled: !!local.alternateSubmit.disabled } : null,
172
+ submitting: !!local.submitting,
173
+ })
143
174
 
144
- const compactLabel = () =>
145
- compactCancel()
146
- ? (local.cancelLabel ?? i18n.t("ui.lineComment.cancel"))
147
- : (local.submitLabel ?? i18n.t("ui.lineComment.submit"))
175
+ const view = createMemo(() => viewLineCommentEditor(editorState(), readConfig()))
148
176
 
149
- const closeMention = () => {
150
- setMentionOpen(false)
151
- mention.clear()
152
- }
177
+ const compactLabel = () =>
178
+ view().alternateActive
179
+ ? local.alternateSubmit!.label
180
+ : view().compactCancel
181
+ ? (local.cancelLabel ?? i18n.t("ui.lineComment.cancel"))
182
+ : (local.submitLabel ?? i18n.t("ui.lineComment.submit"))
153
183
 
154
- const currentMention = () => {
155
- const textarea = textareaRef
184
+ const currentToken = () =>
185
+ local.mention && textareaRef
186
+ ? parseMentionToken(textareaRef.value, textareaRef.selectionStart, textareaRef.selectionEnd)
187
+ : null
156
188
 
157
- if (!textarea) return
189
+ const dispatch = (event: LineCommentEditorEvent) => {
190
+ const transition = transitionLineCommentEditor(untrack(editorState), event)
191
+ setEditorState(transition.state)
158
192
 
159
- if (!local.mention) return
193
+ if (transition.state.status !== "mention-loading") clearTimeout(mentionTimer)
194
+ transition.effects.forEach(run)
160
195
 
161
- if (textarea.selectionStart !== textarea.selectionEnd) return
196
+ return transition.handled
197
+ }
162
198
 
163
- const end = textarea.selectionStart
164
- const match = textarea.value.slice(0, end).match(/@(\S*)$/)
199
+ const run = (effect: LineCommentEditorEffect) => {
200
+ if (effect.type === "mention.load") {
201
+ const attempt = effect.attempt
202
+ clearTimeout(mentionTimer)
203
+ mentionTimer = setTimeout(() => dispatch({ type: "mention.timeout", attempt }), MENTION_TIMEOUT_MS)
204
+ const result = untrack(() => local.mention?.items(effect.query) ?? [])
165
205
 
166
- if (!match) return
206
+ if (Array.isArray(result)) return dispatch({ type: "mention.loaded", attempt, items: result })
207
+ void result.then(
208
+ (items) => dispatch({ type: "mention.loaded", attempt, items }),
209
+ () => dispatch({ type: "mention.failed", attempt }),
210
+ )
167
211
 
168
- return {
169
- query: match[1] ?? "",
170
- start: end - match[0].length,
171
- end,
212
+ return
172
213
  }
173
- }
174
214
 
175
- function selectMention(item: { path: string } | undefined) {
176
- if (!item) return
215
+ if (effect.type === "mention.insert") {
216
+ const textarea = textareaRef
177
217
 
178
- const textarea = textareaRef
179
- const query = currentMention()
218
+ if (!textarea) return
219
+ const value = `${textarea.value.slice(0, effect.token.start)}@${effect.path} ${textarea.value.slice(effect.token.end)}`
220
+ const cursor = effect.token.start + effect.path.length + 2
221
+ local.onInput(value)
222
+ requestAnimationFrame(() => {
223
+ if (untrack(editorState).status === "disposed") return
224
+ textarea.focus()
225
+ textarea.setSelectionRange(cursor, cursor)
226
+ })
180
227
 
181
- if (!textarea || !query) return
228
+ return
229
+ }
182
230
 
183
- const value = `${textarea.value.slice(0, query.start)}@${item.path} ${textarea.value.slice(query.end)}`
184
- const cursor = query.start + item.path.length + 2
231
+ if (effect.type === "submit") {
232
+ if (effect.mode === "alternate") return local.alternateSubmit?.onSubmit(effect.value)
185
233
 
186
- local.onInput(value)
187
- closeMention()
234
+ return local.onSubmit(effect.value)
235
+ }
188
236
 
189
- requestAnimationFrame(() => {
190
- textarea.focus()
191
- textarea.setSelectionRange(cursor, cursor)
192
- })
237
+ if (effect.blur) textareaRef?.blur()
238
+ local.onCancel()
193
239
  }
194
240
 
195
- const mention = useFilteredList<{ path: string }>({
196
- items: async (query) => {
197
- if (!local.mention) return []
241
+ const keyEvent = (event: KeyboardEvent, target: "textarea" | "action") =>
242
+ dispatch({
243
+ type: "key.down",
244
+ target,
245
+ key: event.key,
246
+ ctrl: event.ctrlKey,
247
+ meta: event.metaKey,
248
+ alt: event.altKey,
249
+ shift: event.shiftKey,
250
+ repeat: event.repeat,
251
+ config: readConfig(),
252
+ })
198
253
 
199
- if (!query.trim()) return []
200
- const paths = await local.mention.items(query)
254
+ createComputed(
255
+ on(
256
+ [
257
+ () => local.submitting,
258
+ () => local.variant,
259
+ () => local.allowEmpty,
260
+ () => !!local.mention,
261
+ () => local.alternateSubmit?.disabled,
262
+ () => !!local.alternateSubmit,
263
+ ],
264
+ () => dispatch({ type: "props.synced", config: readConfig(), token: currentToken() }),
265
+ ),
266
+ )
201
267
 
202
- return paths.map((path) => ({ path }))
203
- },
204
- key: (item) => item.path,
205
- filterKeys: ["path"],
206
- skipFilter: () => true,
207
- onSelect: selectMention,
208
- })
268
+ // An owner that resets or rewrites the value closes a mention list the new text no longer has.
269
+ createEffect(
270
+ on(
271
+ () => local.value,
272
+ () => dispatch({ type: "props.synced", config: readConfig(), token: currentToken() }),
273
+ { defer: true },
274
+ ),
275
+ )
209
276
 
210
- const syncMention = () => {
211
- const item = currentMention()
277
+ onCleanup(() => dispatch({ type: "disposed" }))
212
278
 
213
- if (!item) {
214
- closeMention()
279
+ const trackModifiers = createMemo(() => view().trackModifiers)
215
280
 
216
- return
217
- }
218
-
219
- setMentionOpen(true)
220
- mention.onInput(item.query)
221
- }
281
+ createEffect(() => {
282
+ if (!trackModifiers()) return
222
283
 
223
- const selectActiveMention = () => {
224
- const items = mention.flat()
284
+ const update = (event: KeyboardEvent) =>
285
+ dispatch({ type: "modifier.changed", active: modified(event), config: readConfig() })
225
286
 
226
- if (items.length === 0) return
227
- const active = mention.active()
228
- selectMention(items.find((item) => item.path === active) ?? items[0])
229
- }
287
+ // Capture modifier releases; the textarea stops key propagation.
288
+ makeEventListener(document, "keydown", update, { capture: true })
289
+ makeEventListener(document, "keyup", update, { capture: true })
290
+ makeEventListener(window, "blur", () => dispatch({ type: "window.blurred" }))
291
+ })
230
292
 
231
- const submit = () => {
232
- const v = local.value.trim()
233
-
234
- if (!v && !local.allowEmpty) return
235
- local.onSubmit(v)
236
- }
293
+ const syncMention = () => dispatch({ type: "mention.synced", token: currentToken() })
237
294
 
238
295
  onMount(() => {
239
296
  if (local.autofocus === false) return
@@ -278,6 +335,7 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
278
335
  data-component="line-comment-v2"
279
336
  data-variant="editor"
280
337
  data-layout={local.variant ?? "default"}
338
+ aria-busy={view().submitting || undefined}
281
339
  classList={{
282
340
  ...local.classList,
283
341
  [local.class ?? ""]: !!local.class,
@@ -294,12 +352,15 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
294
352
  textareaRef = el
295
353
  }}
296
354
  data-slot="line-comment-v2-textarea"
355
+ // Escape here closes the mention list or cancels the comment, not a dialog or popover around the editor.
356
+ data-owns-escape
297
357
  data-scrollable
298
358
  aria-label={local.label ?? i18n.t("ui.lineComment.submit")}
299
359
  dir="auto"
300
360
  rows={local.rows ?? (local.variant === "compact" ? 1 : 4)}
301
361
  placeholder={local.placeholder ?? i18n.t("ui.lineComment.contextPlaceholder")}
302
362
  value={local.value}
363
+ readOnly={view().submitting}
303
364
  style={{ "unicode-bidi": "plaintext", "text-align": "start" }}
304
365
  onInput={(e) => {
305
366
  local.onInput(e.currentTarget.value)
@@ -312,66 +373,26 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
312
373
 
313
374
  if (e.isComposing || e.keyCode === 229) return
314
375
 
315
- if (mentionOpen()) {
316
- if (e.key === "Escape") {
317
- e.preventDefault()
318
- closeMention()
319
-
320
- return
321
- }
322
-
323
- if (e.key === "Tab") {
324
- if (mention.flat().length === 0) return
325
- e.preventDefault()
326
- selectActiveMention()
327
-
328
- return
329
- }
330
-
331
- const nav = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "Enter"
332
-
333
- const ctrlNav =
334
- e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey && (e.key === "n" || e.key === "p")
335
-
336
- if ((nav || ctrlNav) && mention.flat().length > 0) {
337
- mention.onKeyDown(e)
338
- e.preventDefault()
339
-
340
- return
341
- }
342
- }
343
-
344
- if (e.key === "Escape") {
345
- e.preventDefault()
346
- e.currentTarget.blur()
347
- local.onCancel()
348
-
349
- return
350
- }
351
-
352
- if (e.key === "Enter" && !e.shiftKey) {
353
- e.preventDefault()
354
- submit()
355
- }
376
+ if (keyEvent(e, "textarea")) e.preventDefault()
356
377
  }}
357
378
  />
358
- <Show when={mentionOpen() && mention.flat().length > 0}>
379
+ <Show when={view().mentionItems.length > 0}>
359
380
  <div data-slot="line-comment-v2-mention-list">
360
- <For each={mention.flat().slice(0, 10)}>
361
- {(item) => {
362
- const directory = item.path.endsWith("/") ? item.path : pathDirectory(item.path)
363
- const name = item.path.endsWith("/") ? "" : pathFilename(item.path)
381
+ <For each={view().mentionItems}>
382
+ {(path, index) => {
383
+ const directory = path.endsWith("/") ? path : pathDirectory(path)
384
+ const name = path.endsWith("/") ? "" : pathFilename(path)
364
385
 
365
386
  return (
366
387
  <button
367
388
  type="button"
368
389
  data-slot="line-comment-v2-mention-item"
369
- data-active={mention.active() === item.path ? "" : undefined}
390
+ data-active={view().activeMentionPath === path ? "" : undefined}
370
391
  onMouseDown={(event) => event.preventDefault()}
371
- onMouseEnter={() => mention.setActive(item.path)}
372
- onClick={() => selectMention(item)}
392
+ onMouseEnter={() => dispatch({ type: "mention.hovered", index: index() })}
393
+ onClick={() => dispatch({ type: "mention.selected", index: index() })}
373
394
  >
374
- <FileIcon node={{ path: item.path, type: "file" }} class="shrink-0 size-4" />
395
+ <FileIcon node={{ path, type: "file" }} class="shrink-0 size-4" />
375
396
  <div data-slot="line-comment-v2-mention-path">
376
397
  <span data-slot="line-comment-v2-mention-dir">{directory}</span>
377
398
  <Show when={name}>
@@ -388,19 +409,37 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
388
409
  <Show when={local.variant === "compact"}>
389
410
  <Tooltip
390
411
  value={
391
- <>
392
- {compactLabel()} <Keybind keys={[compactCancel() ? "Esc" : "⏎"]} variant="neutral" />
393
- </>
412
+ <div class="flex flex-col gap-1.5">
413
+ <div class="flex items-center gap-1.5">
414
+ {compactLabel()}
415
+ <Keybind
416
+ keys={view().alternateActive ? local.alternateSubmit!.keys : [view().compactCancel ? "Esc" : "⏎"]}
417
+ variant="neutral"
418
+ />
419
+ </div>
420
+ <Show when={local.alternateSubmit && !view().alternateActive}>
421
+ <div class="flex items-center gap-1.5">
422
+ {local.alternateSubmit!.label}
423
+ <Keybind keys={local.alternateSubmit!.keys} variant="neutral" />
424
+ </div>
425
+ </Show>
426
+ </div>
394
427
  }
395
428
  placement="top"
396
429
  >
397
430
  <IconButton
398
431
  data-slot="line-comment-v2-submit"
432
+ data-owns-escape
399
433
  type="button"
400
434
  size="small"
401
- variant={local.value.trim() ? "neutral" : "ghost-muted"}
435
+ variant={view().compactVariant}
436
+ disabled={view().compactDisabled}
402
437
  icon={
403
- compactCancel() ? (
438
+ view().submitting ? (
439
+ <Loader />
440
+ ) : view().alternateActive ? (
441
+ <Icon name="arrow-up" />
442
+ ) : view().compactCancel ? (
404
443
  <Icon name="close" />
405
444
  ) : (
406
445
  <span
@@ -411,12 +450,21 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
411
450
  )
412
451
  }
413
452
  aria-label={compactLabel()}
414
- onClick={() => (compactCancel() ? local.onCancel() : submit())}
453
+ onPointerEnter={(event) =>
454
+ dispatch({ type: "modifier.changed", active: modified(event), config: readConfig() })
455
+ }
456
+ onPointerDown={(event) =>
457
+ dispatch({ type: "modifier.changed", active: modified(event), config: readConfig() })
458
+ }
459
+ onClick={(event) =>
460
+ dispatch({ type: "action.clicked", modified: modified(event), config: readConfig() })
461
+ }
415
462
  onKeyDown={(event) => {
416
- if (event.key !== "Escape" || event.isComposing) return
463
+ if (event.isComposing) return
464
+
465
+ if (!keyEvent(event, "action")) return
417
466
  event.preventDefault()
418
467
  event.stopPropagation()
419
- local.onCancel()
420
468
  }}
421
469
  />
422
470
  </Tooltip>
@@ -428,10 +476,22 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
428
476
  {(selection) => <div data-slot="line-comment-v2-footer-meta">{selection()}</div>}
429
477
  </Show>
430
478
  <div data-slot="line-comment-v2-footer-actions">
431
- <Button type="button" size="small" variant="ghost" onClick={() => local.onCancel()}>
479
+ <Button
480
+ type="button"
481
+ size="small"
482
+ variant="ghost"
483
+ disabled={view().submitting}
484
+ onClick={() => dispatch({ type: "cancel.requested" })}
485
+ >
432
486
  {local.cancelLabel ?? i18n.t("ui.lineComment.cancel")}
433
487
  </Button>
434
- <Button type="button" size="small" variant="contrast" disabled={!canSubmit()} onClick={submit}>
488
+ <Button
489
+ type="button"
490
+ size="small"
491
+ variant="contrast"
492
+ disabled={!view().canSubmit || view().submitting}
493
+ onClick={() => dispatch({ type: "submit.requested", config: readConfig() })}
494
+ >
435
495
  {local.submitLabel ?? i18n.t("ui.lineComment.submit")}
436
496
  </Button>
437
497
  </div>
@@ -441,3 +501,7 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
441
501
  </div>
442
502
  )
443
503
  }
504
+
505
+ function modified(event: Pick<KeyboardEvent, "metaKey" | "ctrlKey" | "altKey" | "shiftKey">) {
506
+ return (event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey
507
+ }