Skip to content

Commit 190c13e

Browse files
committed
🛠️ Fix custom keyframe panel duplicating
1 parent 054c606 commit 190c13e

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/components/customKeyframePanel.svelte

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
setKeyframeExecuteCondition,
55
} from '../mods/customKeyframesMod'
66
import { Valuable } from '../util/stores'
7-
</script>
8-
9-
<script lang="ts">
107
import { translate } from '../util/translation'
118
import CommandsKeyframePanel from './keyframePanels/commandsKeyframePanel.svelte'
129
import VariantKeyframePanel from './keyframePanels/variantKeyframePanel.svelte'
10+
</script>
1311

14-
export let currentPanel: Valuable<HTMLDivElement>
12+
<script lang="ts">
1513
export let selectedKeyframe: _Keyframe
1614
1715
const executeCondition = new Valuable<string>(
@@ -23,7 +21,7 @@
2321
})
2422
</script>
2523

26-
<div class="container" bind:this={$currentPanel}>
24+
<div class="container">
2725
{#if selectedKeyframe.channel === 'variant'}
2826
<VariantKeyframePanel {selectedKeyframe} />
2927
{:else if selectedKeyframe.channel === 'commands'}

src/interface/customKeyframePanel.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import type { SvelteComponentDev } from 'svelte/internal'
12
import { isCurrentFormat } from '../blueprintFormat'
23
import CustomKeyframePanelSvelteComponent from '../components/customKeyframePanel.svelte'
34
import { CUSTOM_CHANNELS } from '../mods/customKeyframesMod'
45
import { events } from '../util/events'
56
import { injectSvelteCompomponent } from '../util/injectSvelteComponent'
6-
import { Valuable } from '../util/stores'
77
import { translate } from '../util/translation'
88

9-
const CURRENT_PANEL = new Valuable<HTMLDivElement | undefined>(undefined)
9+
let currentPanel: SvelteComponentDev | undefined = undefined
1010

1111
export function injectCustomKeyframePanel(selectedKeyframe: _Keyframe) {
1212
if (
@@ -32,23 +32,23 @@ export function injectCustomKeyframePanel(selectedKeyframe: _Keyframe) {
3232
void injectSvelteCompomponent({
3333
component: CustomKeyframePanelSvelteComponent,
3434
props: {
35-
currentPanel: CURRENT_PANEL as Valuable<HTMLDivElement>,
3635
selectedKeyframe,
3736
},
3837
elementSelector() {
3938
return element
4039
},
41-
postMount() {
40+
postMount(comp) {
4241
const label = jQuery('#panel_keyframe .panel_vue_wrapper #keyframe_type_label label')
4342
if (label && selectedKeyframe.channel) {
4443
const property = selectedKeyframe.animator.channels[selectedKeyframe.channel]
4544
label.text(translate('panel.keyframe.keyframe_title', `${property.name}`))
4645
}
46+
currentPanel?.$destroy()
47+
currentPanel = comp
4748
},
4849
})
4950
}
5051

5152
events.SELECT_KEYFRAME.subscribe(kf => {
52-
CURRENT_PANEL.get()?.remove()
53-
requestAnimationFrame(() => injectCustomKeyframePanel(kf))
53+
injectCustomKeyframePanel(kf)
5454
})

0 commit comments

Comments
 (0)