The short answer is you can't publish the levels graphic UI (you can, but it doesn't work in FCPX - all you get is the collection of the individual slider controls.)
You can create a shape with a gradient fill. Set a middle color tab and a second opacity tab. You can use Link parameter behaviors from the color/opacity tabs to the the filter > Levels parameter controls. Use the color tabs for Black In, Gamma and White In. Use the Opacity tabs for Black Out and White Out.
You can publish the shape's gradient.
The problem is, to publish this UI, you're publishing an actual gradient and people will be able to make alterations to the gradient (it won't change how it operates the levels controls.) The other problem with it is that it is possible for users to accidentally pull off or add new tabs which will immediately break the effect (and immediate "undo" should repair it though). Then, figuring out how to manipulate the Gamma control is going to be a trick (I haven't figured out yet.) The values go from 5 (all the way left) to 0 (all the way right - with 1 the 50% mark) for the Gamma control itself, but the UI controller (the middle tab on the gradient) moves the control in the opposite direction and the values are logarithmic in scale. You can use the mid-tab control on the gradient linked to the gamma parameter value, but it won't behave the same way as you would expect a genuine levels control to behave (left to right goes from black to white when the expectation would be the opposite.)
A gradient with links into the filter is about the only way to go if you want it give it a shot.