@adea-ai/ui 0.151.0 → 0.151.7

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 (47) hide show
  1. package/README.md +5 -0
  2. package/dist/components/composites/action-button/action-button.d.ts.map +1 -1
  3. package/dist/components/composites/action-button/action-button.js +8 -2
  4. package/dist/components/composites/action-button/action-button.js.map +1 -1
  5. package/dist/components/composites/inline-citation/inline-citation.d.ts.map +1 -1
  6. package/dist/components/composites/inline-citation/inline-citation.js +39 -36
  7. package/dist/components/composites/inline-citation/inline-citation.js.map +1 -1
  8. package/dist/components/conversation/internal/chat-composer-shell.d.ts.map +1 -1
  9. package/dist/components/conversation/internal/chat-composer-shell.js +28 -4
  10. package/dist/components/conversation/internal/chat-composer-shell.js.map +1 -1
  11. package/dist/components/conversation/paste-token-editor.d.ts.map +1 -1
  12. package/dist/components/conversation/paste-token-editor.js +127 -37
  13. package/dist/components/conversation/paste-token-editor.js.map +1 -1
  14. package/dist/components/conversation/scroll-follow-core.d.ts +13 -0
  15. package/dist/components/conversation/scroll-follow-core.d.ts.map +1 -1
  16. package/dist/components/conversation/scroll-follow-core.js +12 -1
  17. package/dist/components/conversation/scroll-follow-core.js.map +1 -1
  18. package/dist/components/conversation/scroll-follow.d.ts.map +1 -1
  19. package/dist/components/conversation/scroll-follow.js +52 -21
  20. package/dist/components/conversation/scroll-follow.js.map +1 -1
  21. package/dist/components/ui/calendar/calendar.d.ts.map +1 -1
  22. package/dist/components/ui/calendar/calendar.js +109 -115
  23. package/dist/components/ui/calendar/calendar.js.map +1 -1
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -1
  27. package/dist/r/appearance-editor.json +1 -1
  28. package/dist/r/lib.json +1 -1
  29. package/dist/r/registry.json +3 -3
  30. package/dist/r/src/components/composites/action-button/action-button.tsx +11 -1
  31. package/dist/r/src/components/composites/inline-citation/inline-citation.tsx +112 -105
  32. package/dist/r/src/components/conversation/internal/chat-composer-shell.tsx +36 -2
  33. package/dist/r/src/components/conversation/paste-token-editor.tsx +191 -49
  34. package/dist/r/src/components/conversation/scroll-follow-core.ts +23 -0
  35. package/dist/r/src/components/conversation/scroll-follow.ts +69 -17
  36. package/dist/r/src/components/ui/calendar/calendar.tsx +99 -104
  37. package/dist/r/theming.json +1 -1
  38. package/package.json +9 -3
  39. package/registry.json +3 -3
  40. package/src/components/composites/action-button/action-button.tsx +11 -1
  41. package/src/components/composites/inline-citation/inline-citation.tsx +112 -105
  42. package/src/components/conversation/internal/chat-composer-shell.tsx +36 -2
  43. package/src/components/conversation/paste-token-editor.tsx +191 -49
  44. package/src/components/conversation/scroll-follow-core.ts +23 -0
  45. package/src/components/conversation/scroll-follow.ts +69 -17
  46. package/src/components/ui/calendar/calendar.tsx +99 -104
  47. package/src/index.ts +1 -0
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  Show,
3
+ createRoot,
3
4
  createSignal,
4
5
  splitProps,
5
6
  type ComponentProps,
@@ -66,7 +67,16 @@ function guardedClick(
66
67
  onActivate: (event: MouseEvent) => void = () => {}
67
68
  ) {
68
69
  return (event: MouseEvent) => {
69
- if (disabled()) {
70
+ // A polymorphic trigger can provide a getter that creates reactive work.
71
+ // Event callbacks have no owner, so dispose any such work after the read.
72
+ const isDisabled = createRoot((dispose) => {
73
+ try {
74
+ return disabled()
75
+ } finally {
76
+ dispose()
77
+ }
78
+ })
79
+ if (isDisabled) {
70
80
  event.preventDefault()
71
81
  event.stopImmediatePropagation()
72
82
  return
@@ -157,116 +157,123 @@ export function InlineCitation(props: InlineCitationProps) {
157
157
  if (wasPeeking) queueMicrotask(() => content?.focus())
158
158
  }
159
159
 
160
+ // The badge and the popover's portal marker share one wrapper. Without it they
161
+ // are loose siblings in the host's node list, and when the portal marker comes
162
+ // and goes as the card opens and closes, a host that renders its inline nodes
163
+ // as one array (MessageText) reconciles that array and can move the badge,
164
+ // which drops keyboard focus to <body> on the badge the reader just reached.
160
165
  return (
161
166
  <Show when={count() > 0}>
162
- <Popover
163
- open={mode() !== 'closed'}
164
- onOpenChange={(next) => {
165
- if (!next && !pressing) dispatch('dismiss')
166
- }}
167
- placement="bottom"
168
- gutter={6}
169
- >
170
- <PopoverTrigger
171
- as={Button}
172
- variant="subtle"
173
- size="2xs"
174
- touchTarget="comfortable"
175
- data-slot="inline-citation"
176
- aria-label={citationName(local.sources, local.index)}
177
- class={cn('mx-0.5 align-baseline tabular-nums', local.class)}
178
- onClick={onClick}
179
- onPointerEnter={onPointerEnter}
180
- onPointerLeave={onPointerLeave}
181
- onFocus={(event: FocusEvent & { currentTarget: HTMLElement }) => {
182
- // Mouse focus follows the press; only keyboard focus peeks.
183
- if (restoringFocus) return
184
- if (event.currentTarget.matches(':focus-visible')) dispatch('focus')
167
+ <span data-slot="inline-citation-root">
168
+ <Popover
169
+ open={mode() !== 'closed'}
170
+ onOpenChange={(next) => {
171
+ if (!next && !pressing) dispatch('dismiss')
185
172
  }}
186
- onBlur={() => dispatch('blur')}
173
+ placement="bottom"
174
+ gutter={6}
187
175
  >
188
- <span aria-hidden="true" class="max-w-32 truncate">
189
- {citationLabel(local.index, local.sources[0])}
190
- </span>
191
- <Show when={count() > 1}>
192
- <span aria-hidden="true">+{count() - 1}</span>
193
- </Show>
194
- </PopoverTrigger>
195
- <PopoverContent
196
- ref={(element: HTMLElement) => (content = element)}
197
- inert={keyboardPeek() || mode() === 'closed' || undefined}
198
- class="w-72 max-w-full"
199
- onOpenAutoFocus={(event: Event) => {
200
- if (mode() === 'peek') event.preventDefault()
201
- }}
202
- onFocusIn={() => {
203
- focusInCard = true
204
- }}
205
- onKeyDown={(event: KeyboardEvent) => {
206
- if (event.key !== 'Escape' || escapeClosedTooltip || mode() !== 'pinned') return
207
- dispatch('dismiss')
208
- }}
209
- onCloseAutoFocus={(event: Event) => {
210
- const returnFocus = focusInCard
211
- focusInCard = false
212
- if (!returnFocus) {
213
- event.preventDefault()
214
- return
215
- }
216
- // The focus move that follows is synchronous; the microtask ends the window.
217
- restoringFocus = true
218
- queueMicrotask(() => {
219
- restoringFocus = false
220
- })
221
- }}
222
- onPointerEnter={(event: PointerEvent) => {
223
- if (event.pointerType !== 'touch') clear()
224
- }}
225
- onPointerLeave={onPointerLeave}
226
- >
227
- <Show when={active()}>
228
- {(source) => (
229
- <div class="flex min-w-0 flex-col gap-1.5 px-2 py-1.5">
230
- <Show when={count() > 1}>
231
- <div class="flex items-center justify-between gap-2">
232
- <span
233
- role="status"
234
- aria-live="polite"
235
- class="text-xs text-muted-foreground tabular-nums"
236
- >
237
- Source {wrapIndex(position(), count()) + 1} of {count()}
238
- </span>
239
- <span class="flex items-center gap-0.5">
240
- <ActionButton
241
- variant="ghost"
242
- size="icon-xs"
243
- aria-label="Previous source"
244
- tooltip="Previous source"
245
- onClick={() => setPosition((value) => wrapIndex(value - 1, count()))}
246
- >
247
- <ChevronLeft />
248
- </ActionButton>
249
- <ActionButton
250
- variant="ghost"
251
- size="icon-xs"
252
- aria-label="Next source"
253
- tooltip="Next source"
254
- onClick={() => setPosition((value) => wrapIndex(value + 1, count()))}
176
+ <PopoverTrigger
177
+ as={Button}
178
+ variant="subtle"
179
+ size="2xs"
180
+ touchTarget="comfortable"
181
+ data-slot="inline-citation"
182
+ aria-label={citationName(local.sources, local.index)}
183
+ class={cn('mx-0.5 align-baseline tabular-nums', local.class)}
184
+ onClick={onClick}
185
+ onPointerEnter={onPointerEnter}
186
+ onPointerLeave={onPointerLeave}
187
+ onFocus={(event: FocusEvent & { currentTarget: HTMLElement }) => {
188
+ // Mouse focus follows the press; only keyboard focus peeks.
189
+ if (restoringFocus) return
190
+ if (event.currentTarget.matches(':focus-visible')) dispatch('focus')
191
+ }}
192
+ onBlur={() => dispatch('blur')}
193
+ >
194
+ <span aria-hidden="true" class="max-w-32 truncate">
195
+ {citationLabel(local.index, local.sources[0])}
196
+ </span>
197
+ <Show when={count() > 1}>
198
+ <span aria-hidden="true">+{count() - 1}</span>
199
+ </Show>
200
+ </PopoverTrigger>
201
+ <PopoverContent
202
+ ref={(element: HTMLElement) => (content = element)}
203
+ inert={keyboardPeek() || mode() === 'closed' || undefined}
204
+ class="w-72 max-w-full"
205
+ onOpenAutoFocus={(event: Event) => {
206
+ if (mode() === 'peek') event.preventDefault()
207
+ }}
208
+ onFocusIn={() => {
209
+ focusInCard = true
210
+ }}
211
+ onKeyDown={(event: KeyboardEvent) => {
212
+ if (event.key !== 'Escape' || escapeClosedTooltip || mode() !== 'pinned') return
213
+ dispatch('dismiss')
214
+ }}
215
+ onCloseAutoFocus={(event: Event) => {
216
+ const returnFocus = focusInCard
217
+ focusInCard = false
218
+ if (!returnFocus) {
219
+ event.preventDefault()
220
+ return
221
+ }
222
+ // The focus move that follows is synchronous; the microtask ends the window.
223
+ restoringFocus = true
224
+ queueMicrotask(() => {
225
+ restoringFocus = false
226
+ })
227
+ }}
228
+ onPointerEnter={(event: PointerEvent) => {
229
+ if (event.pointerType !== 'touch') clear()
230
+ }}
231
+ onPointerLeave={onPointerLeave}
232
+ >
233
+ <Show when={active()}>
234
+ {(source) => (
235
+ <div class="flex min-w-0 flex-col gap-1.5 px-2 py-1.5">
236
+ <Show when={count() > 1}>
237
+ <div class="flex items-center justify-between gap-2">
238
+ <span
239
+ role="status"
240
+ aria-live="polite"
241
+ class="text-xs text-muted-foreground tabular-nums"
255
242
  >
256
- <ChevronRight />
257
- </ActionButton>
258
- </span>
259
- </div>
260
- </Show>
261
- <PopoverTitle class="p-0 [overflow-wrap:anywhere]">
262
- {sourceTitle(source())}
263
- </PopoverTitle>
264
- <CitationDetails source={source()} />
265
- </div>
266
- )}
267
- </Show>
268
- </PopoverContent>
269
- </Popover>
243
+ Source {wrapIndex(position(), count()) + 1} of {count()}
244
+ </span>
245
+ <span class="flex items-center gap-0.5">
246
+ <ActionButton
247
+ variant="ghost"
248
+ size="icon-xs"
249
+ aria-label="Previous source"
250
+ tooltip="Previous source"
251
+ onClick={() => setPosition((value) => wrapIndex(value - 1, count()))}
252
+ >
253
+ <ChevronLeft />
254
+ </ActionButton>
255
+ <ActionButton
256
+ variant="ghost"
257
+ size="icon-xs"
258
+ aria-label="Next source"
259
+ tooltip="Next source"
260
+ onClick={() => setPosition((value) => wrapIndex(value + 1, count()))}
261
+ >
262
+ <ChevronRight />
263
+ </ActionButton>
264
+ </span>
265
+ </div>
266
+ </Show>
267
+ <PopoverTitle class="p-0 [overflow-wrap:anywhere]">
268
+ {sourceTitle(source())}
269
+ </PopoverTitle>
270
+ <CitationDetails source={source()} />
271
+ </div>
272
+ )}
273
+ </Show>
274
+ </PopoverContent>
275
+ </Popover>
276
+ </span>
270
277
  </Show>
271
278
  )
272
279
  }
@@ -72,6 +72,7 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
72
72
  const [error, setError] = createSignal<string | null>(null)
73
73
  let field: HTMLTextAreaElement | undefined
74
74
  let restoreBar: HTMLButtonElement | undefined
75
+ let root: HTMLDivElement | undefined
75
76
  let focusFrame: number | undefined
76
77
  let focusTarget: 'input' | 'bar' | undefined
77
78
  let selection:
@@ -89,9 +90,24 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
89
90
  const requestFocus = (target: 'input' | 'bar') => {
90
91
  cancelFocus()
91
92
  focusTarget = target
93
+ const requester = document.activeElement
92
94
  focusFrame = requestAnimationFrame(() => {
93
95
  focusFrame = undefined
94
96
  if (!active || props.approvalFocus) return
97
+ // Focus that moved elsewhere since the request (another conversation,
98
+ // say, while a collapse or expand waited for this frame) is a newer
99
+ // owner; taking it back would also drop whatever is being typed there.
100
+ const current = document.activeElement
101
+ if (
102
+ current &&
103
+ current !== document.body &&
104
+ current !== requester &&
105
+ !root?.contains(current)
106
+ ) {
107
+ focusTarget = undefined
108
+ if (target === 'input') selection = undefined
109
+ return
110
+ }
95
111
  if (target === 'bar' && collapsed()) restoreBar?.focus()
96
112
  if (target === 'input' && !collapsed() && !props.disabled && field) {
97
113
  field.focus()
@@ -105,6 +121,16 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
105
121
  focusTarget = undefined
106
122
  })
107
123
  }
124
+ /**
125
+ * A press or key in the input before the deferred expand restore runs is a
126
+ * newer selection owner: the restore must not move its caret back.
127
+ */
128
+ const yieldInputRestore = () => {
129
+ if (focusTarget !== 'input') return
130
+ cancelFocus()
131
+ focusTarget = undefined
132
+ selection = undefined
133
+ }
108
134
  const changeCollapsed = (value: boolean) => {
109
135
  if (!props.collapse || props.approvalFocus) return
110
136
  if (value && field)
@@ -183,6 +209,7 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
183
209
  return first.length > 120 ? `${first.slice(0, 120)}…` : first
184
210
  }
185
211
  const handleInputKeyDown = (event: KeyboardEvent) => {
212
+ yieldInputRestore()
186
213
  if (event.key === 'Escape' && error()) {
187
214
  setError(null)
188
215
  return
@@ -211,7 +238,11 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
211
238
  ime.onBlur()
212
239
  }
213
240
  return (
214
- <div data-slot="chat-composer" class="mx-auto flex w-full max-w-4xl flex-col px-4 pb-1">
241
+ <div
242
+ ref={(element) => (root = element)}
243
+ data-slot="chat-composer"
244
+ class="mx-auto flex w-full max-w-4xl flex-col px-4 pb-1"
245
+ >
215
246
  <Show when={!props.approvalFocus}>
216
247
  <Show when={props.knowledge}>
217
248
  <div data-slot="composer-knowledge">{props.knowledge}</div>
@@ -287,10 +318,13 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
287
318
  {props.renderInput({
288
319
  ref: (element) => {
289
320
  field = element
290
- if (element)
321
+ if (element) {
322
+ element.addEventListener('pointerdown', yieldInputRestore)
291
323
  onCleanup(() => {
324
+ element.removeEventListener('pointerdown', yieldInputRestore)
292
325
  if (field === element) field = undefined
293
326
  })
327
+ }
294
328
  },
295
329
  value: () => props.value,
296
330
  resetKey: () => props.resetKey,