11import { registerPatch } from 'blockbench-patch-manager'
22import { injectComponent } from 'svelte-patching-tools'
3- import { EFFECT_ANIMATOR_CHANNELS , isCustomKeyframeChannel } from '../../mods/customKeyframes'
3+ import { EFFECT_ANIMATOR_CHANNELS } from '../../mods/customKeyframes'
44import EVENTS from '../../util/events'
55import { localize as translate } from '../../util/lang'
66import CommandsKeyframePanel from './commandsKeyframe.svelte'
77import VariantKeyframePanel from './variantKeyframe.svelte'
88
99let unmountCallback : ( ( ) => Promise < void > ) | null = null
10+ let currentUpdatePromise : Promise < void > | null = null
11+
12+ const updatePanel = ( ) => {
13+ if ( currentUpdatePromise ) {
14+ return currentUpdatePromise . then ( ( ) => {
15+ void updatePanel ( )
16+ } )
17+ }
18+
19+ currentUpdatePromise = new Promise ( async resolve => {
20+ await unmountCallback ?.( )
21+
22+ // if (!activeProjectIsBlueprintFormat()) return
23+
24+ const keyframe = Timeline . selected . at ( 0 )
25+ if ( keyframe ) {
26+ let component : any
27+ switch ( keyframe . channel ) {
28+ case EFFECT_ANIMATOR_CHANNELS . VARIANT :
29+ component = VariantKeyframePanel
30+ break
31+
32+ case EFFECT_ANIMATOR_CHANNELS . FUNCTION :
33+ component = CommandsKeyframePanel
34+ break
35+
36+ default :
37+ currentUpdatePromise = null
38+ resolve ( )
39+ return
40+ }
41+
42+ unmountCallback = injectComponent ( {
43+ component,
44+ props : { keyframe } ,
45+ elementSelector ( ) {
46+ return Panels . keyframe . node
47+ } ,
48+ postMount ( ) {
49+ currentUpdatePromise = null
50+ resolve ( )
51+ } ,
52+ } )
53+ } else {
54+ currentUpdatePromise = null
55+ resolve ( )
56+ }
57+ } )
58+ }
1059
1160registerPatch ( {
1261 id : 'animated_java:panel/custom-keyframe-data-points' ,
@@ -18,46 +67,8 @@ registerPatch({
1867 Language . data [ 'timeline.function' ] = translate ( 'effect_animator.timeline.function' )
1968
2069 const unsubs = [
21- EVENTS . UPDATE_KEYFRAME_SELECTION . subscribe ( async ( ) => {
22- await unmountCallback ?.( )
23- unmountCallback = null
24-
25- const keyframe = Timeline . selected . at ( 0 )
26- const isCustomKeyframe = isCustomKeyframeChannel ( keyframe ?. channel ?? '' )
27-
28- if ( keyframe && isCustomKeyframe ) {
29- let component : any
30- switch ( keyframe . channel ) {
31- case EFFECT_ANIMATOR_CHANNELS . VARIANT :
32- component = VariantKeyframePanel
33- break
34-
35- case EFFECT_ANIMATOR_CHANNELS . FUNCTION :
36- component = CommandsKeyframePanel
37- break
38-
39- default :
40- console . error ( `Unknown custom keyframe channel: '${ keyframe . channel } '` )
41- return
42- }
43-
44- unmountCallback = injectComponent ( {
45- component,
46- props : { keyframe } ,
47- elementSelector ( ) : HTMLElement | null {
48- return document . querySelector (
49- '#panel_keyframe .panel_vue_wrapper .keyframe_data_point'
50- )
51- } ,
52- // hideTargetChildren: true,
53- } )
54- }
55- } ) ,
56-
57- EVENTS . UNSELECT_AJ_PROJECT . subscribe ( async ( ) => {
58- await unmountCallback ?.( )
59- unmountCallback = null
60- } ) ,
70+ EVENTS . UPDATE_KEYFRAME_SELECTION . subscribe ( ( ) => void updatePanel ( ) ) ,
71+ EVENTS . UNSELECT_AJ_PROJECT . subscribe ( ( ) => void updatePanel ( ) ) ,
6172 ]
6273
6374 return { unsubs }
0 commit comments