|
1 | 1 | <script lang="ts"> |
2 | | - import type { TransitionFunction, TransitionWithProps } from '@dvcol/svelte-utils/transition'; |
| 2 | + import type { TransitionFunction } from '@dvcol/svelte-utils/transition'; |
3 | 3 | import type { Snippet } from 'svelte'; |
4 | 4 |
|
5 | 5 | import type { TransitionProps } from '~/models/component.model.js'; |
6 | 6 |
|
7 | 7 | import { toStyle } from '@dvcol/common-utils/common/class'; |
8 | 8 | import { mutation } from '@dvcol/svelte-utils/mutation'; |
9 | 9 |
|
| 10 | + import { isTransitionFunction, isTransitionObject } from '~/models/component.model.js'; |
| 11 | +
|
10 | 12 | const { children, key, id, transition }: { children: Snippet; id: string; key: any | any[]; transition: TransitionProps } = $props(); |
11 | 13 |
|
12 | 14 | let firstRender = $state(true); |
13 | | - const first = $derived<TransitionProps['first']>(transition?.first ?? true); |
14 | | - const skipTransition = () => { |
15 | | - if (!firstRender) return false; |
16 | | - firstRender = false; |
17 | | - return first === false; |
18 | | - }; |
19 | | -
|
20 | | - const isTransitionFunction = (skip?: TransitionProps['first']): skip is TransitionFunction => typeof skip === 'function' && !!skip; |
21 | | - const isTransitionObject = (skip?: TransitionProps['first']): skip is TransitionWithProps => typeof skip === 'object' && !!skip?.use; |
| 15 | + const first = transition?.first ?? true; |
22 | 16 |
|
23 | 17 | const _in = $derived<TransitionFunction>(((node, props, options) => { |
24 | | - if (skipTransition()) return; |
25 | | - if (firstRender && isTransitionFunction(first)) return first; |
26 | | - if (firstRender && isTransitionObject(first)) return first.use; |
| 18 | + if (firstRender) { |
| 19 | + firstRender = false; |
| 20 | + if (first === false) return; |
| 21 | + if (isTransitionFunction(first)) return first(node, props, options); |
| 22 | + if (isTransitionObject(first)) return first.use(node, props ?? {}, options); |
| 23 | + } |
27 | 24 | return transition?.in?.(node, props, options); |
28 | 25 | }) as TransitionFunction); |
29 | | - const _out = $derived<TransitionFunction>(((node, props, options) => { |
30 | | - if (firstRender && first) return; |
31 | | - return transition?.out?.(node, props, options); |
32 | | - }) as TransitionFunction); |
33 | 26 |
|
34 | 27 | const _inParams = $derived.by(() => { |
35 | 28 | if (firstRender && isTransitionObject(first) && first.props) return first.props; |
36 | 29 | return transition?.params?.in ?? {}; |
37 | 30 | }); |
| 31 | +
|
| 32 | + const _out = $derived<TransitionFunction>(((node, props, options) => { |
| 33 | + if (firstRender && first === false) return; |
| 34 | + return transition?.out?.(node, props, options); |
| 35 | + }) as TransitionFunction); |
| 36 | +
|
38 | 37 | const _outParams = $derived(transition?.params?.out ?? {}); |
39 | 38 |
|
40 | 39 | const _containerProps = $derived(transition?.props?.container); |
|
0 commit comments