@@ -4,16 +4,18 @@ import { motionTuning, type MotionKnob } from "./motion-tuning"
44const global = "Global"
55
66// Kit's palette, applied to every spring at once.
7- const palette = { snappy : 0.25 , calm : 0.3 , smooth : 0.45 }
7+ const durations = { snappy : 0.25 , calm : 0.3 , smooth : 0.45 }
88
99/**
1010 * Mounts the Motion workspace into `container`: a tab per surface, Global on every tab, an action row per replay
11- * button, presets and copy as code. knobs loads on first mount, so importing this module costs nothing until then.
12- * Works anywhere a surface registered its knobs, including Storybook stories. Returns its removal.
11+ * button, a "Jump to" palette over sections, actions and presets, presets and copy as code. knobs loads on first
12+ * mount, so importing this module costs nothing until then. Works anywhere a surface registered its knobs, including
13+ * Storybook stories. Returns its removal.
1314 */
14- export function mountMotionPanel ( container : HTMLElement , options : { title ?: string } = { } ) {
15+ export function mountMotionPanel ( container : HTMLElement , options : { title ?: string ; section ?: string } = { } ) {
1516 let unmount : ( ( ) => void ) | undefined
1617 let disposed = false
18+ let section = options . section
1719
1820 void start ( )
1921
@@ -23,7 +25,10 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
2325 }
2426
2527 async function start ( ) {
26- const { action, defineControls, knob, spring, toggle } = await import ( "knobs" )
28+ const [ { action, defineControls, knob, spring, toggle } , { commandPalette, commandsFrom } ] = await Promise . all ( [
29+ import ( "knobs" ) ,
30+ import ( "knobs/ui" ) ,
31+ ] )
2732
2833 const field = ( item : MotionKnob ) => {
2934 const meta = { label : item . label , group : item . group , tab : item . group === global ? undefined : item . group }
@@ -60,6 +65,25 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
6065 const actions = motionTuning . actions ( )
6166 const mounted = identity ( )
6267 const springs = list . flatMap ( ( item ) => ( item . kind === "spring" ? [ item ] : [ ] ) )
68+ const sections = [ ...new Set ( [ ...list , ...actions ] . map ( ( item ) => item . group ) ) ] . filter ( ( group ) => group !== global )
69+
70+ const palette = commandPalette ( {
71+ hotkey : false ,
72+ recents : false ,
73+ placeholder : "Jump to a section, action or preset" ,
74+ commands : ( ) => [
75+ ...sections . map ( ( id ) => ( {
76+ id : `section.${ id } ` ,
77+ label : id ,
78+ section : "Sections" ,
79+ run : ( ) => {
80+ section = id
81+ mount ( )
82+ } ,
83+ } ) ) ,
84+ ...commandsFrom ( controls , { fields : false } ) . filter ( ( command ) => command . label !== "Jump to…" ) ,
85+ ] ,
86+ } )
6387
6488 const controls = defineControls (
6589 "opencode-motion" ,
@@ -71,12 +95,15 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
7195 action ( item . label , { group : item . group , tab : item . group , run : item . run } ) ,
7296 ] ) ,
7397 ) ,
98+ ...Object . fromEntries ( [ [ "jump" , action ( "Jump to…" , { group : global , run : ( ) => palette . open ( ) } ) ] ] ) ,
7499 } ,
75100 {
101+ // knobs enables itself only on localhost; this module is only loaded in developer channels.
102+ enabled : true ,
76103 ship : ( ) => import ( "knobs/panel" ) ,
77104 persist : "variants" ,
78105 presets : Object . fromEntries (
79- Object . entries ( palette ) . map ( ( [ name , duration ] ) => [
106+ Object . entries ( durations ) . map ( ( [ name , duration ] ) => [
80107 name ,
81108 Object . fromEntries ( springs . map ( ( item ) => [ item . id , { duration, bounce : 0 } ] ) ) ,
82109 ] ) ,
@@ -96,7 +123,9 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
96123 const stopPanel = controls . mount ( container , {
97124 theme : "auto" ,
98125 title : options . title ?? "Motion" ,
99- tabs : [ ...new Set ( [ ...list , ...actions ] . map ( ( item ) => item . group ) ) ] . filter ( ( group ) => group !== global ) ,
126+ tabs : sections ,
127+ tab : section ,
128+ onTab : ( id ) => ( section = id ) ,
100129 } )
101130
102131 const stopWatch = motionTuning . subscribe ( ( ) => {
@@ -108,6 +137,7 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
108137 unmount = ( ) => {
109138 stopWatch ( )
110139 stopPanel ( )
140+ palette . dispose ( )
111141 }
112142 }
113143
0 commit comments