✨ feat(core): 实现详情面板动画逻辑并完善相关测试
* 新增 detailMotion 工具类以支持更精细的动画控制 * 优化 FileManageView 面板渲染逻辑,改用 v-show 提升交互性能 * 调整 Transition 组件为手动控制模式以适配自定义动画 * 在 package.json 中配置自动化测试脚本 * 补充 detailMotion 相关的单元测试与测试说明文档
This commit is contained in:
1 parent
9bac0c0040
commit
af009cf3c5
6 files changed
+307
-138
No files matched your search
@@ -5,6 +5,8 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
"test:motion": "node --experimental-strip-types --test tests/detailMotion.test.mjs",
|
||||||
|
"test:motion:coverage": "node --experimental-strip-types --test --experimental-test-coverage --test-coverage-include=src/utils/detailMotion.ts tests/detailMotion.test.mjs",
|
||||||
"build": "run-s check:architecture type-check build-only",
|
"build": "run-s check:architecture type-check build-only",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"build-only": "vite build",
|
"build-only": "vite build",
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/** Own only detail animations; release filled effects before returning to auto layout. */
|
||||||
|
export function createDetailMotion(reducedMotion: () => boolean) {
|
||||||
|
const active = new Map<HTMLElement, () => void>()
|
||||||
|
const cancel = (element: HTMLElement) => active.get(element)?.()
|
||||||
|
const play = (
|
||||||
|
element: HTMLElement,
|
||||||
|
keyframes: Keyframe[],
|
||||||
|
options: KeyframeAnimationOptions,
|
||||||
|
done: () => void
|
||||||
|
) => {
|
||||||
|
cancel(element)
|
||||||
|
if (reducedMotion()) {
|
||||||
|
done()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const animation = element.animate(keyframes, { fill: 'both', ...options })
|
||||||
|
const settle = () => {
|
||||||
|
animation.removeEventListener('finish', settle)
|
||||||
|
animation.removeEventListener('cancel', settle)
|
||||||
|
active.delete(element)
|
||||||
|
animation.cancel()
|
||||||
|
done()
|
||||||
|
}
|
||||||
|
active.set(element, settle)
|
||||||
|
animation.addEventListener('finish', settle, { once: true })
|
||||||
|
animation.addEventListener('cancel', settle, { once: true })
|
||||||
|
}
|
||||||
|
const dispose = () => [...active.values()].forEach(settle => settle())
|
||||||
|
return { play, cancel, dispose }
|
||||||
|
}
|
||||||
@@ -71,8 +71,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Transition name="fcb-expand-120" @before-enter="beforeExpandPanelEnter" @enter="enterExpandPanel" @after-enter="afterExpandPanelEnter" @before-leave="beforeExpandPanelLeave" @leave="leaveExpandPanel">
|
<Transition :css="false" @before-enter="beforeExpandPanelEnter" @enter="enterExpandPanel" @after-enter="afterExpandPanelEnter" @before-leave="beforeExpandPanelLeave" @leave="leaveExpandPanel">
|
||||||
<div id="file-filter-panel" v-if="filterBodyVisible" class="fcb-expand-content mt-4 grid gap-4">
|
<div id="file-filter-panel" v-show="filterBodyVisible" class="fcb-expand-content mt-4 grid gap-4">
|
||||||
<div class="flex flex-col gap-3 lg:flex-row lg:items-center">
|
<div class="flex flex-col gap-3 lg:flex-row lg:items-center">
|
||||||
<label class="min-w-0 flex-1">
|
<label class="min-w-0 flex-1">
|
||||||
<span class="sr-only">{{ t('fileManage.searchPlaceholder') }}</span>
|
<span class="sr-only">{{ t('fileManage.searchPlaceholder') }}</span>
|
||||||
@@ -1227,7 +1227,7 @@
|
|||||||
<TransitionGroup
|
<TransitionGroup
|
||||||
:css="false"
|
:css="false"
|
||||||
tag="div"
|
tag="div"
|
||||||
ref="lifecycleListRef" class="fcb-lifecycle-list"
|
class="fcb-lifecycle-list"
|
||||||
@before-enter="beforeLifecycleRowEnter"
|
@before-enter="beforeLifecycleRowEnter"
|
||||||
@enter="enterLifecycleRow"
|
@enter="enterLifecycleRow"
|
||||||
@leave="leaveLifecycleRow"
|
@leave="leaveLifecycleRow"
|
||||||
@@ -1246,7 +1246,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="fcb-lifecycle-card theme-2026-card-hover mb-2.5 rounded-[16px] border px-3 py-2 shadow-sm transition-all duration-200 hover:shadow-md last:mb-0 sm:rounded-[20px]"
|
class="fcb-lifecycle-card theme-2026-card-hover rounded-[16px] border px-3 py-2 shadow-sm transition-all duration-200 hover:shadow-md sm:rounded-[20px]"
|
||||||
:class="[
|
:class="[
|
||||||
isDarkMode ? 'border-gray-700 bg-gray-800/60' : 'border-gray-100 bg-gray-50'
|
isDarkMode ? 'border-gray-700 bg-gray-800/60' : 'border-gray-100 bg-gray-50'
|
||||||
]"
|
]"
|
||||||
@@ -1276,14 +1276,15 @@
|
|||||||
}}
|
}}
|
||||||
</button>
|
</button>
|
||||||
<Transition
|
<Transition
|
||||||
name="fcb-retrieval-panel"
|
:css="false"
|
||||||
@before-enter="beforeRetrievalPanelEnter"
|
@before-enter="beforeRetrievalPanelEnter"
|
||||||
@enter="enterRetrievalPanel"
|
@enter="enterRetrievalPanel"
|
||||||
@after-enter="afterRetrievalPanelEnter"
|
@after-enter="afterRetrievalPanelEnter"
|
||||||
@before-leave="beforeRetrievalPanelLeave"
|
@before-leave="beforeRetrievalPanelLeave"
|
||||||
@leave="leaveRetrievalPanel"
|
@leave="leaveRetrievalPanel"
|
||||||
>
|
>
|
||||||
<div v-if="isRetrievalHistoryExpanded" class="mt-2.5 space-y-1.5">
|
<div v-show="isRetrievalHistoryExpanded" class="fcb-retrieval-panel">
|
||||||
|
<div class="space-y-1.5 pt-2.5">
|
||||||
<div
|
<div
|
||||||
v-for="(event, eventIndex) in retrievalTimelineEvents"
|
v-for="(event, eventIndex) in retrievalTimelineEvents"
|
||||||
:key="`${event.key}-${eventIndex}-${event.displayMeta}`"
|
:key="`${event.key}-${eventIndex}-${event.displayMeta}`"
|
||||||
@@ -1296,6 +1297,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<p class="mt-1 leading-5" :class="mutedTextClass">{{ event.displayDescription }}</p>
|
<p class="mt-1 leading-5" :class="mutedTextClass">{{ event.displayDescription }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
</div>
|
</div>
|
||||||
@@ -1751,6 +1753,7 @@ import BaseModal from '@/components/common/BaseModal.vue'
|
|||||||
import BaseButton from '@/components/common/BaseButton.vue'
|
import BaseButton from '@/components/common/BaseButton.vue'
|
||||||
import { useAdminFiles, useInjectedDarkMode, useTransferAnalytics } from '@/composables'
|
import { useAdminFiles, useInjectedDarkMode, useTransferAnalytics } from '@/composables'
|
||||||
import { formatFileSize, formatTimestamp } from '@/utils/common'
|
import { formatFileSize, formatTimestamp } from '@/utils/common'
|
||||||
|
import { createDetailMotion } from '@/utils/detailMotion'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const isDarkMode = useInjectedDarkMode()
|
const isDarkMode = useInjectedDarkMode()
|
||||||
@@ -1859,9 +1862,8 @@ const syncMobileViewport = (event: MediaQueryListEvent) => {
|
|||||||
isMobileViewport.value = event.matches
|
isMobileViewport.value = event.matches
|
||||||
}
|
}
|
||||||
const isLifecycleExpanded = ref(false)
|
const isLifecycleExpanded = ref(false)
|
||||||
const lifecycleListRef = ref<HTMLElement | null>(null)
|
|
||||||
const lifecycleViewportRef = ref<HTMLElement | null>(null)
|
const lifecycleViewportRef = ref<HTMLElement | null>(null)
|
||||||
let lifecycleHeightAnimation: Animation | null = null
|
let lifecycleHeightRevision = 0
|
||||||
const isRetrievalHistoryExpanded = ref(false)
|
const isRetrievalHistoryExpanded = ref(false)
|
||||||
const retrievalTimelineEvents = computed(() =>
|
const retrievalTimelineEvents = computed(() =>
|
||||||
(selectedFileDetail.value?.detailTimeline || []).filter((item) => item.key === 'retrieved_event')
|
(selectedFileDetail.value?.detailTimeline || []).filter((item) => item.key === 'retrieved_event')
|
||||||
@@ -1875,55 +1877,37 @@ const visibleDetailTimeline = computed(() =>
|
|||||||
isLifecycleExpanded.value ? detailTimelineRows.value : detailTimelineRows.value.slice(0, 3)
|
isLifecycleExpanded.value ? detailTimelineRows.value : detailTimelineRows.value.slice(0, 3)
|
||||||
)
|
)
|
||||||
|
|
||||||
const animateLifecycleHeight = async () => {
|
|
||||||
await nextTick()
|
|
||||||
const viewport = lifecycleViewportRef.value
|
|
||||||
if (!viewport || reducedMotionQuery.matches) return
|
|
||||||
lifecycleHeightAnimation?.cancel()
|
|
||||||
lifecycleHeightAnimation = null
|
|
||||||
viewport.style.height = ''
|
|
||||||
await nextTick()
|
|
||||||
const currentHeight = viewport.getBoundingClientRect().height
|
|
||||||
viewport.style.height = `${currentHeight}px`
|
|
||||||
await nextTick()
|
|
||||||
const targetHeight = viewport.scrollHeight
|
|
||||||
lifecycleHeightAnimation = viewport.animate(
|
|
||||||
[{ height: `${currentHeight}px` }, { height: `${targetHeight}px` }],
|
|
||||||
{ duration: 420, easing: 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'forwards' }
|
|
||||||
)
|
|
||||||
const cleanup = () => {
|
|
||||||
viewport.style.height = ''
|
|
||||||
lifecycleHeightAnimation = null
|
|
||||||
}
|
|
||||||
lifecycleHeightAnimation.addEventListener('finish', cleanup, { once: true })
|
|
||||||
lifecycleHeightAnimation.addEventListener('cancel', cleanup, { once: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
const LIFECYCLE_ENTER_MS = 160
|
|
||||||
const LIFECYCLE_LEAVE_MS = 120
|
|
||||||
const lifecycleEasing = 'cubic-bezier(0.22, 1, 0.36, 1)'
|
|
||||||
const lifecycleExitEasing = 'cubic-bezier(0.4, 0, 1, 1)'
|
|
||||||
watch(isLifecycleExpanded, animateLifecycleHeight)
|
|
||||||
|
|
||||||
const reducedMotionQuery = window.matchMedia('(prefers-reduced-motion: reduce)')
|
const reducedMotionQuery = window.matchMedia('(prefers-reduced-motion: reduce)')
|
||||||
|
const detailMotion = createDetailMotion(() => reducedMotionQuery.matches)
|
||||||
|
const playDetailAnimation = detailMotion.play
|
||||||
|
const PANEL_DURATION_MS = 420
|
||||||
|
const lifecycleEasing = 'cubic-bezier(0.32, 0.72, 0, 1)'
|
||||||
|
const LIFECYCLE_ENTER_MS = 180
|
||||||
|
const LIFECYCLE_LEAVE_MS = 120
|
||||||
|
|
||||||
const playDetailAnimation = (
|
// This watcher runs before Vue patches the rows: capture the visible starting
|
||||||
element: HTMLElement,
|
// height now, then measure the natural list height after leaving rows exit flow.
|
||||||
keyframes: Keyframe[],
|
watch(isLifecycleExpanded, async () => {
|
||||||
options: KeyframeAnimationOptions,
|
const revision = ++lifecycleHeightRevision
|
||||||
done: () => void
|
const viewport = lifecycleViewportRef.value
|
||||||
) => {
|
if (!viewport) return
|
||||||
if (reducedMotionQuery.matches) {
|
const from = viewport.getBoundingClientRect().height
|
||||||
done()
|
detailMotion.cancel(viewport)
|
||||||
return
|
viewport.style.height = `${from}px`
|
||||||
}
|
viewport.style.overflow = 'hidden'
|
||||||
|
await nextTick()
|
||||||
element.getAnimations().forEach((animation) => animation.cancel())
|
if (revision !== lifecycleHeightRevision || !viewport.isConnected) return
|
||||||
const animation = element.animate(keyframes, { fill: 'both', ...options })
|
const to = viewport.firstElementChild?.getBoundingClientRect().height ?? 0
|
||||||
const finish = () => done()
|
playDetailAnimation(
|
||||||
animation.addEventListener('finish', finish, { once: true })
|
viewport,
|
||||||
animation.addEventListener('cancel', finish, { once: true })
|
[{ height: `${from}px` }, { height: `${to}px` }],
|
||||||
}
|
{ duration: PANEL_DURATION_MS, easing: lifecycleEasing },
|
||||||
|
() => {
|
||||||
|
viewport.style.height = ''
|
||||||
|
viewport.style.overflow = ''
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const beforeLifecycleRowEnter = (element: Element) => {
|
const beforeLifecycleRowEnter = (element: Element) => {
|
||||||
const row = element as HTMLElement
|
const row = element as HTMLElement
|
||||||
@@ -1946,6 +1930,11 @@ const enterLifecycleRow = (element: Element, done: () => void) => {
|
|||||||
}
|
}
|
||||||
const leaveLifecycleRow = (element: Element, done: () => void) => {
|
const leaveLifecycleRow = (element: Element, done: () => void) => {
|
||||||
const row = element as HTMLElement
|
const row = element as HTMLElement
|
||||||
|
const width = row.getBoundingClientRect().width
|
||||||
|
const top = row.offsetTop
|
||||||
|
row.style.position = 'absolute'
|
||||||
|
row.style.top = `${top}px`
|
||||||
|
row.style.width = `${width}px`
|
||||||
row.style.willChange = 'opacity'
|
row.style.willChange = 'opacity'
|
||||||
playDetailAnimation(
|
playDetailAnimation(
|
||||||
row,
|
row,
|
||||||
@@ -1953,86 +1942,66 @@ const leaveLifecycleRow = (element: Element, done: () => void) => {
|
|||||||
{ opacity: 1 },
|
{ opacity: 1 },
|
||||||
{ opacity: 0 }
|
{ opacity: 0 }
|
||||||
],
|
],
|
||||||
{ duration: LIFECYCLE_LEAVE_MS, easing: lifecycleExitEasing },
|
{ duration: LIFECYCLE_LEAVE_MS, easing: lifecycleEasing },
|
||||||
() => {
|
() => {
|
||||||
row.style.willChange = ''
|
row.style.willChange = ''
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const beforeExpandPanelEnter = (element: Element) => {
|
const clearPanelStyles = (element: Element) => {
|
||||||
const panel = element as HTMLElement
|
|
||||||
panel.style.height = '0px'
|
|
||||||
panel.style.overflow = 'hidden'
|
|
||||||
}
|
|
||||||
const enterExpandPanel = (element: Element, done: () => void) => {
|
|
||||||
const panel = element as HTMLElement
|
|
||||||
const targetHeight = panel.scrollHeight
|
|
||||||
playDetailAnimation(panel, [{ height: '0px', opacity: 0 }, { height: `${targetHeight}px`, opacity: 1 }], { duration: 420, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' }, done)
|
|
||||||
}
|
|
||||||
const afterExpandPanelEnter = (element: Element) => {
|
|
||||||
const panel = element as HTMLElement
|
|
||||||
panel.style.height = ''
|
|
||||||
panel.style.overflow = ''
|
|
||||||
}
|
|
||||||
const beforeExpandPanelLeave = (element: Element) => {
|
|
||||||
const panel = element as HTMLElement
|
|
||||||
panel.style.height = `${panel.scrollHeight}px`
|
|
||||||
panel.style.overflow = 'hidden'
|
|
||||||
}
|
|
||||||
const leaveExpandPanel = (element: Element, done: () => void) => {
|
|
||||||
const panel = element as HTMLElement
|
|
||||||
const currentHeight = panel.scrollHeight
|
|
||||||
playDetailAnimation(panel, [{ height: `${currentHeight}px`, opacity: 1 }, { height: '0px', opacity: 0 }], { duration: 320, easing: 'cubic-bezier(0.4, 0, 0.8, 0.2)' }, done)
|
|
||||||
}
|
|
||||||
|
|
||||||
const beforeRetrievalPanelEnter = (element: Element) => {
|
|
||||||
const panel = element as HTMLElement
|
|
||||||
panel.style.height = '0px'
|
|
||||||
panel.style.overflow = 'clip'
|
|
||||||
panel.style.willChange = 'height, opacity, transform'
|
|
||||||
}
|
|
||||||
const enterRetrievalPanel = (element: Element, done: () => void) => {
|
|
||||||
const panel = element as HTMLElement
|
|
||||||
const height = panel.scrollHeight
|
|
||||||
playDetailAnimation(
|
|
||||||
panel,
|
|
||||||
[
|
|
||||||
{ height: '0px', opacity: 0, transform: 'translate3d(0, -4px, 0)' },
|
|
||||||
{ height: `${height}px`, opacity: 1, transform: 'translate3d(0, 0, 0)' }
|
|
||||||
],
|
|
||||||
{ duration: LIFECYCLE_ENTER_MS, easing: lifecycleEasing },
|
|
||||||
done
|
|
||||||
)
|
|
||||||
}
|
|
||||||
const afterRetrievalPanelEnter = (element: Element) => {
|
|
||||||
const panel = element as HTMLElement
|
const panel = element as HTMLElement
|
||||||
panel.style.height = ''
|
panel.style.height = ''
|
||||||
panel.style.overflow = ''
|
panel.style.overflow = ''
|
||||||
panel.style.willChange = ''
|
panel.style.willChange = ''
|
||||||
}
|
}
|
||||||
const beforeRetrievalPanelLeave = (element: Element) => {
|
const beforeExpandPanelEnter = (element: Element) => {
|
||||||
const panel = element as HTMLElement
|
const panel = element as HTMLElement
|
||||||
panel.style.height = `${panel.scrollHeight}px`
|
// v-show briefly sets display:none while reversing leave; computed height
|
||||||
panel.style.overflow = 'clip'
|
// still includes the running effect, whereas the bounding box is then zero.
|
||||||
panel.style.willChange = 'height, opacity, transform'
|
const from = panel.style.height ? Number.parseFloat(getComputedStyle(panel).height) : 0
|
||||||
|
detailMotion.cancel(panel)
|
||||||
|
panel.style.height = `${from}px`
|
||||||
|
panel.style.overflow = 'hidden'
|
||||||
|
panel.style.willChange = 'height, opacity'
|
||||||
}
|
}
|
||||||
const leaveRetrievalPanel = (element: Element, done: () => void) => {
|
const enterExpandPanel = (element: Element, done: () => void) => {
|
||||||
const panel = element as HTMLElement
|
const panel = element as HTMLElement
|
||||||
const height = panel.scrollHeight
|
// Remove the frozen height while measuring: scrollHeight cannot measure a
|
||||||
playDetailAnimation(
|
// smaller destination when the element still has a larger explicit height.
|
||||||
panel,
|
const from = panel.getBoundingClientRect().height
|
||||||
[
|
panel.style.height = ''
|
||||||
{ height: `${height}px`, opacity: 1, transform: 'translate3d(0, 0, 0)' },
|
const to = panel.getBoundingClientRect().height
|
||||||
{ height: '0px', opacity: 0, transform: 'translate3d(0, -4px, 0)' }
|
panel.style.height = `${from}px`
|
||||||
],
|
playDetailAnimation(panel,
|
||||||
{ duration: LIFECYCLE_LEAVE_MS, easing: lifecycleExitEasing },
|
[{ height: `${from}px`, opacity: from > 0 ? 1 : 0 }, { height: `${to}px`, opacity: 1 }],
|
||||||
() => {
|
{ duration: PANEL_DURATION_MS, easing: lifecycleEasing },
|
||||||
panel.style.willChange = ''
|
() => { clearPanelStyles(panel); done() }
|
||||||
done()
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
const afterExpandPanelEnter = clearPanelStyles
|
||||||
|
const beforeExpandPanelLeave = (element: Element) => {
|
||||||
|
const panel = element as HTMLElement
|
||||||
|
const from = panel.getBoundingClientRect().height
|
||||||
|
detailMotion.cancel(panel)
|
||||||
|
panel.style.height = `${from}px`
|
||||||
|
panel.style.overflow = 'hidden'
|
||||||
|
panel.style.willChange = 'height, opacity'
|
||||||
|
}
|
||||||
|
const leaveExpandPanel = (element: Element, done: () => void) => {
|
||||||
|
const panel = element as HTMLElement
|
||||||
|
const from = panel.getBoundingClientRect().height
|
||||||
|
playDetailAnimation(panel,
|
||||||
|
[{ height: `${from}px`, opacity: 1 }, { height: '0px', opacity: 0 }],
|
||||||
|
{ duration: PANEL_DURATION_MS, easing: lifecycleEasing },
|
||||||
|
() => { clearPanelStyles(panel); done() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const beforeRetrievalPanelEnter = beforeExpandPanelEnter
|
||||||
|
const enterRetrievalPanel = enterExpandPanel
|
||||||
|
const afterRetrievalPanelEnter = afterExpandPanelEnter
|
||||||
|
const beforeRetrievalPanelLeave = beforeExpandPanelLeave
|
||||||
|
const leaveRetrievalPanel = leaveExpandPanel
|
||||||
watch(
|
watch(
|
||||||
() => selectedFileDetail.value?.id,
|
() => selectedFileDetail.value?.id,
|
||||||
() => {
|
() => {
|
||||||
@@ -2554,17 +2523,22 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
lifecycleHeightRevision++
|
||||||
|
detailMotion.dispose()
|
||||||
mobileMediaQuery.removeEventListener('change', syncMobileViewport)
|
mobileMediaQuery.removeEventListener('change', syncMobileViewport)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.fcb-lifecycle-viewport {
|
.fcb-lifecycle-viewport {
|
||||||
overflow: hidden;
|
overflow: visible;
|
||||||
will-change: height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.fcb-lifecycle-list {
|
.fcb-lifecycle-viewport > .fcb-lifecycle-list {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2587,20 +2561,4 @@ onUnmounted(() => {
|
|||||||
will-change: grid-template-rows, opacity, transform;
|
will-change: grid-template-rows, opacity, transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fcb-expand-120-enter-active,
|
|
||||||
.fcb-expand-120-leave-active {
|
|
||||||
overflow: hidden;
|
|
||||||
will-change: height, opacity;
|
|
||||||
}
|
|
||||||
.fcb-expand-120-enter-from,
|
|
||||||
.fcb-expand-120-leave-to { opacity: 0; }
|
|
||||||
.fcb-expand-120-enter-to,
|
|
||||||
.fcb-expand-120-leave-from { opacity: 1; }
|
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
|
||||||
.fcb-expand-120-enter-active,
|
|
||||||
.fcb-expand-120-leave-active {
|
|
||||||
transition-duration: 1ms;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# Detail motion regression checks
|
||||||
|
|
||||||
|
Requires Node 22.6+ for the TypeScript unit tests (no extra test dependencies).
|
||||||
|
|
||||||
|
- `npm run test:motion`: animation completion, cancellation, reversal and reduced motion.
|
||||||
|
- `npm run test:motion:coverage`: coverage of `src/utils/detailMotion.ts` only.
|
||||||
|
|
||||||
|
Browser integration uses the actual Vue file-detail view and backend data. Start
|
||||||
|
Vite with the desired test backend, sign in, and open a file with more than three
|
||||||
|
lifecycle rows and at least one retrieval event. In that page's DevTools console:
|
||||||
|
|
||||||
|
```js
|
||||||
|
await (await import('/theme-assets/tests/detailMotion.browser.mjs')).runDetailMotionChecks()
|
||||||
|
```
|
||||||
|
|
||||||
|
Run again at 390px width, then with `prefers-reduced-motion: reduce` emulated:
|
||||||
|
|
||||||
|
```js
|
||||||
|
await (await import('/theme-assets/tests/detailMotion.browser.mjs')).runDetailMotionChecks({ reducedMotion: true })
|
||||||
|
```
|
||||||
|
|
||||||
|
Checks three expand/collapse cycles, nonidentical height endpoints, return to
|
||||||
|
natural height, visible retrieval records, no vertical record transform, rapid
|
||||||
|
reversals and final collapsed layout. It only toggles presentation and never
|
||||||
|
uploads, deletes, restores or changes file data. These checks do not measure
|
||||||
|
whole-project coverage or validate the storage implementation.
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// Run in the local app with a file detail dialog open (more than 3 lifecycle rows
|
||||||
|
// and retrieval events). Reads real data and toggles presentation only.
|
||||||
|
export async function runDetailMotionChecks({ reducedMotion = false } = {}) {
|
||||||
|
const results = []
|
||||||
|
const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||||
|
const assert = (condition, message) => { if (!condition) throw new Error(message) }
|
||||||
|
const lifecycle = () => document.querySelector('.fcb-lifecycle-viewport')
|
||||||
|
const toggle = (kind, expanded) => {
|
||||||
|
const label = kind === 'lifecycle'
|
||||||
|
? (expanded ? '展开全部生命周期记录' : '收起生命周期记录')
|
||||||
|
: (expanded ? '展开全部取件记录' : '收起取件记录')
|
||||||
|
const button = [...document.querySelectorAll('button')].find(b => b.textContent.includes(label))
|
||||||
|
if (button) button.click()
|
||||||
|
}
|
||||||
|
const assertNaturalHeight = label => {
|
||||||
|
const v = lifecycle()
|
||||||
|
const actual = v.getBoundingClientRect().height
|
||||||
|
const expected = v.firstElementChild.getBoundingClientRect().height
|
||||||
|
assert(Math.abs(actual - expected) < 1, `${label}: viewport ${actual}, content ${expected}`)
|
||||||
|
assert(!v.style.height && v.getAnimations().length === 0, `${label}: retained height effect`)
|
||||||
|
results.push({ label, height: actual, contentHeight: expected })
|
||||||
|
}
|
||||||
|
assert(lifecycle(), 'Open a file detail dialog first')
|
||||||
|
toggle('lifecycle', false)
|
||||||
|
await wait(500)
|
||||||
|
const initial = lifecycle().getBoundingClientRect().height
|
||||||
|
for (let cycle = 0; cycle < 3; cycle++) {
|
||||||
|
toggle('lifecycle', true)
|
||||||
|
await wait(30)
|
||||||
|
if (!reducedMotion) {
|
||||||
|
const animation = lifecycle().getAnimations()[0]
|
||||||
|
assert(animation, 'Missing outer height animation')
|
||||||
|
const frames = animation.effect.getKeyframes()
|
||||||
|
assert(frames[0].height !== frames[1].height, 'Identical start and end heights')
|
||||||
|
assert(animation.effect.getTiming().duration === 420, 'Unexpected height duration')
|
||||||
|
}
|
||||||
|
await wait(500)
|
||||||
|
assertNaturalHeight(`expanded-${cycle}`)
|
||||||
|
toggle('lifecycle', false)
|
||||||
|
await wait(500)
|
||||||
|
assertNaturalHeight(`collapsed-${cycle}`)
|
||||||
|
assert(Math.abs(lifecycle().getBoundingClientRect().height - initial) < 1, 'Collapsed height drift')
|
||||||
|
assert(lifecycle().querySelectorAll('.fcb-lifecycle-row').length === 3, 'Unexpected collapsed rows')
|
||||||
|
}
|
||||||
|
toggle('lifecycle', true)
|
||||||
|
await wait(500)
|
||||||
|
toggle('retrieval', true)
|
||||||
|
await wait(500)
|
||||||
|
const panel = document.querySelector('.fcb-retrieval-panel')
|
||||||
|
assert(panel && panel.getBoundingClientRect().height > 0, 'Retrieval panel is hidden')
|
||||||
|
assert(panel.querySelectorAll('.font-medium').length > 0, 'Missing retrieval records')
|
||||||
|
assert(getComputedStyle(panel).transform === 'none', 'Retrieval records translate vertically')
|
||||||
|
assertNaturalHeight('retrieval-expanded')
|
||||||
|
for (let i = 0; i < 6; i++) {
|
||||||
|
const before = panel.getBoundingClientRect().height
|
||||||
|
toggle('retrieval', i % 2 !== 0)
|
||||||
|
await wait(60)
|
||||||
|
const after = panel.getBoundingClientRect().height
|
||||||
|
assert(i % 2 === 0 ? after <= before : after >= before, 'Reversal jumps in the wrong direction')
|
||||||
|
}
|
||||||
|
await wait(500)
|
||||||
|
assertNaturalHeight('rapid-retrieval-reversal')
|
||||||
|
for (let i = 0; i < 6; i++) {
|
||||||
|
toggle('lifecycle', i % 2 !== 0)
|
||||||
|
await wait(60)
|
||||||
|
}
|
||||||
|
await wait(500)
|
||||||
|
assertNaturalHeight('rapid-lifecycle-reversal')
|
||||||
|
toggle('retrieval', false)
|
||||||
|
await wait(500)
|
||||||
|
assert(getComputedStyle(document.querySelector('.fcb-retrieval-panel')).display === 'none', 'Retrieval panel remains visible')
|
||||||
|
assertNaturalHeight('retrieval-collapsed')
|
||||||
|
toggle('lifecycle', false)
|
||||||
|
await wait(500)
|
||||||
|
assertNaturalHeight('final-collapsed')
|
||||||
|
return results
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { test } from 'node:test'
|
||||||
|
import { createDetailMotion } from '../src/utils/detailMotion.ts'
|
||||||
|
|
||||||
|
class FakeAnimation extends EventTarget {
|
||||||
|
cancelled = false
|
||||||
|
cancel() { this.cancelled = true; this.dispatchEvent(new Event('cancel')) }
|
||||||
|
finish() { this.dispatchEvent(new Event('finish')) }
|
||||||
|
}
|
||||||
|
class FakeElement {
|
||||||
|
animations = []
|
||||||
|
animate(frames, options) {
|
||||||
|
const animation = new FakeAnimation()
|
||||||
|
Object.assign(animation, { frames, options })
|
||||||
|
this.animations.push(animation)
|
||||||
|
return animation
|
||||||
|
}
|
||||||
|
getAnimations() { return this.animations.filter(a => !a.cancelled) }
|
||||||
|
}
|
||||||
|
const frames = [{ height: '186px' }, { height: '429px' }]
|
||||||
|
|
||||||
|
test('completed height effects are removed so content can shrink and nested records can grow', () => {
|
||||||
|
const motion = createDetailMotion(() => false)
|
||||||
|
const element = new FakeElement()
|
||||||
|
let done = 0
|
||||||
|
motion.play(element, frames, { duration: 420 }, () => done++)
|
||||||
|
element.animations[0].finish()
|
||||||
|
assert.equal(done, 1)
|
||||||
|
assert.equal(element.getAnimations().length, 0)
|
||||||
|
})
|
||||||
|
test('rapid reversal finishes the previous transition once and ignores its stale finish event', () => {
|
||||||
|
const motion = createDetailMotion(() => false)
|
||||||
|
const element = new FakeElement()
|
||||||
|
let first = 0, second = 0
|
||||||
|
motion.play(element, frames, {}, () => first++)
|
||||||
|
const old = element.animations[0]
|
||||||
|
motion.play(element, frames.toReversed(), {}, () => second++)
|
||||||
|
old.finish()
|
||||||
|
assert.equal(first, 1)
|
||||||
|
assert.equal(second, 0)
|
||||||
|
assert.equal(element.getAnimations().length, 1)
|
||||||
|
element.animations[1].finish()
|
||||||
|
assert.equal(second, 1)
|
||||||
|
assert.equal(element.getAnimations().length, 0)
|
||||||
|
})
|
||||||
|
test('explicit cancellation removes effects and calls completion only once', () => {
|
||||||
|
const motion = createDetailMotion(() => false)
|
||||||
|
const element = new FakeElement()
|
||||||
|
let done = 0
|
||||||
|
motion.play(element, frames, {}, () => done++)
|
||||||
|
motion.cancel(element)
|
||||||
|
motion.cancel(element)
|
||||||
|
element.animations[0].finish()
|
||||||
|
assert.equal(done, 1)
|
||||||
|
assert.equal(element.getAnimations().length, 0)
|
||||||
|
})
|
||||||
|
test('reduced motion skips animations and still completes', () => {
|
||||||
|
const motion = createDetailMotion(() => true)
|
||||||
|
const element = new FakeElement()
|
||||||
|
let done = 0
|
||||||
|
motion.play(element, frames, {}, () => done++)
|
||||||
|
assert.equal(done, 1)
|
||||||
|
assert.equal(element.animations.length, 0)
|
||||||
|
})
|
||||||
|
test('external cancellation and disposal release all owned animations', () => {
|
||||||
|
const motion = createDetailMotion(() => false)
|
||||||
|
const a = new FakeElement(), b = new FakeElement()
|
||||||
|
let done = 0
|
||||||
|
motion.play(a, frames, {}, () => done++)
|
||||||
|
a.animations[0].cancel()
|
||||||
|
motion.play(a, frames, {}, () => done++)
|
||||||
|
motion.play(b, frames, {}, () => done++)
|
||||||
|
motion.dispose()
|
||||||
|
assert.equal(done, 3)
|
||||||
|
assert.equal(a.getAnimations().length + b.getAnimations().length, 0)
|
||||||
|
})
|
||||||
Reference in new issue
Block a user