@leavepulse/ui 0.22.21 → 0.22.22
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/dist/chunks/{LpAddressInput-CxKwIG6T.js → LpAddressInput-peTpNSJK.js} +3 -3
- package/dist/chunks/{LpAppShell-D8CAP9oF.js → LpAppShell-CaQYQKZV.js} +25 -14
- package/dist/chunks/{LpConfirmDialog-CmgeAdCh.js → LpConfirmDialog-DOU_zaTI.js} +1 -1
- package/dist/chunks/{LpFormField-Bn-ZwC6z.js → LpFormField-CesaPWPO.js} +12 -6
- package/dist/chunks/{LpInput-BkomKdqQ.js → LpInput-BfLIWV-P.js} +1 -1
- package/dist/chunks/{LpModal-CNNSf5pv.js → LpModal-D_o-56To.js} +13 -76
- package/dist/chunks/{LpNotificationBell-DWDEkmdA.js → LpNotificationBell-a08cl0yY.js} +67 -61
- package/dist/chunks/{LpPasswordInput-DgUC2Ur7.js → LpPasswordInput-BfjDrvZq.js} +1 -1
- package/dist/chunks/LpShift-DXNsauQZ.js +40 -0
- package/dist/chunks/{LpTextarea-CRAkhemZ.js → LpTextarea-BDl7PR9U.js} +1 -1
- package/dist/component-names.d.ts +1 -1
- package/dist/components/LpAddressInput.vue.js +1 -1
- package/dist/components/LpAppShell.vue.d.ts +6 -6
- package/dist/components/LpAppShell.vue.js +1 -1
- package/dist/components/LpConfirmDialog.vue.js +1 -1
- package/dist/components/LpFormField.vue.js +1 -1
- package/dist/components/LpInput.vue.js +1 -1
- package/dist/components/LpModal.vue.js +1 -1
- package/dist/components/LpNotificationBell.vue.js +1 -1
- package/dist/components/LpPasswordInput.vue.js +1 -1
- package/dist/components/LpShift.vue.d.ts +36 -0
- package/dist/components/LpShift.vue.js +4 -0
- package/dist/components/LpShortcutsDialog.vue.js +1 -1
- package/dist/components/LpTextarea.vue.js +1 -1
- package/dist/composables/useShift.d.ts +35 -0
- package/dist/composables/useShift.js +112 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +44 -40
- package/package.json +1 -1
- package/src/component-names.ts +1 -0
- package/src/components/LpAppShell.vue +27 -7
- package/src/components/LpFormField.vue +19 -2
- package/src/components/LpModal.vue +20 -128
- package/src/components/LpNotificationBell.vue +48 -42
- package/src/components/LpShift.vue +90 -0
- package/src/composables/useShift.ts +236 -0
- package/src/index.ts +3 -0
|
@@ -16,6 +16,7 @@ import LpEmptyState from "./LpEmptyState.vue"
|
|
|
16
16
|
import LpIcon from "./LpIcon.vue"
|
|
17
17
|
import LpPopover from "./LpPopover.vue"
|
|
18
18
|
import LpScrollArea from "./LpScrollArea.vue"
|
|
19
|
+
import LpShift from "./LpShift.vue"
|
|
19
20
|
|
|
20
21
|
export interface NotificationItem {
|
|
21
22
|
id: string
|
|
@@ -225,52 +226,57 @@ function timeAgo(iso?: string): string {
|
|
|
225
226
|
</button>
|
|
226
227
|
</header>
|
|
227
228
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
<!-- Skeleton → empty → feed are three different heights, so the panel
|
|
230
|
+
jumped as the list loaded and again whenever it emptied. Easing the
|
|
231
|
+
swap keeps the popover from snapping under the bell. -->
|
|
232
|
+
<LpShift axis="height">
|
|
233
|
+
<div v-if="loading" class="space-y-1.5 px-2 pb-2">
|
|
234
|
+
<div v-for="i in 4" :key="i" class="h-12 animate-pulse rounded-control bg-surface-soft" />
|
|
235
|
+
</div>
|
|
231
236
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
237
|
+
<LpEmptyState
|
|
238
|
+
v-else-if="!items.length"
|
|
239
|
+
icon="lucide:bell-off"
|
|
240
|
+
:title="l.empty"
|
|
241
|
+
class="px-3 py-10"
|
|
242
|
+
/>
|
|
238
243
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
>
|
|
252
|
-
<span
|
|
253
|
-
class="grid size-7 shrink-0 place-items-center rounded-control"
|
|
254
|
-
:class="item.read ? 'bg-surface-soft text-muted' : 'bg-brand-soft text-brand'"
|
|
244
|
+
<!-- The feed sits in a thin gutter; rows are self-contained tiles (rounded,
|
|
245
|
+
hover-lit) instead of full-width strips with hard dividers — lighter and
|
|
246
|
+
easier to scan. Each row carries its own right-click action menu. -->
|
|
247
|
+
<LpScrollArea v-else class="max-h-96" content-class="flex flex-col gap-0.5 px-2 pb-2">
|
|
248
|
+
<LpContextMenu v-for="item in items" :key="item.id" :items="rowMenu(item)">
|
|
249
|
+
<component
|
|
250
|
+
:is="item.link ? 'a' : 'button'"
|
|
251
|
+
:href="item.link || undefined"
|
|
252
|
+
:type="item.link ? undefined : 'button'"
|
|
253
|
+
class="group/notif flex w-full items-start gap-2.5 rounded-control px-2 py-2 text-left outline-none transition-colors hover:bg-white/[0.05] focus-visible:bg-white/[0.05]"
|
|
254
|
+
:class="item.read ? '' : 'bg-brand-soft/35'"
|
|
255
|
+
@click="onSelect(item)"
|
|
255
256
|
>
|
|
256
|
-
<
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
<
|
|
261
|
-
{{ item.title }}
|
|
262
|
-
</span>
|
|
263
|
-
<span v-if="!item.read" class="size-1.5 shrink-0 rounded-full bg-brand" />
|
|
257
|
+
<span
|
|
258
|
+
class="grid size-7 shrink-0 place-items-center rounded-control"
|
|
259
|
+
:class="item.read ? 'bg-surface-soft text-muted' : 'bg-brand-soft text-brand'"
|
|
260
|
+
>
|
|
261
|
+
<LpIcon :name="item.icon || 'lucide:bell'" :size="15" />
|
|
264
262
|
</span>
|
|
265
|
-
<span
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
263
|
+
<span class="min-w-0 flex-1">
|
|
264
|
+
<span class="flex items-center gap-1.5">
|
|
265
|
+
<span class="truncate text-sm font-medium" :class="item.read ? 'text-muted-strong' : 'text-ink'">
|
|
266
|
+
{{ item.title }}
|
|
267
|
+
</span>
|
|
268
|
+
<span v-if="!item.read" class="size-1.5 shrink-0 rounded-full bg-brand" />
|
|
269
|
+
</span>
|
|
270
|
+
<span v-if="item.body" class="mt-0.5 line-clamp-2 block text-xs text-muted">
|
|
271
|
+
{{ item.body }}
|
|
272
|
+
</span>
|
|
273
|
+
<span v-if="item.createdAt" class="mt-0.5 block text-[11px] text-muted/70">
|
|
274
|
+
{{ timeAgo(item.createdAt) }}
|
|
275
|
+
</span>
|
|
270
276
|
</span>
|
|
271
|
-
</
|
|
272
|
-
</
|
|
273
|
-
</
|
|
274
|
-
</
|
|
277
|
+
</component>
|
|
278
|
+
</LpContextMenu>
|
|
279
|
+
</LpScrollArea>
|
|
280
|
+
</LpShift>
|
|
275
281
|
</LpPopover>
|
|
276
282
|
</template>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Wraps content whose size is derived from what's inside it, so that everything
|
|
4
|
+
* around it shifts smoothly instead of jumping.
|
|
5
|
+
*
|
|
6
|
+
* Reach for it wherever a change of content changes a box's measurements: a
|
|
7
|
+
* toolbar that gains or loses a button, a label swapped by a translation, a
|
|
8
|
+
* placeholder replaced by the loaded thing, a validation message appearing
|
|
9
|
+
* under a field. Those all resize in a single frame otherwise, and everything
|
|
10
|
+
* they push jolts with them.
|
|
11
|
+
*
|
|
12
|
+
* <LpShift axis="width">
|
|
13
|
+
* <slot name="actions" />
|
|
14
|
+
* </LpShift>
|
|
15
|
+
*
|
|
16
|
+
* Note it is the NEIGHBOURS that motivate this, not the box: a fixed-height
|
|
17
|
+
* header never resizes, yet its controls jump whenever one of them changes
|
|
18
|
+
* width. Easing that one box is what makes the row glide.
|
|
19
|
+
*
|
|
20
|
+
* Content is measured through a wrapper that is never itself pinned, so the
|
|
21
|
+
* slot keeps whatever layout it brings (flex row, grid, plain text). `axis`
|
|
22
|
+
* picks which dimension is content-derived: pin only the one that actually
|
|
23
|
+
* moves, so the other stays free to respond to the surrounding layout.
|
|
24
|
+
*
|
|
25
|
+
* The mechanism — measure the natural size, pin it in pixels, tween — lives in
|
|
26
|
+
* `useShift`, and LpModal drives its panel with the same composable.
|
|
27
|
+
*/
|
|
28
|
+
import { computed } from "vue"
|
|
29
|
+
import { useShift, type ShiftAxis } from "../composables/useShift"
|
|
30
|
+
|
|
31
|
+
const props = withDefaults(
|
|
32
|
+
defineProps<{
|
|
33
|
+
/**
|
|
34
|
+
* Which dimension eases. `"width"` for a row that gains/loses controls,
|
|
35
|
+
* `"height"` for a stack whose content grows, `"both"` when either can.
|
|
36
|
+
*/
|
|
37
|
+
axis?: ShiftAxis
|
|
38
|
+
/** Tween length in ms. Defaults to the kit's `--duration-fast`. */
|
|
39
|
+
duration?: number
|
|
40
|
+
/**
|
|
41
|
+
* Turn the easing off entirely — the wrapper stays, the box resizes
|
|
42
|
+
* instantly. For a box that is being driven by something else (a drag, a
|
|
43
|
+
* canvas), where a tween would fight the thing already animating it.
|
|
44
|
+
*/
|
|
45
|
+
disabled?: boolean
|
|
46
|
+
}>(),
|
|
47
|
+
{ axis: "height", disabled: false },
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const { el, tweening, resizing } = useShift({
|
|
51
|
+
axis: () => props.axis,
|
|
52
|
+
duration: () => props.duration,
|
|
53
|
+
enabled: () => !props.disabled,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// Only the pinned axis is transitioned: naming the other one would animate a
|
|
57
|
+
// dimension the layout is still free to set, so a flex row settling into place
|
|
58
|
+
// would ease sideways for no reason.
|
|
59
|
+
//
|
|
60
|
+
// Spelled out as whole literals rather than built from `axis`. The consuming
|
|
61
|
+
// app's Tailwind scans this file as TEXT, so a class assembled at runtime is a
|
|
62
|
+
// class it never sees — the utility simply wouldn't be emitted.
|
|
63
|
+
const TRANSITION_CLASS: Record<ShiftAxis, string> = {
|
|
64
|
+
height: "transition-[height]",
|
|
65
|
+
width: "transition-[width]",
|
|
66
|
+
both: "transition-[height,width]",
|
|
67
|
+
}
|
|
68
|
+
const transitionClass = computed(() => TRANSITION_CLASS[props.axis])
|
|
69
|
+
|
|
70
|
+
defineExpose({ resizing })
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<template>
|
|
74
|
+
<!-- `overflow-hidden` only while a tween owns the size: the box is briefly
|
|
75
|
+
smaller than the content it already holds, and without the clip that
|
|
76
|
+
content spills past the easing edge. Dropped once settled, so nothing
|
|
77
|
+
that legitimately overflows — a dropdown, a focus ring — is clipped at
|
|
78
|
+
rest. -->
|
|
79
|
+
<div
|
|
80
|
+
ref="el"
|
|
81
|
+
:class="[
|
|
82
|
+
tweening && !disabled
|
|
83
|
+
? `${transitionClass} duration-fast ease-[var(--ease-emphasized)] motion-reduce:transition-none`
|
|
84
|
+
: '',
|
|
85
|
+
resizing ? 'overflow-hidden' : '',
|
|
86
|
+
]"
|
|
87
|
+
>
|
|
88
|
+
<slot :resizing="resizing" />
|
|
89
|
+
</div>
|
|
90
|
+
</template>
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { onBeforeUnmount, ref, toValue, watch, type MaybeRefOrGetter, type Ref } from "vue"
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* "Let this box shift its neighbours smoothly instead of jolting them."
|
|
5
|
+
*
|
|
6
|
+
* A box sized by what's inside it resizes in a single frame: a button appears
|
|
7
|
+
* in a toolbar, a translation swaps a short word for a long one, a placeholder
|
|
8
|
+
* is replaced by the loaded thing — and the layout snaps. Every neighbour it
|
|
9
|
+
* pushes snaps with it.
|
|
10
|
+
*
|
|
11
|
+
* The easing is applied to the BOX, but the point of it is the neighbours. A
|
|
12
|
+
* header of fixed height never resizes, yet the controls inside it jump the
|
|
13
|
+
* moment one of them changes width; giving that one box its width back
|
|
14
|
+
* gradually is what turns the jump into a glide. So this is named for what the
|
|
15
|
+
* user sees — things shifting — not for the measurement that achieves it.
|
|
16
|
+
*
|
|
17
|
+
* CSS alone cannot smooth this. `width`/`height: auto` are not interpolable,
|
|
18
|
+
* and the keyword-interpolation escape hatches (`interpolate-size`,
|
|
19
|
+
* `calc-size()`) are Chromium-only, so they'd do nothing in the WebKitGTK
|
|
20
|
+
* launcher. Measuring the natural size and pinning it in pixels is what works
|
|
21
|
+
* on every engine.
|
|
22
|
+
*
|
|
23
|
+
* This was first solved inside LpModal, whose panel grows as its body arrives.
|
|
24
|
+
* The mechanism is the same wherever content drives size, so it lives here and
|
|
25
|
+
* LpModal consumes it — see also LpShift, the wrapper form.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export type ShiftAxis = "height" | "width" | "both"
|
|
29
|
+
|
|
30
|
+
export interface UseShiftOptions {
|
|
31
|
+
/** Which dimension is content-derived. Default `"height"`. */
|
|
32
|
+
axis?: MaybeRefOrGetter<ShiftAxis | undefined>
|
|
33
|
+
/** Tween length. Defaults to the kit's `--duration-fast` (160ms). */
|
|
34
|
+
duration?: MaybeRefOrGetter<number | undefined>
|
|
35
|
+
/**
|
|
36
|
+
* Gate: while falsy the element is left entirely alone — no observers, no
|
|
37
|
+
* pinning. Use it for a box that only exists while something is open, so a
|
|
38
|
+
* remounted element starts measuring from scratch rather than easing in from
|
|
39
|
+
* a size it held in a previous life. Default: always active.
|
|
40
|
+
*/
|
|
41
|
+
enabled?: MaybeRefOrGetter<unknown>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface UseShift {
|
|
45
|
+
/** Attach to the element whose content-derived size should ease. */
|
|
46
|
+
el: Ref<HTMLElement | null>
|
|
47
|
+
/**
|
|
48
|
+
* True while a tween owns the size. Bind the transition utilities off this,
|
|
49
|
+
* so the element is only transition-enabled once it has a size to ease FROM
|
|
50
|
+
* (otherwise the very first pin animates in from zero).
|
|
51
|
+
*/
|
|
52
|
+
tweening: Ref<boolean>
|
|
53
|
+
/**
|
|
54
|
+
* True while the element is still catching up to its new size. During the
|
|
55
|
+
* tween the box is briefly smaller than the content it already holds, so any
|
|
56
|
+
* scroll region inside it would raise a bar for an overflow that resolves
|
|
57
|
+
* itself as the tween lands — hide the bar (not the scrolling) on this.
|
|
58
|
+
*/
|
|
59
|
+
resizing: Ref<boolean>
|
|
60
|
+
/** Re-measure and ease to the current natural size. Rarely needed by hand. */
|
|
61
|
+
retune: () => void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Kept in step with the `duration-fast` token the transition utilities use. */
|
|
65
|
+
const TWEEN_MS = 160
|
|
66
|
+
|
|
67
|
+
export function useShift(
|
|
68
|
+
options: UseShiftOptions = {},
|
|
69
|
+
): UseShift {
|
|
70
|
+
const el = ref<HTMLElement | null>(null)
|
|
71
|
+
const tweening = ref(false)
|
|
72
|
+
const resizing = ref(false)
|
|
73
|
+
|
|
74
|
+
let ro: ResizeObserver | undefined
|
|
75
|
+
let mo: MutationObserver | undefined
|
|
76
|
+
let raf = 0
|
|
77
|
+
let settleTimer: ReturnType<typeof setTimeout> | undefined
|
|
78
|
+
/** Where the box last settled, so a retune has a size to ease FROM. */
|
|
79
|
+
let lastHeight = 0
|
|
80
|
+
let lastWidth = 0
|
|
81
|
+
/** True while a tween owns the size, so observers don't cancel it midway. */
|
|
82
|
+
let inFlight = false
|
|
83
|
+
|
|
84
|
+
const axisOf = () => toValue(options.axis) ?? "height"
|
|
85
|
+
const wantsHeight = () => axisOf() !== "width"
|
|
86
|
+
const wantsWidth = () => axisOf() !== "height"
|
|
87
|
+
|
|
88
|
+
function reducedMotion() {
|
|
89
|
+
return (
|
|
90
|
+
typeof window !== "undefined" &&
|
|
91
|
+
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
* The size is driven imperatively rather than through a style binding. By the
|
|
97
|
+
* time replacement content is in the DOM the box has already reflowed to its
|
|
98
|
+
* new size, so a bound value would only ever be written once, with no earlier
|
|
99
|
+
* size for the transition to start from. Writing the OLD size, forcing a
|
|
100
|
+
* reflow, then writing the new one gives the transition both ends.
|
|
101
|
+
*/
|
|
102
|
+
function retune() {
|
|
103
|
+
const node = el.value
|
|
104
|
+
if (!node) return
|
|
105
|
+
// One swap wakes both observers — the mutation as content lands, the resize
|
|
106
|
+
// as it reflows — and the second call would clear the pin the first wrote.
|
|
107
|
+
if (inFlight) return
|
|
108
|
+
|
|
109
|
+
// Remembered, not measured: by the time either observer fires the box has
|
|
110
|
+
// already reflowed, so the element can only report where it is going.
|
|
111
|
+
const fromHeight = lastHeight
|
|
112
|
+
const fromWidth = lastWidth
|
|
113
|
+
|
|
114
|
+
// Measured with any cap lifted, then the clamp is left to CSS. A `max-*`
|
|
115
|
+
// from a class makes the element report the clipped figure once the cap
|
|
116
|
+
// bites, and pinning that would hold the box short of the content it now
|
|
117
|
+
// has to fit.
|
|
118
|
+
if (wantsHeight()) {
|
|
119
|
+
node.style.height = ""
|
|
120
|
+
node.style.maxHeight = "none"
|
|
121
|
+
}
|
|
122
|
+
if (wantsWidth()) {
|
|
123
|
+
node.style.width = ""
|
|
124
|
+
node.style.maxWidth = "none"
|
|
125
|
+
}
|
|
126
|
+
const toHeight = wantsHeight() ? node.offsetHeight : 0
|
|
127
|
+
const toWidth = wantsWidth() ? node.offsetWidth : 0
|
|
128
|
+
if (wantsHeight()) node.style.maxHeight = ""
|
|
129
|
+
if (wantsWidth()) node.style.maxWidth = ""
|
|
130
|
+
lastHeight = toHeight
|
|
131
|
+
lastWidth = toWidth
|
|
132
|
+
|
|
133
|
+
// Nothing moved on either axis, so there is nothing to ease — and leaving
|
|
134
|
+
// the size unset keeps the box free to size itself.
|
|
135
|
+
//
|
|
136
|
+
// Only the FROM size has to be non-zero. A target of zero is a real
|
|
137
|
+
// collapse — the last message cleared, the list emptied — and is exactly
|
|
138
|
+
// the case worth easing; an earlier guard against `to === 0` silently
|
|
139
|
+
// dropped it, so content vanishing still snapped. A zero FROM is the
|
|
140
|
+
// different thing it was meant to catch: the box was not in the layout yet,
|
|
141
|
+
// so there is no size to ease out of.
|
|
142
|
+
const movesHeight =
|
|
143
|
+
wantsHeight() && fromHeight !== 0 && toHeight !== fromHeight
|
|
144
|
+
const movesWidth = wantsWidth() && fromWidth !== 0 && toWidth !== fromWidth
|
|
145
|
+
if (!movesHeight && !movesWidth) return
|
|
146
|
+
|
|
147
|
+
if (movesHeight) node.style.height = `${fromHeight}px`
|
|
148
|
+
if (movesWidth) node.style.width = `${fromWidth}px`
|
|
149
|
+
void node.offsetHeight
|
|
150
|
+
if (movesHeight) node.style.height = `${toHeight}px`
|
|
151
|
+
if (movesWidth) node.style.width = `${toWidth}px`
|
|
152
|
+
|
|
153
|
+
inFlight = true
|
|
154
|
+
resizing.value = true
|
|
155
|
+
clearTimeout(settleTimer)
|
|
156
|
+
const wait = reducedMotion() ? 0 : (toValue(options.duration) ?? TWEEN_MS)
|
|
157
|
+
settleTimer = setTimeout(() => {
|
|
158
|
+
inFlight = false
|
|
159
|
+
resizing.value = false
|
|
160
|
+
// Released once the box has arrived. A size left pinned in pixels stops
|
|
161
|
+
// being a starting point and becomes a cap: content that grows afterwards
|
|
162
|
+
// is clipped, and `max-*` can no longer size the element itself.
|
|
163
|
+
node.style.height = ""
|
|
164
|
+
node.style.width = ""
|
|
165
|
+
// Re-read rather than trusting the target: a `max-*` may have clamped the
|
|
166
|
+
// box short of it, and the next tween has to start from where it sits.
|
|
167
|
+
lastHeight = node.offsetHeight
|
|
168
|
+
lastWidth = node.offsetWidth
|
|
169
|
+
}, wait)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function teardown() {
|
|
173
|
+
ro?.disconnect()
|
|
174
|
+
mo?.disconnect()
|
|
175
|
+
ro = undefined
|
|
176
|
+
mo = undefined
|
|
177
|
+
cancelAnimationFrame(raf)
|
|
178
|
+
clearTimeout(settleTimer)
|
|
179
|
+
tweening.value = false
|
|
180
|
+
resizing.value = false
|
|
181
|
+
lastHeight = 0
|
|
182
|
+
lastWidth = 0
|
|
183
|
+
inFlight = false
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Keyed off the element AND the gate: a portalled box remounts on every open,
|
|
187
|
+
// and the teardown has to run on close, when the ref is already gone.
|
|
188
|
+
watch(
|
|
189
|
+
[el, () => toValue(options.enabled) ?? true],
|
|
190
|
+
([node, enabled]) => {
|
|
191
|
+
teardown()
|
|
192
|
+
if (!enabled || !node) return
|
|
193
|
+
|
|
194
|
+
lastHeight = node.offsetHeight
|
|
195
|
+
lastWidth = node.offsetWidth
|
|
196
|
+
if (wantsHeight()) node.style.height = `${lastHeight}px`
|
|
197
|
+
if (wantsWidth()) node.style.width = `${lastWidth}px`
|
|
198
|
+
// A box must not animate in from its pre-content size, so the transition
|
|
199
|
+
// only arms once that first pin has painted. The pin is dropped in the
|
|
200
|
+
// same frame: it exists to give the first `retune` something to start
|
|
201
|
+
// from, and holding it would cap the box at its opening size.
|
|
202
|
+
raf = requestAnimationFrame(() => {
|
|
203
|
+
tweening.value = true
|
|
204
|
+
node.style.height = ""
|
|
205
|
+
node.style.width = ""
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
// Two triggers, since either can move the size alone: the resize observer
|
|
209
|
+
// catches a child growing in place (an image decoding, a list filling
|
|
210
|
+
// in), the mutation observer catches one subtree swapped for another,
|
|
211
|
+
// where every observed box may keep its size. Children are observed,
|
|
212
|
+
// never the element itself — that would feed the pin straight back in.
|
|
213
|
+
const watchChildren = () => {
|
|
214
|
+
if (!ro) return
|
|
215
|
+
ro.disconnect()
|
|
216
|
+
for (const child of Array.from(node.children)) ro.observe(child)
|
|
217
|
+
}
|
|
218
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
219
|
+
ro = new ResizeObserver(() => retune())
|
|
220
|
+
watchChildren()
|
|
221
|
+
}
|
|
222
|
+
if (typeof MutationObserver !== "undefined") {
|
|
223
|
+
mo = new MutationObserver(() => {
|
|
224
|
+
watchChildren()
|
|
225
|
+
retune()
|
|
226
|
+
})
|
|
227
|
+
mo.observe(node, { childList: true, subtree: true, characterData: true })
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
{ flush: "post" },
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
onBeforeUnmount(teardown)
|
|
234
|
+
|
|
235
|
+
return { el, tweening, resizing, retune }
|
|
236
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -99,6 +99,7 @@ export { default as LpSelect } from "./components/LpSelect.vue"
|
|
|
99
99
|
export type { SelectOption, SelectValue } from "./components/LpSelect.vue"
|
|
100
100
|
export { default as LpServiceNode } from "./components/LpServiceNode.vue"
|
|
101
101
|
export type { ServiceNodeData } from "./components/LpServiceNode.vue"
|
|
102
|
+
export { default as LpShift } from "./components/LpShift.vue"
|
|
102
103
|
export { default as LpShortcutsDialog } from "./components/LpShortcutsDialog.vue"
|
|
103
104
|
export type { ShortcutEntry, ShortcutGroup } from "./components/LpShortcutsDialog.vue"
|
|
104
105
|
export { default as LpSidebar } from "./components/LpSidebar.vue"
|
|
@@ -192,6 +193,8 @@ export { useRovingFocus } from "./composables/useRovingFocus"
|
|
|
192
193
|
export type { RovingItem, UseRovingFocusOptions } from "./composables/useRovingFocus"
|
|
193
194
|
export { useSettled } from "./composables/useSettled"
|
|
194
195
|
export type { UseSettledOptions } from "./composables/useSettled"
|
|
196
|
+
export { useShift } from "./composables/useShift"
|
|
197
|
+
export type { ShiftAxis, UseShift, UseShiftOptions } from "./composables/useShift"
|
|
195
198
|
export { useTilt } from "./composables/useTilt"
|
|
196
199
|
export type { UseTilt, UseTiltOptions } from "./composables/useTilt"
|
|
197
200
|
export { useZoomPan } from "./composables/useZoomPan"
|