CMS-3593 Re-expanding closed tree nodes must remember what was expanded before closing
Minor refactoring, mostly typings.