@meistrari/tela-build 1.75.1 → 1.76.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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Latest updates and announcements.
4
4
 
5
+ ## September 24, 2026
6
+
7
+ - [Floating chat](/templates/chat#floating) adds `keepMounted` (default `false`); set it to `true` to hide the window on close instead of unmounting it, so polling and other work inside it keep running.
8
+
5
9
  ## September 22, 2026
6
10
 
7
11
  - [Prompt Input](/templates/chat#prompt-input) adapts to its shell: inside `TelaChatFloatingWindow` and `TelaChatSidepanelWindow` it uses a 12px radius and 8px right padding, and the action menu trigger stays inline. On full-page chats it keeps the 16px radius and pulls the trigger flush with the editor.
@@ -147,6 +147,8 @@ A launcher pill fixed to the bottom-right corner opens the chat in an anchored p
147
147
 
148
148
  The window opens over its own launcher: the surface springs out of the launcher's box (and shrinks back into it on close) while the conversation is revealed in place, pinned to the shared bottom-right corner. The launcher fades out while the window is open and returns as the surface settles. The scroll lock is released only after the exit finishes, so the scrollbar coming back never shifts the window mid-animation.
149
149
 
150
+ By default, closing unmounts the content. Set `keepMounted` to hide it instead after the first open, so background work inside, like chat polling, keeps running and the conversation keeps its state. Nothing mounts until the first open.
151
+
150
152
  The widget header inside the window gets two extra actions automatically: **expand** grows the window until 8px from the top of the viewport (and back), and **minimize** closes it. See [Widget Header & History](#widget-header--history).
151
153
 
152
154
  ```vue
@@ -1511,6 +1513,7 @@ type FloatingWindowProps = {
1511
1513
  open: boolean
1512
1514
  contained?: boolean // anchor the launcher to the nearest positioned ancestor instead of the viewport
1513
1515
  triggerLabel?: string // label of the default trigger; ignored when #launcher is provided
1516
+ keepMounted?: boolean // defaults to false; keeps the content mounted (hidden) after the first open
1514
1517
  }
1515
1518
  // emits: update:open(value: boolean)
1516
1519
 
@@ -0,0 +1,182 @@
1
+ // @vitest-environment happy-dom
2
+ import { mount } from '@vue/test-utils'
3
+ import { PopoverRoot, PopoverTrigger } from 'reka-ui'
4
+ import { computed, defineComponent, h, nextTick, onBeforeUnmount, onMounted, onUnmounted, provide, ref, watch } from 'vue'
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
6
+ import TelaPopoverContent from '../../popover/popover-content.vue'
7
+ import FloatingWindow from './floating-window.vue'
8
+
9
+ const cn = (...values: unknown[]) => values.filter(Boolean).join(' ')
10
+
11
+ vi.stubGlobal('cn', cn)
12
+ vi.stubGlobal('computed', computed)
13
+ vi.stubGlobal('nextTick', nextTick)
14
+ vi.stubGlobal('onBeforeUnmount', onBeforeUnmount)
15
+ vi.stubGlobal('onMounted', onMounted)
16
+ vi.stubGlobal('provide', provide)
17
+ vi.stubGlobal('ref', ref)
18
+ vi.stubGlobal('watch', watch)
19
+
20
+ const lifecycle = { mounted: 0, unmounted: 0 }
21
+ const mounted: Array<{ unmount: () => void }> = []
22
+
23
+ const ChatBody = defineComponent({
24
+ setup() {
25
+ onMounted(() => lifecycle.mounted++)
26
+ onUnmounted(() => lifecycle.unmounted++)
27
+
28
+ return () => h('div', { 'data-chat-prompt-input': '' }, [h('textarea', { 'data-testid': 'editor' })])
29
+ },
30
+ })
31
+
32
+ function mountWindow(props: { open: boolean, keepMounted?: boolean }) {
33
+ const wrapper = mount(FloatingWindow, {
34
+ props,
35
+ slots: { default: () => h(ChatBody) },
36
+ attachTo: document.body,
37
+ global: {
38
+ mocks: { cn },
39
+ components: {
40
+ TelaPopover: PopoverRoot,
41
+ TelaPopoverTrigger: PopoverTrigger,
42
+ TelaPopoverContent,
43
+ },
44
+ stubs: {
45
+ Motion: defineComponent({ setup: (_, { slots }) => () => h('div', slots.default?.()) }),
46
+ TelaChatFloatingWindowTrigger: defineComponent({ setup: () => () => h('button', { 'data-testid': 'launcher' }) }),
47
+ },
48
+ },
49
+ })
50
+
51
+ mounted.push(wrapper)
52
+
53
+ return wrapper
54
+ }
55
+
56
+ function content() {
57
+ return document.querySelector<HTMLElement>('.widget-popover')
58
+ }
59
+
60
+ describe('floating chat window', () => {
61
+ beforeEach(() => {
62
+ vi.useFakeTimers()
63
+ lifecycle.mounted = 0
64
+ lifecycle.unmounted = 0
65
+ })
66
+
67
+ afterEach(() => {
68
+ mounted.splice(0).forEach(wrapper => wrapper.unmount())
69
+ vi.useRealTimers()
70
+ document.body.innerHTML = ''
71
+ })
72
+
73
+ it('does not mount the content before the first open', () => {
74
+ // Arrange & Act
75
+ mountWindow({ open: false, keepMounted: true })
76
+
77
+ // Assert
78
+ expect(content()).toBeNull()
79
+ expect(lifecycle.mounted).toBe(0)
80
+ })
81
+
82
+ it('keeps the content mounted and hides it after the exit animation', async () => {
83
+ // Arrange
84
+ const wrapper = mountWindow({ open: true, keepMounted: true })
85
+ await nextTick()
86
+
87
+ // Act
88
+ await wrapper.setProps({ open: false })
89
+ const hiddenDuringExit = content()?.hasAttribute('data-content-hidden')
90
+ vi.advanceTimersByTime(380)
91
+ await nextTick()
92
+
93
+ // Assert
94
+ expect(hiddenDuringExit).toBe(false)
95
+ expect(content()?.dataset.state).toBe('closed')
96
+ expect(content()?.hasAttribute('data-content-hidden')).toBe(true)
97
+ expect(lifecycle).toEqual({ mounted: 1, unmounted: 0 })
98
+ })
99
+
100
+ it('reuses the same content instance when reopened', async () => {
101
+ // Arrange
102
+ const wrapper = mountWindow({ open: true, keepMounted: true })
103
+ await nextTick()
104
+ await wrapper.setProps({ open: false })
105
+ vi.advanceTimersByTime(380)
106
+ await nextTick()
107
+ await nextTick()
108
+
109
+ // Act
110
+ await wrapper.setProps({ open: true })
111
+ await nextTick()
112
+
113
+ // Assert
114
+ expect(content()?.dataset.state).toBe('open')
115
+ expect(content()?.hasAttribute('data-content-hidden')).toBe(false)
116
+ expect(lifecycle).toEqual({ mounted: 1, unmounted: 0 })
117
+ })
118
+
119
+ it('returns focus to the launcher when closing from inside', async () => {
120
+ // Arrange
121
+ const wrapper = mountWindow({ open: true, keepMounted: true })
122
+ await nextTick()
123
+ document.querySelector<HTMLElement>('[data-testid="editor"]')?.focus()
124
+
125
+ // Act
126
+ await wrapper.setProps({ open: false })
127
+
128
+ // Assert
129
+ expect(document.activeElement?.getAttribute('data-testid')).toBe('launcher')
130
+ })
131
+
132
+ it('focuses the editor when reopened', async () => {
133
+ // Arrange
134
+ const wrapper = mountWindow({ open: true, keepMounted: true })
135
+ await nextTick()
136
+ await wrapper.setProps({ open: false })
137
+ vi.advanceTimersByTime(380)
138
+ await nextTick()
139
+ const outside = document.body.appendChild(document.createElement('button'))
140
+ outside.focus()
141
+
142
+ // Act
143
+ await wrapper.setProps({ open: true })
144
+ await nextTick()
145
+
146
+ // Assert
147
+ expect(document.activeElement?.getAttribute('data-testid')).toBe('editor')
148
+ })
149
+
150
+ it('does not re-emit a close while already closed', async () => {
151
+ // Arrange
152
+ const wrapper = mountWindow({ open: true, keepMounted: true })
153
+ await nextTick()
154
+ await wrapper.setProps({ open: false })
155
+ vi.advanceTimersByTime(380)
156
+ await nextTick()
157
+ await nextTick()
158
+
159
+ // Act
160
+ document.body.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
161
+ await nextTick()
162
+
163
+ // Assert
164
+ expect(wrapper.emitted('update:open')).toBeUndefined()
165
+ })
166
+
167
+ it('unmounts the content on close by default', async () => {
168
+ // Arrange
169
+ const wrapper = mountWindow({ open: true })
170
+ await nextTick()
171
+
172
+ // Act
173
+ await wrapper.setProps({ open: false })
174
+ // reka's Presence waits a tick before unmounting content with no exit animation
175
+ await nextTick()
176
+ await nextTick()
177
+
178
+ // Assert
179
+ expect(content()).toBeNull()
180
+ expect(lifecycle).toEqual({ mounted: 1, unmounted: 1 })
181
+ })
182
+ })
@@ -11,6 +11,8 @@ const props = withDefaults(defineProps<{
11
11
  contained?: boolean
12
12
  /** Label of the default trigger, ignored when the `launcher` slot is provided. */
13
13
  triggerLabel?: string
14
+ /** Keep the content mounted (hidden) after the first open, so background work inside it, like chat polling, survives closing the window. */
15
+ keepMounted?: boolean
14
16
  }>(), {
15
17
  closeOnOutsideClick: true,
16
18
  })
@@ -118,6 +120,11 @@ function handleEscapeKeyDown() {
118
120
  }
119
121
 
120
122
  function handleOpenUpdate(value: boolean) {
123
+ // A kept-mounted window stays a dismissable layer while closed, so Escape
124
+ // and outside interactions still reach it; there is nothing left to close.
125
+ if (!value && !props.open)
126
+ return
127
+
121
128
  if (!value && deferNextDismissal) {
122
129
  deferNextDismissal = false
123
130
  return
@@ -179,6 +186,7 @@ function unlockScroll() {
179
186
  const exitHoldMs = 380
180
187
 
181
188
  let unlockTimer: ReturnType<typeof setTimeout> | undefined
189
+ let hideTimer: ReturnType<typeof setTimeout> | undefined
182
190
 
183
191
  watch(() => props.open, (open) => {
184
192
  if (typeof document === 'undefined')
@@ -197,19 +205,58 @@ watch(() => props.open, (open) => {
197
205
 
198
206
  onBeforeUnmount(() => {
199
207
  clearTimeout(unlockTimer)
208
+ clearTimeout(hideTimer)
200
209
  unlockScroll()
201
210
  })
202
211
 
212
+ const hasOpened = ref(props.open)
213
+ const contentHidden = ref(false)
214
+ const forceMountContent = computed(() => props.keepMounted && hasOpened.value)
215
+
216
+ // Kept-mounted content never remounts, so reka's open/close auto-focus does not
217
+ // fire again: focus the editor on reopen and hand focus back to the launcher on close.
218
+ watch(() => props.open, (open) => {
219
+ clearTimeout(hideTimer)
220
+
221
+ if (open) {
222
+ const reopening = forceMountContent.value
223
+
224
+ hasOpened.value = true
225
+ contentHidden.value = false
226
+
227
+ if (reopening && shellEl.value)
228
+ focusEditorIn(shellEl.value)
229
+
230
+ return
231
+ }
232
+
233
+ if (!forceMountContent.value)
234
+ return
235
+
236
+ if (shellEl.value?.contains(document.activeElement))
237
+ launcher.value?.querySelector<HTMLElement>('[aria-haspopup]')?.focus()
238
+
239
+ hideTimer = setTimeout(() => {
240
+ contentHidden.value = true
241
+ }, exitHoldMs)
242
+ })
243
+
203
244
  function focusEditor(event: Event) {
204
245
  event.preventDefault()
205
246
 
247
+ const content = event.target instanceof HTMLElement
248
+ ? event.target
249
+ : document.querySelector<HTMLElement>('.widget-popover')
250
+
251
+ if (content)
252
+ focusEditorIn(content)
253
+ }
254
+
255
+ function focusEditorIn(content: HTMLElement) {
206
256
  nextTick(() => {
207
- const content = event.target instanceof HTMLElement
208
- ? event.target
209
- : document.querySelector('.widget-popover')
210
- const editor = Array.from(content?.querySelectorAll<HTMLElement>(
257
+ const editor = Array.from(content.querySelectorAll<HTMLElement>(
211
258
  '[data-prompt-editor] [contenteditable="true"], [data-chat-prompt-input] input:not(:disabled), [data-chat-prompt-input] textarea:not(:disabled), [data-chat-answer] input:not(:disabled), [data-chat-answer] textarea:not(:disabled)',
212
- ) ?? []).find(element => element.getClientRects().length > 0)
259
+ )).find(element => element.getClientRects().length > 0)
213
260
 
214
261
  if (!editor)
215
262
  return
@@ -250,6 +297,8 @@ function focusEditor(event: Event) {
250
297
  side="top"
251
298
  align="end"
252
299
  :side-offset="sideOffset"
300
+ :force-mount="forceMountContent"
301
+ :data-content-hidden="contentHidden || undefined"
253
302
  :class="cn(
254
303
  'widget-popover relative w-[min(480px,calc(100vw-32px))] p-0 z-599! transition-[height] duration-200 ease-out',
255
304
  expanded
@@ -292,6 +341,12 @@ function focusEditor(event: Event) {
292
341
  animation: widgetShellHoldOut 0.38s linear both;
293
342
  }
294
343
 
344
+ /* After the exit animation, kept-mounted content stops painting, taking focus and catching clicks. */
345
+ [data-reka-popper-content-wrapper]:has(> .widget-popover[data-content-hidden]) {
346
+ visibility: hidden;
347
+ pointer-events: none;
348
+ }
349
+
295
350
  @keyframes widgetShellHoldOut {
296
351
  from { opacity: 1; }
297
352
  to { opacity: 1; }
@@ -4,6 +4,7 @@ import {
4
4
  canSubmitNegativeFeedback,
5
5
  closeMessageFeedback,
6
6
  createMessageFeedbackState,
7
+ isBareFeedbackSubmitInFlight,
7
8
  openMessageFeedback,
8
9
  submitMessageFeedback,
9
10
  toggleMessageFeedbackReason,
@@ -177,6 +178,46 @@ describe('negative feedback validation', () => {
177
178
  })
178
179
  })
179
180
 
181
+ describe('bare submission loading', () => {
182
+ it('flags a bare submission while it is in flight and clears it after', async () => {
183
+ const state = createMessageFeedbackState()
184
+
185
+ expect(isBareFeedbackSubmitInFlight(state)).toBe(false)
186
+
187
+ let finish: ((result: { ok: true }) => void) | undefined
188
+ const pending = submitMessageFeedback(
189
+ state,
190
+ 'positive',
191
+ async () => await new Promise(resolve => finish = resolve),
192
+ 'Não foi possível enviar.',
193
+ )
194
+
195
+ expect(isBareFeedbackSubmitInFlight(state)).toBe(true)
196
+
197
+ finish?.({ ok: true })
198
+ await pending
199
+ expect(isBareFeedbackSubmitInFlight(state)).toBe(false)
200
+ })
201
+
202
+ it('stays false while a popover submission is in flight', async () => {
203
+ const state = createMessageFeedbackState()
204
+ openMessageFeedback(state, 'negative')
205
+
206
+ let finish: ((result: { ok: true }) => void) | undefined
207
+ const pending = submitMessageFeedback(
208
+ state,
209
+ 'negative',
210
+ async () => await new Promise(resolve => finish = resolve),
211
+ 'Não foi possível enviar.',
212
+ )
213
+
214
+ expect(isBareFeedbackSubmitInFlight(state)).toBe(false)
215
+
216
+ finish?.({ ok: true })
217
+ await pending
218
+ })
219
+ })
220
+
180
221
  describe('message feedback timeout', () => {
181
222
  it('gives up on a handler that never settles and offers a retry', async () => {
182
223
  const state = createMessageFeedbackState()
@@ -72,6 +72,13 @@ export function canSubmitNegativeFeedback(
72
72
  return state.comment.trim().length > 0
73
73
  }
74
74
 
75
+ // A bare thumbs-up submits without opening a popover, so a pending submission
76
+ // with no open rating can only be the bare button's — the popover flows keep
77
+ // openRating set until the vote is confirmed.
78
+ export function isBareFeedbackSubmitInFlight(state: MessageFeedbackState): boolean {
79
+ return state.submitting && state.openRating === null
80
+ }
81
+
75
82
  export const DEFAULT_SUBMIT_TIMEOUT_MS = 15_000
76
83
 
77
84
  export async function submitMessageFeedback(
@@ -4,6 +4,7 @@ import {
4
4
  canSubmitNegativeFeedback,
5
5
  closeMessageFeedback,
6
6
  createMessageFeedbackState,
7
+ isBareFeedbackSubmitInFlight,
7
8
  openMessageFeedback,
8
9
  submitMessageFeedback,
9
10
  toggleMessageFeedbackReason,
@@ -94,6 +95,8 @@ const canSubmitNegative = computed(() => canSubmitNegativeFeedback(
94
95
  negativeReasons.value,
95
96
  ))
96
97
 
98
+ const bareSubmitInFlight = computed(() => isBareFeedbackSubmitInFlight(state))
99
+
97
100
  async function submitRating(next: FeedbackRating) {
98
101
  const submit: FeedbackSubmitHandler = props.submit ?? (async (payload: FeedbackPayload) => {
99
102
  emit('submit', payload)
@@ -120,12 +123,14 @@ function toggleReason(reason: string) {
120
123
  cursor-pointer
121
124
  :disabled="state.submitting"
122
125
  :class="currentRating === 'positive' ? 'bg-green-100 text-green-700' : 'text-icon-secondary hover:bg-subtle hover:text-icon'"
123
- :aria-label="helpfulLabel"
126
+ :aria-label="bareSubmitInFlight ? submittingLabel : helpfulLabel"
124
127
  @click="submitRating('positive')"
125
128
  >
129
+ <TelaIconSpinner v-if="bareSubmitInFlight" class="animate-spin" />
126
130
  <TelaIcon
131
+ v-else
127
132
  :name="currentRating === 'positive' ? 'i-ph-thumbs-up-fill' : 'i-ph-thumbs-up'"
128
- size="14px"
133
+ size="18px"
129
134
  />
130
135
  </button>
131
136
  <TelaPopover v-else v-model:open="positiveOpen">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/tela-build",
3
- "version": "1.75.1",
3
+ "version": "1.76.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "app.config.ts",