@meistrari/tela-build 1.101.0 → 1.102.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,14 @@
2
2
 
3
3
  Latest updates and announcements.
4
4
 
5
+ ## November 12, 2026
6
+
7
+ - [Chat](/templates/chat#floating) The floating chat launcher can be moved along the bottom edge: hold it for half a second and it lifts and follows the pointer horizontally over a translucent dashed rail, with a hint that explains how to drop or cancel (Escape). It stays wherever it is released, snapping to an end when dropped within 24px of it, and the window opens above it, aligned to its half of the screen. With the launcher focused, Alt+Left/Right moves it a tenth of the way. The spot is shared by every launcher and remembered in `localStorage`; moving it back to a launcher's default end forgets it, so pages with another default keep theirs. A short click still opens the chat. `TelaChatFloatingWindow` adds `movable` (default `true`; `false` pins the launcher to `position` and ignores the remembered spot), and the new `TelaChatFloatingWindowAnchor` makes a custom launcher movable the same way.
8
+
9
+ ## November 9, 2026
10
+
11
+ - [Chat](/templates/chat) `TelaChatFloatingWindow` with `position="left"` offsets its launcher by `--tela-floating-window-inset-left` (default `0px`), so an app with a fixed left sidebar can keep the launcher 16px to the right of it instead of on top of it.
12
+
5
13
  ## November 6, 2026
6
14
 
7
15
  - [Skeleton Reveal](/components/skeleton-reveal) is a new component that puts a page or section behind a skeleton measured from its own content, built on [skullet](https://skullet.lochie.me). The first load shows the `#placeholder` slot, later loads draw the layout remembered under `id`, and loads under 150ms show no skeleton. It uses the same `bg-muted` surface and pulse as [Skeleton](/components/skeleton). `forgetSkeletonShapes()` clears the remembered layouts.
@@ -149,6 +149,8 @@ The window opens over its own launcher: the surface springs out of the launcher'
149
149
 
150
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
151
 
152
+ Users can move the launcher along the bottom edge: holding it for half a second lifts it under the pointer and shows a translucent dashed rail where it can go. It follows the pointer horizontally and stays where it is released, snapping to an end when dropped within 24px of it; Escape returns it to where it was. With the launcher focused, Alt+Left/Right moves it a tenth of the way. A short click still opens the chat. The window opens above the launcher, aligned to its half of the screen, and the spot is stored in `localStorage`, so every launcher on the page follows it across reloads. Moving a launcher back to its default end clears the stored spot, so a page with a different default (like `position="left"`) keeps it. Set `movable` to `false` to pin the launcher to `position`, ignoring the stored spot. To make a launcher you render yourself movable in the same way, wrap it in `TelaChatFloatingWindowAnchor` with a `position` (0 is the left end, 1 the right end) and handle `update:position`. `useFloatingLauncherPosition()` from `components/tela/chat/floating/launcher-position` returns the stored spot.
153
+
152
154
  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).
153
155
 
154
156
  ```vue
@@ -1439,6 +1441,7 @@ import { TelaChatIconsAnthropic, TelaChatIconsGemini, TelaChatIconsOpenai } from
1439
1441
  | `TelaChatWidgetHeader` | Widget top bar: optional title, new-conversation and history actions, plus expand and minimize (floating shell only). Marked with `data-widget-header`. |
1440
1442
  | `TelaChatWidgetHistoryList` | Searchable conversation list for the header's `#history` slot. |
1441
1443
  | `TelaChatFloatingWindowTrigger` | Pill button that opens the floating widget. |
1444
+ | `TelaChatFloatingWindowAnchor` | Fixed spot on the bottom edge for a launcher; hold for half a second to slide it along the edge. |
1442
1445
  | `TelaChatFloatingWindow` | Anchored popover shell for the floating variant (`open` / `@update:open`). |
1443
1446
  | `TelaChatSidepanelWindow` | Always-open, in-flow docked column for the sidepanel variant. |
1444
1447
  | `TelaChatAnswer` | Controlled single/multiple-choice question card; emits intent only, the host owns state and submission. |
@@ -1710,12 +1713,22 @@ type FloatingWindowTriggerProps = {
1710
1713
  type FloatingWindowProps = {
1711
1714
  closeOnOutsideClick?: boolean // defaults to true; false keeps the window open on outside clicks
1712
1715
  open: boolean
1716
+ position?: 'left' | 'right' // defaults to 'right'; end of the bottom edge the launcher starts at until the user moves it. A left launcher is offset by --tela-floating-window-inset-left (e.g. a fixed app sidebar's width)
1717
+ movable?: boolean // defaults to true; holding the closed launcher for 0.5s (or Alt+Left/Right while focused) slides it along the bottom edge; false pins it to position
1713
1718
  contained?: boolean // anchor the launcher to the nearest positioned ancestor instead of the viewport
1714
1719
  triggerLabel?: string // label of the default trigger; ignored when #launcher is provided
1715
1720
  keepMounted?: boolean // defaults to false; keeps the content mounted (hidden) after the first open
1716
1721
  }
1717
1722
  // emits: update:open(value: boolean)
1718
1723
 
1724
+ type FloatingWindowAnchorProps = {
1725
+ position: number // 0 is the left end of the bottom edge, 1 the right end
1726
+ contained?: boolean // position against the nearest positioned ancestor instead of the viewport
1727
+ movable?: boolean // defaults to true; also enables Alt+Left/Right while the launcher is focused
1728
+ holdMs?: number // defaults to 500; how long to hold before the launcher can be dragged
1729
+ }
1730
+ // emits: update:position(position: number)
1731
+
1719
1732
  // TelaChatSidepanelWindow takes no props.
1720
1733
  ```
1721
1734
 
@@ -0,0 +1,246 @@
1
+ // @vitest-environment happy-dom
2
+ import { mount } from '@vue/test-utils'
3
+ import { computed, h, nextTick, onBeforeUnmount, ref } from 'vue'
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
+ import { DEFAULT_TELA_LABELS } from '../../../../composables/tela-labels'
6
+ import FloatingWindowAnchor from './floating-window-anchor.vue'
7
+
8
+ const cn = (...values: unknown[]) => values.filter(Boolean).join(' ')
9
+
10
+ vi.stubGlobal('cn', cn)
11
+ vi.stubGlobal('computed', computed)
12
+ vi.stubGlobal('nextTick', nextTick)
13
+ vi.stubGlobal('onBeforeUnmount', onBeforeUnmount)
14
+ vi.stubGlobal('ref', ref)
15
+ vi.stubGlobal('useTelaLabels', () => computed(() => DEFAULT_TELA_LABELS))
16
+
17
+ // happy-dom has no layout: the rail spans x 16..1016 and the 100px-wide launcher starts at the right end,
18
+ // so its left edge travels 900px.
19
+ const railBox = { left: 16, top: 718, width: 1000, height: 34 }
20
+ const launcherBox = { left: 916, top: 718, width: 100, height: 34 }
21
+
22
+ function box({ left, top, width, height }: typeof railBox) {
23
+ return { left, top, width, height, x: left, y: top, right: left + width, bottom: top + height, toJSON: () => ({}) } as DOMRect
24
+ }
25
+
26
+ const mounted: Array<{ unmount: () => void }> = []
27
+
28
+ function mountAnchor(props: { position?: number, movable?: boolean } = {}) {
29
+ const onClick = vi.fn()
30
+ const wrapper = mount(FloatingWindowAnchor, {
31
+ props: { position: 1, ...props },
32
+ slots: { default: () => h('button', { 'data-testid': 'launcher', 'onClick': onClick }) },
33
+ attachTo: document.body,
34
+ global: { mocks: { cn } },
35
+ })
36
+
37
+ mounted.push(wrapper)
38
+
39
+ return { wrapper, onClick, button: () => document.querySelector<HTMLElement>('[data-testid="launcher"]')! }
40
+ }
41
+
42
+ function pointer(type: string, target: EventTarget, x: number, y = 735) {
43
+ target.dispatchEvent(new PointerEvent(type, { clientX: x, clientY: y, button: 0, isPrimary: true, pointerId: 1, bubbles: true }))
44
+ }
45
+
46
+ function mouseClick(target: HTMLElement) {
47
+ target.dispatchEvent(new MouseEvent('click', { detail: 1, bubbles: true, cancelable: true }))
48
+ }
49
+
50
+ // Grabs the launcher 50px from its left edge.
51
+ const start = 966
52
+
53
+ async function holdAndSlideTo(button: HTMLElement, x: number) {
54
+ pointer('pointerdown', button, start)
55
+ vi.advanceTimersByTime(500)
56
+ await nextTick()
57
+ pointer('pointermove', window, x)
58
+ await nextTick()
59
+ }
60
+
61
+ describe('floating window anchor', () => {
62
+ beforeEach(() => {
63
+ vi.useFakeTimers()
64
+ vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (this: HTMLElement) {
65
+ return box(this.hasAttribute('data-launcher-rail') ? railBox : launcherBox)
66
+ })
67
+ })
68
+
69
+ afterEach(() => {
70
+ mounted.splice(0).forEach(wrapper => wrapper.unmount())
71
+ vi.restoreAllMocks()
72
+ vi.useRealTimers()
73
+ document.body.innerHTML = ''
74
+ })
75
+
76
+ it('enters move mode after a half second hold and shows the bottom rail', async () => {
77
+ // Arrange
78
+ const { button } = mountAnchor()
79
+ pointer('pointerdown', button(), start)
80
+
81
+ // Act
82
+ vi.advanceTimersByTime(499)
83
+ await nextTick()
84
+ const railBeforeHold = document.querySelector('[data-launcher-rail]')
85
+ vi.advanceTimersByTime(1)
86
+ await nextTick()
87
+
88
+ // Assert
89
+ expect(railBeforeHold).toBeNull()
90
+ expect(document.querySelector('[data-launcher-rail]')).not.toBeNull()
91
+ expect(document.querySelector('[data-launcher-moving]')).not.toBeNull()
92
+ expect(document.querySelector('[role="status"]')?.textContent?.trim()).toBe(DEFAULT_TELA_LABELS.moveLauncherHint)
93
+ })
94
+
95
+ it('follows the pointer horizontally while moving', async () => {
96
+ // Arrange
97
+ const { wrapper, button } = mountAnchor()
98
+
99
+ // Act
100
+ await holdAndSlideTo(button(), 516)
101
+
102
+ // Assert
103
+ const style = wrapper.get('[data-launcher-moving]').attributes('style')
104
+ expect(style).toContain('* 0.5)')
105
+ expect(style).not.toContain('top')
106
+ })
107
+
108
+ it('stays where it is dropped without pressing the launcher', async () => {
109
+ // Arrange
110
+ const { wrapper, onClick, button } = mountAnchor()
111
+ await holdAndSlideTo(button(), 291)
112
+
113
+ // Act
114
+ pointer('pointerup', button(), 291)
115
+ mouseClick(button())
116
+ await nextTick()
117
+
118
+ // Assert
119
+ expect(wrapper.emitted('update:position')).toEqual([[0.25]])
120
+ expect(onClick).not.toHaveBeenCalled()
121
+ expect(document.querySelector('[data-launcher-moving]')).toBeNull()
122
+ })
123
+
124
+ it('snaps a drop close to an end onto that end', async () => {
125
+ // Arrange
126
+ const { wrapper, button } = mountAnchor({ position: 0.5 })
127
+ await holdAndSlideTo(button(), 86)
128
+
129
+ // Act
130
+ pointer('pointerup', button(), 86)
131
+ await nextTick()
132
+
133
+ // Assert
134
+ expect(wrapper.emitted('update:position')).toEqual([[0]])
135
+ })
136
+
137
+ it('keeps a short press as a normal click', async () => {
138
+ // Arrange
139
+ const { wrapper, onClick, button } = mountAnchor()
140
+
141
+ // Act
142
+ pointer('pointerdown', button(), start)
143
+ vi.advanceTimersByTime(300)
144
+ pointer('pointerup', button(), start)
145
+ mouseClick(button())
146
+ vi.advanceTimersByTime(500)
147
+ await nextTick()
148
+
149
+ // Assert
150
+ expect(onClick).toHaveBeenCalledOnce()
151
+ expect(wrapper.emitted('update:position')).toBeUndefined()
152
+ expect(document.querySelector('[data-launcher-moving]')).toBeNull()
153
+ })
154
+
155
+ it('cancels the hold when the pointer moves before it completes', async () => {
156
+ // Arrange
157
+ const { button } = mountAnchor()
158
+ pointer('pointerdown', button(), start)
159
+
160
+ // Act
161
+ pointer('pointermove', window, start - 20)
162
+ vi.advanceTimersByTime(500)
163
+ await nextTick()
164
+
165
+ // Assert
166
+ expect(document.querySelector('[data-launcher-moving]')).toBeNull()
167
+ })
168
+
169
+ it('returns to where it was when Escape is pressed while moving', async () => {
170
+ // Arrange
171
+ const { wrapper, button } = mountAnchor()
172
+ await holdAndSlideTo(button(), 291)
173
+
174
+ // Act
175
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
176
+ pointer('pointerup', button(), 291)
177
+ await nextTick()
178
+
179
+ // Assert
180
+ expect(wrapper.emitted('update:position')).toBeUndefined()
181
+ expect(document.querySelector('[data-launcher-moving]')).toBeNull()
182
+ expect(document.querySelector('[data-launcher-move-guide]')).toBeNull()
183
+ })
184
+
185
+ it('does not press the launcher when Escape cancels the hold before it completes', async () => {
186
+ // Arrange
187
+ const { wrapper, onClick, button } = mountAnchor()
188
+ pointer('pointerdown', button(), start)
189
+ vi.advanceTimersByTime(200)
190
+
191
+ // Act
192
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
193
+ pointer('pointerup', button(), start)
194
+ mouseClick(button())
195
+ vi.advanceTimersByTime(500)
196
+ await nextTick()
197
+
198
+ // Assert
199
+ expect(onClick).not.toHaveBeenCalled()
200
+ expect(wrapper.emitted('update:position')).toBeUndefined()
201
+ expect(document.querySelector('[data-launcher-moving]')).toBeNull()
202
+ })
203
+
204
+ it('still opens from the keyboard after a move was cancelled with Escape', async () => {
205
+ // Arrange
206
+ const { onClick, button } = mountAnchor()
207
+ await holdAndSlideTo(button(), 291)
208
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
209
+ pointer('pointerup', window, 291)
210
+ await nextTick()
211
+
212
+ // Act
213
+ button().click()
214
+
215
+ // Assert
216
+ expect(onClick).toHaveBeenCalledOnce()
217
+ })
218
+
219
+ it('moves a tenth of the way per Alt+Arrow key', async () => {
220
+ // Arrange
221
+ const { wrapper, button } = mountAnchor({ position: 1 })
222
+
223
+ // Act
224
+ button().dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft', altKey: true, bubbles: true }))
225
+ button().dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft', bubbles: true }))
226
+ button().dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight', altKey: true, bubbles: true }))
227
+ await nextTick()
228
+
229
+ // Assert
230
+ expect(wrapper.emitted('update:position')).toEqual([[0.9]])
231
+ })
232
+
233
+ it('does not move when movable is false', async () => {
234
+ // Arrange
235
+ const { wrapper, button } = mountAnchor({ movable: false })
236
+
237
+ // Act
238
+ await holdAndSlideTo(button(), 291)
239
+ button().dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft', altKey: true, bubbles: true }))
240
+ await nextTick()
241
+
242
+ // Assert
243
+ expect(document.querySelector('[data-launcher-moving]')).toBeNull()
244
+ expect(wrapper.emitted('update:position')).toBeUndefined()
245
+ })
246
+ })
@@ -0,0 +1,280 @@
1
+ <script setup lang="ts">
2
+ import type { FloatingLauncherPosition } from './launcher-position'
3
+ import { LAUNCHER_EDGE_SNAP_PX, clampLauncherPosition, floatingLauncherPositionStyle, launcherGutters } from './launcher-position'
4
+
5
+ defineOptions({ inheritAttrs: false })
6
+
7
+ const props = withDefaults(defineProps<{
8
+ /** Where the launcher sits along the bottom edge: 0 is the left end, 1 the right end. */
9
+ position: FloatingLauncherPosition
10
+ /** Positions against the nearest positioned ancestor instead of the viewport. */
11
+ contained?: boolean
12
+ /** Holding the launcher for `holdMs` lets the user slide it along the bottom edge; Alt+Left/Right moves it while focused. */
13
+ movable?: boolean
14
+ holdMs?: number
15
+ }>(), {
16
+ movable: true,
17
+ holdMs: 500,
18
+ })
19
+
20
+ const emit = defineEmits<{
21
+ (e: 'update:position', position: FloatingLauncherPosition): void
22
+ }>()
23
+
24
+ const labels = useTelaLabels()
25
+
26
+ const moveTolerance = 6
27
+ const keyboardStep = 0.1
28
+
29
+ const anchor = ref<HTMLElement | null>(null)
30
+ const rail = ref<HTMLElement | null>(null)
31
+ const phase = ref<'idle' | 'holding' | 'moving'>('idle')
32
+ const draggedPosition = ref<FloatingLauncherPosition | null>(null)
33
+ const launcherHeight = ref(0)
34
+
35
+ const positionStyle = computed(() => floatingLauncherPositionStyle(draggedPosition.value ?? props.position, props.contained))
36
+ const railStyle = computed(() => ({ ...launcherGutters(props.contained), height: `${launcherHeight.value}px` }))
37
+
38
+ let start = { x: 0, y: 0 }
39
+ let grabOffset = 0
40
+ let launcherWidth = 0
41
+ let pointerId: number | undefined
42
+ let holdTimer: ReturnType<typeof setTimeout> | undefined
43
+ let suppressClick = false
44
+
45
+ function addListeners() {
46
+ window.addEventListener('pointermove', handlePointerMove)
47
+ window.addEventListener('pointerup', handlePointerUp)
48
+ window.addEventListener('pointercancel', handlePointerCancel)
49
+ window.addEventListener('keydown', handleKeyDown, true)
50
+ }
51
+
52
+ function removeListeners() {
53
+ window.removeEventListener('pointermove', handlePointerMove)
54
+ window.removeEventListener('pointerup', handlePointerUp)
55
+ window.removeEventListener('pointercancel', handlePointerCancel)
56
+ window.removeEventListener('keydown', handleKeyDown, true)
57
+ }
58
+
59
+ function reset() {
60
+ clearTimeout(holdTimer)
61
+ removeListeners()
62
+
63
+ if (pointerId !== undefined && anchor.value?.hasPointerCapture?.(pointerId))
64
+ anchor.value.releasePointerCapture(pointerId)
65
+
66
+ pointerId = undefined
67
+ phase.value = 'idle'
68
+ draggedPosition.value = null
69
+ }
70
+
71
+ function handlePointerDown(event: PointerEvent) {
72
+ suppressClick = false
73
+
74
+ if (!props.movable || phase.value !== 'idle' || event.button !== 0 || !event.isPrimary)
75
+ return
76
+
77
+ start = { x: event.clientX, y: event.clientY }
78
+ pointerId = event.pointerId
79
+ phase.value = 'holding'
80
+ holdTimer = setTimeout(startMoving, props.holdMs)
81
+ addListeners()
82
+ }
83
+
84
+ function startMoving() {
85
+ const element = anchor.value
86
+
87
+ if (!element)
88
+ return reset()
89
+
90
+ const box = element.getBoundingClientRect()
91
+
92
+ launcherWidth = box.width
93
+ launcherHeight.value = box.height
94
+ grabOffset = start.x - box.left
95
+ draggedPosition.value = props.position
96
+ phase.value = 'moving'
97
+ // The release ends the drag; it must not also press the launcher.
98
+ suppressClick = true
99
+
100
+ if (pointerId !== undefined)
101
+ element.setPointerCapture?.(pointerId)
102
+ }
103
+
104
+ /** Where the launcher's left edge can travel along the rail, in viewport pixels. */
105
+ function track() {
106
+ const box = rail.value?.getBoundingClientRect()
107
+
108
+ return box ? { left: box.left, length: Math.max(0, box.width - launcherWidth) } : null
109
+ }
110
+
111
+ function positionAt(clientX: number) {
112
+ const span = track()
113
+
114
+ if (!span?.length)
115
+ return props.position
116
+
117
+ return clampLauncherPosition((clientX - grabOffset - span.left) / span.length)
118
+ }
119
+
120
+ /** A drop within `LAUNCHER_EDGE_SNAP_PX` of an end lands on that end, so the default spot is easy to get back to. */
121
+ function snapToEnds(position: FloatingLauncherPosition) {
122
+ const length = track()?.length ?? 0
123
+
124
+ if (position * length <= LAUNCHER_EDGE_SNAP_PX)
125
+ return 0
126
+
127
+ if ((1 - position) * length <= LAUNCHER_EDGE_SNAP_PX)
128
+ return 1
129
+
130
+ return position
131
+ }
132
+
133
+ function handlePointerMove(event: PointerEvent) {
134
+ if (event.pointerId !== pointerId)
135
+ return
136
+
137
+ if (phase.value === 'holding') {
138
+ if (Math.hypot(event.clientX - start.x, event.clientY - start.y) > moveTolerance)
139
+ reset()
140
+
141
+ return
142
+ }
143
+
144
+ draggedPosition.value = positionAt(event.clientX)
145
+ }
146
+
147
+ function handlePointerUp(event: PointerEvent) {
148
+ if (event.pointerId !== pointerId)
149
+ return
150
+
151
+ if (phase.value !== 'moving')
152
+ return reset()
153
+
154
+ const position = snapToEnds(positionAt(event.clientX))
155
+
156
+ reset()
157
+ commit(position)
158
+ }
159
+
160
+ function handlePointerCancel(event: PointerEvent) {
161
+ if (event.pointerId === pointerId)
162
+ reset()
163
+ }
164
+
165
+ function handleKeyDown(event: KeyboardEvent) {
166
+ if (event.key !== 'Escape' || phase.value === 'idle')
167
+ return
168
+
169
+ event.preventDefault()
170
+ event.stopPropagation()
171
+ // A cancelled hold or move: the release that follows must not press the launcher either.
172
+ suppressClick = true
173
+ reset()
174
+ }
175
+
176
+ function handleClickCapture(event: MouseEvent) {
177
+ // Keyboard clicks (detail 0) never end a drag, so a cancelled drag can't swallow them.
178
+ if (!suppressClick || event.detail === 0)
179
+ return
180
+
181
+ suppressClick = false
182
+ event.preventDefault()
183
+ event.stopPropagation()
184
+ }
185
+
186
+ function handleLauncherKeyDown(event: KeyboardEvent) {
187
+ if (!props.movable || phase.value !== 'idle' || !event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
188
+ return
189
+
190
+ const direction = event.key === 'ArrowLeft' ? -1 : event.key === 'ArrowRight' ? 1 : 0
191
+
192
+ if (!direction)
193
+ return
194
+
195
+ event.preventDefault()
196
+ commit(clampLauncherPosition(Math.round((props.position + direction * keyboardStep) * 10) / 10))
197
+ }
198
+
199
+ function commit(position: FloatingLauncherPosition) {
200
+ if (position !== props.position)
201
+ emit('update:position', position)
202
+ }
203
+
204
+ onBeforeUnmount(reset)
205
+ </script>
206
+
207
+ <template>
208
+ <div
209
+ ref="anchor"
210
+ v-bind="$attrs"
211
+ :data-launcher-moving="phase === 'moving' || undefined"
212
+ :class="cn(
213
+ 'bottom-16px z-599 w-max touch-none',
214
+ contained ? 'absolute' : 'fixed',
215
+ phase === 'moving'
216
+ ? 'cursor-grabbing will-change-[left,translate]'
217
+ : 'transition-[left,translate] duration-300 ease-[cubic-bezier(0.32,1.2,0.5,1)] motion-reduce:transition-none',
218
+ )"
219
+ :style="positionStyle"
220
+ @pointerdown="handlePointerDown"
221
+ @keydown="handleLauncherKeyDown"
222
+ @click.capture="handleClickCapture"
223
+ @contextmenu="phase !== 'idle' && $event.preventDefault()"
224
+ @dragstart.prevent
225
+ >
226
+ <div
227
+ :class="cn(
228
+ 'rounded-8px transition-[transform,box-shadow] motion-reduce:transition-none',
229
+ phase === 'holding' && 'scale-96 duration-500 ease-linear',
230
+ phase === 'moving' && 'scale-105 duration-200 ease-out [box-shadow:0_16px_40px_0_rgba(0,0,0,0.16),0_4px_12px_0_rgba(0,0,0,0.08)]',
231
+ phase === 'idle' && 'duration-200 ease-out',
232
+ )"
233
+ >
234
+ <slot />
235
+ </div>
236
+ </div>
237
+
238
+ <Transition
239
+ enter-active-class="transition-opacity duration-150 ease-out motion-reduce:transition-none"
240
+ leave-active-class="transition-opacity duration-150 ease-out motion-reduce:transition-none"
241
+ enter-from-class="opacity-0"
242
+ leave-to-class="opacity-0"
243
+ >
244
+ <div
245
+ v-if="phase === 'moving'"
246
+ data-launcher-move-guide
247
+ pointer-events-none
248
+ z-598
249
+ :class="contained ? 'absolute inset-0' : 'fixed inset-0'"
250
+ >
251
+ <div
252
+ ref="rail"
253
+ data-launcher-rail
254
+ absolute
255
+ bottom-16px
256
+ rounded-8px
257
+ border-1px
258
+ border-dashed
259
+ border-neutral-300
260
+ class="bg-background-subtle/50"
261
+ :style="railStyle"
262
+ />
263
+ <div
264
+ role="status"
265
+ class="left-1/2 -translate-x-1/2 [box-shadow:0_8px_24px_0_rgba(0,0,0,0.16)]"
266
+ absolute
267
+ px-12px
268
+ py-6px
269
+ rounded-full
270
+ bg-neutral-900
271
+ text-white
272
+ body-12-medium
273
+ whitespace-nowrap
274
+ :style="{ bottom: `${16 + launcherHeight + 12}px` }"
275
+ >
276
+ {{ labels.moveLauncherHint }}
277
+ </div>
278
+ </div>
279
+ </Transition>
280
+ </template>
@@ -4,7 +4,10 @@ import { PopoverRoot, PopoverTrigger } from 'reka-ui'
4
4
  import { computed, defineComponent, h, nextTick, onBeforeUnmount, onMounted, onUnmounted, provide, ref, watch } from 'vue'
5
5
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
6
6
  import TelaPopoverContent from '../../popover/popover-content.vue'
7
+ import { DEFAULT_TELA_LABELS } from '../../../../composables/tela-labels'
8
+ import FloatingWindowAnchor from './floating-window-anchor.vue'
7
9
  import FloatingWindow from './floating-window.vue'
10
+ import { useFloatingLauncherPosition } from './launcher-position'
8
11
 
9
12
  const cn = (...values: unknown[]) => values.filter(Boolean).join(' ')
10
13
 
@@ -16,6 +19,7 @@ vi.stubGlobal('onMounted', onMounted)
16
19
  vi.stubGlobal('provide', provide)
17
20
  vi.stubGlobal('ref', ref)
18
21
  vi.stubGlobal('watch', watch)
22
+ vi.stubGlobal('useTelaLabels', () => computed(() => DEFAULT_TELA_LABELS))
19
23
 
20
24
  const lifecycle = { mounted: 0, unmounted: 0 }
21
25
  const mounted: Array<{ unmount: () => void }> = []
@@ -29,7 +33,7 @@ const ChatBody = defineComponent({
29
33
  },
30
34
  })
31
35
 
32
- function mountWindow(props: { open: boolean, keepMounted?: boolean }) {
36
+ function mountWindow(props: { open: boolean, keepMounted?: boolean, position?: 'left' | 'right', movable?: boolean }) {
33
37
  const wrapper = mount(FloatingWindow, {
34
38
  props,
35
39
  slots: { default: () => h(ChatBody) },
@@ -40,6 +44,7 @@ function mountWindow(props: { open: boolean, keepMounted?: boolean }) {
40
44
  TelaPopover: PopoverRoot,
41
45
  TelaPopoverTrigger: PopoverTrigger,
42
46
  TelaPopoverContent,
47
+ TelaChatFloatingWindowAnchor: FloatingWindowAnchor,
43
48
  },
44
49
  stubs: {
45
50
  Motion: defineComponent({ setup: (_, { slots }) => () => h('div', slots.default?.()) }),
@@ -62,6 +67,7 @@ describe('floating chat window', () => {
62
67
  vi.useFakeTimers()
63
68
  lifecycle.mounted = 0
64
69
  lifecycle.unmounted = 0
70
+ useFloatingLauncherPosition().value = null
65
71
  })
66
72
 
67
73
  afterEach(() => {
@@ -70,6 +76,76 @@ describe('floating chat window', () => {
70
76
  document.body.innerHTML = ''
71
77
  })
72
78
 
79
+ it('starts a left launcher at the left end, clear of the host inset', () => {
80
+ // Arrange & Act
81
+ const wrapper = mountWindow({ open: false, position: 'left' })
82
+ const style = wrapper.get('[data-tela-floating-window]').attributes('style')
83
+
84
+ // Assert
85
+ expect(style).toContain('var(--tela-floating-window-inset-left, 0px)')
86
+ expect(style).toContain('* 0)')
87
+ })
88
+
89
+ it('starts a right launcher at the right end', () => {
90
+ // Arrange & Act
91
+ const wrapper = mountWindow({ open: false })
92
+ const launcher = wrapper.get('[data-tela-floating-window]')
93
+
94
+ // Assert
95
+ expect(launcher.classes()).toContain('bottom-16px')
96
+ expect(launcher.attributes('style')).toContain('* 1)')
97
+ })
98
+
99
+ it('places the launcher where the user moved it along the bottom', () => {
100
+ // Arrange
101
+ useFloatingLauncherPosition().value = 0.4
102
+
103
+ // Act
104
+ const wrapper = mountWindow({ open: false })
105
+ const launcher = wrapper.get('[data-tela-floating-window]')
106
+
107
+ // Assert
108
+ expect(launcher.classes()).toContain('bottom-16px')
109
+ expect(launcher.attributes('style')).toContain('* 0.4)')
110
+ })
111
+
112
+ it('keeps a launcher that is not movable on its position', () => {
113
+ // Arrange
114
+ useFloatingLauncherPosition().value = 0.4
115
+
116
+ // Act
117
+ const wrapper = mountWindow({ open: false, movable: false })
118
+
119
+ // Assert
120
+ expect(wrapper.get('[data-tela-floating-window]').attributes('style')).toContain('* 1)')
121
+ })
122
+
123
+ it('forgets the moved position when the launcher goes back to its default end', async () => {
124
+ // Arrange
125
+ useFloatingLauncherPosition().value = 0.4
126
+ const wrapper = mountWindow({ open: false, position: 'left' })
127
+
128
+ // Act
129
+ wrapper.getComponent({ name: 'FloatingWindowAnchor' }).vm.$emit('update:position', 0)
130
+ await nextTick()
131
+
132
+ // Assert
133
+ expect(useFloatingLauncherPosition().value).toBeNull()
134
+ })
135
+
136
+ it('opens the window above the launcher, aligned to its half of the screen', async () => {
137
+ // Arrange
138
+ useFloatingLauncherPosition().value = 0.3
139
+
140
+ // Act
141
+ mountWindow({ open: true })
142
+ await nextTick()
143
+
144
+ // Assert
145
+ expect(content()?.dataset.side).toBe('top')
146
+ expect(content()?.dataset.align).toBe('start')
147
+ })
148
+
73
149
  it('does not mount the content before the first open', () => {
74
150
  // Arrange & Act
75
151
  mountWindow({ open: false, keepMounted: true })
@@ -2,11 +2,14 @@
2
2
  import { hasOpenEscapeLayer, markEscapeClosingFloatingWindow, registerFloatingWindowCloser } from './escape-layer'
3
3
  import { chatShellContextKey } from '../chat-shell-context'
4
4
  import { floatingWindowContextKey } from './floating-window-context'
5
+ import { isLauncherOnLeftHalf, useFloatingLauncherPosition } from './launcher-position'
5
6
 
6
7
  const props = withDefaults(defineProps<{
7
8
  open: boolean
8
- /** Corner used by the launcher and the window's open/close animation. */
9
+ /** End of the bottom edge the launcher starts at, until the user moves it. The window opens above the launcher. */
9
10
  position?: 'left' | 'right'
11
+ /** Holding the closed launcher for half a second lets the user slide it anywhere along the bottom edge (Alt+Left/Right while it is focused). The spot is remembered across pages and reloads; moving it back to its default end forgets it. `false` pins it to `position`. */
12
+ movable?: boolean
10
13
  /** Close on outside clicks. Disable to keep the chat open while interacting with the page. */
11
14
  closeOnOutsideClick?: boolean
12
15
  /** Anchors the launcher to the nearest positioned ancestor instead of the viewport (docs/embedded previews). */
@@ -18,12 +21,18 @@ const props = withDefaults(defineProps<{
18
21
  }>(), {
19
22
  closeOnOutsideClick: true,
20
23
  position: 'right',
24
+ movable: true,
21
25
  })
22
26
 
23
27
  const emit = defineEmits<{
24
28
  (e: 'update:open', value: boolean): void
25
29
  }>()
26
30
 
31
+ const movedPosition = useFloatingLauncherPosition()
32
+ const defaultPosition = computed(() => props.position === 'left' ? 0 : 1)
33
+ const launcherPosition = computed(() => (props.movable ? movedPosition.value : null) ?? defaultPosition.value)
34
+ const alignsLeft = computed(() => isLauncherOnLeftHalf(launcherPosition.value))
35
+
27
36
  const expanded = ref(false)
28
37
  const launcher = ref<HTMLElement | null>(null)
29
38
  const launcherWidth = ref(0)
@@ -296,26 +305,24 @@ function focusEditorIn(content: HTMLElement) {
296
305
 
297
306
  <template>
298
307
  <TelaPopover :open="open" @update:open="handleOpenUpdate">
299
- <div
300
- ref="launcher"
308
+ <TelaChatFloatingWindowAnchor
301
309
  data-tela-floating-window
302
- :class="cn(
303
- 'bottom-16px z-599',
304
- contained ? 'absolute' : 'fixed',
305
- position === 'left' ? 'left-16px' : contained ? 'right-16px' : 'right-[calc(16px+var(--scrollbar-width,0px))]',
306
- )"
310
+ :position="launcherPosition"
311
+ :contained="contained"
312
+ :movable="movable && !open"
313
+ @update:position="movedPosition = $event === defaultPosition ? null : $event"
307
314
  >
308
- <div :class="cn('transition-opacity', open ? 'opacity-0 duration-100' : 'duration-160 delay-160')">
315
+ <div ref="launcher" :class="cn('transition-opacity', open ? 'opacity-0 duration-100' : 'duration-160 delay-160')">
309
316
  <TelaPopoverTrigger as-child>
310
317
  <slot name="launcher">
311
318
  <TelaChatFloatingWindowTrigger :open="open" :label="triggerLabel" />
312
319
  </slot>
313
320
  </TelaPopoverTrigger>
314
321
  </div>
315
- </div>
322
+ </TelaChatFloatingWindowAnchor>
316
323
  <TelaPopoverContent
317
324
  side="top"
318
- :align="position === 'left' ? 'start' : 'end'"
325
+ :align="alignsLeft ? 'start' : 'end'"
319
326
  :side-offset="sideOffset"
320
327
  :force-mount="forceMountContent"
321
328
  :data-content-hidden="contentHidden || undefined"
@@ -337,15 +344,15 @@ function focusEditorIn(content: HTMLElement) {
337
344
  :initial="launcherBox"
338
345
  :animate="surfaceAnimate"
339
346
  :transition="surfaceTransition"
340
- :class="position === 'left' ? 'left-0' : 'right-0'"
347
+ :class="alignsLeft ? 'left-0' : 'right-0'"
341
348
  class="absolute bottom-0 w-full h-full overflow-hidden bg rounded-12px border-0.5px border-black/12 [box-shadow:-24px_-24px_249px_0_rgba(0,0,0,0.08),-12px_-8px_48px_0_rgba(0,0,0,0.03)]"
342
349
  >
343
350
  <Motion
344
351
  :initial="contentInitial"
345
352
  :animate="contentAnimate"
346
353
  :transition="contentTransition"
347
- :style="{ originX: position === 'left' ? 0 : 1, originY: 1, height: shellHeight ? `${shellHeight}px` : '100%' }"
348
- :class="position === 'left' ? 'left-0' : 'right-0'"
354
+ :style="{ originX: alignsLeft ? 0 : 1, originY: 1, height: shellHeight ? `${shellHeight}px` : '100%' }"
355
+ :class="alignsLeft ? 'left-0' : 'right-0'"
349
356
  class="absolute bottom-0 w-[min(480px,calc(100vw-32px))] flex flex-col"
350
357
  >
351
358
  <slot />
@@ -0,0 +1,49 @@
1
+ import { createGlobalState, useLocalStorage } from '@vueuse/core'
2
+
3
+ /** Horizontal position of the launcher along the bottom edge: 0 is the left end, 1 the right end. */
4
+ export type FloatingLauncherPosition = number
5
+
6
+ /** Within this distance of an end, a dropped launcher snaps to it. */
7
+ export const LAUNCHER_EDGE_SNAP_PX = 24
8
+
9
+ /**
10
+ * Position the user moved the chat launcher to, shared by every launcher on the page and persisted.
11
+ * `null` until the user moves it, so each launcher keeps its own default end.
12
+ */
13
+ export const useFloatingLauncherPosition = createGlobalState(() =>
14
+ useLocalStorage<FloatingLauncherPosition | null>('tela-chat-launcher-position', null, {
15
+ serializer: {
16
+ read: (value) => {
17
+ const position = Number.parseFloat(value)
18
+ return Number.isFinite(position) ? clampLauncherPosition(position) : null
19
+ },
20
+ write: value => value === null ? '' : String(value),
21
+ },
22
+ }),
23
+ )
24
+
25
+ export function clampLauncherPosition(position: number) {
26
+ return Math.min(1, Math.max(0, position))
27
+ }
28
+
29
+ export function isLauncherOnLeftHalf(position: FloatingLauncherPosition) {
30
+ return position < 0.5
31
+ }
32
+
33
+ /** CSS lengths of the gaps the launcher keeps from the left and right edges. */
34
+ export function launcherGutters(contained = false) {
35
+ return {
36
+ left: 'calc(16px + var(--tela-floating-window-inset-left, 0px))',
37
+ right: contained ? '16px' : 'calc(16px + var(--scrollbar-width, 0px))',
38
+ }
39
+ }
40
+
41
+ /** Places the launcher `position` of the way along the bottom edge, between the gutters. */
42
+ export function floatingLauncherPositionStyle(position: FloatingLauncherPosition, contained = false) {
43
+ const gutters = launcherGutters(contained)
44
+
45
+ return {
46
+ left: `calc(${gutters.left} + (100% - ${gutters.left} - ${gutters.right}) * ${position})`,
47
+ translate: `calc(-100% * ${position}) 0`,
48
+ }
49
+ }
@@ -26,6 +26,7 @@ export interface TelaLabels {
26
26
  pause: string
27
27
  toggleReplies: string
28
28
  deleteTag: string
29
+ moveLauncherHint: string
29
30
  selectColor: (color: string) => string
30
31
  }
31
32
 
@@ -53,6 +54,7 @@ export const DEFAULT_TELA_LABELS: TelaLabels = {
53
54
  pause: 'Pause',
54
55
  toggleReplies: 'Replies',
55
56
  deleteTag: 'Delete tag',
57
+ moveLauncherHint: 'Slide along the bottom and release · Esc to cancel',
56
58
  selectColor: color => `Select ${color}`,
57
59
  }
58
60
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/tela-build",
3
- "version": "1.101.0",
3
+ "version": "1.102.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "app.config.ts",