Is there a way to conditionally lock Z-axis rotation for ArcballControls while limiting Y-axis one to make it behave as OrbitControls?

I have been using OrbitControls to rotate the camera around the object, and it has worked well. However, I now need to dynamically enable and disable rotation around the Z-axis using mouse events or programmatically. After spending some time playing with camera.up adjustments, I realized that achieving this with OrbitControls is quite challenging. As a result, I started looking into ArcballControls since it provides Z-axis rotation out of the box. However, I encountered the opposite issue: I am now struggling to disable the mentioned rotation. I attempted to conditionally disable the camera.up update as shown below:

      //update camera up vector
      if (
        (this._state == STATE.ROTATE ||
        this._state == STATE.ZROTATE ||
        this._state == STATE.ANIMATION_ROTATE) && 
       !this._disableZAxis
      ) {
        this.camera.up
          .copy(this._upState)
          .applyQuaternion(this.camera.quaternion);
      }

However, this approach resulted in a weird behavior when using diagonal mouse-move rotation. OrbitControls handle this situation better by limiting vertical mouse rotation to 180 degrees. I would like to replicate this behavior in ArcballControls when Z-axis rotation is disabled, however, I am still quite new in this area and I am not sure how to do it. Should I adjust rotationAxis calculation or it is purely rotationMatrix manipulation? How can it be done?
Thank you in advance!

If this helps, the LookAt command automatically cancels out any Z-rotation. So your camera is always rotated level with the horizon (like OrbitControls). So, if there is a way to add that command to your code, you should be set.

Thanks. But the problem is not with Z-axis locking itself since disabling camera.up updates solves this problem, but it is more with Y-axis limiting. It seems that the ArcballControls use Math.tan to calculate camera position and when we cross Y-axis during rotation it starts rotating the camera as well and this is what I am trying to prevent.