packageDocumentation module import { RendererDescription } from "./Renderer" ; public export interface CategoryDescription { /** Unique name */ name : string ; /** Display label */ label : string ; /** Extensive description */ description : string ; /** Priority. Categories with higher priority should appear higher in the UI */ priority : number ; /** Should this category be auto-expanded when it's displayed in the UI */ expand : boolean ; /** Parent category description */ parent ? : CategoryDescription ; /** Custom renderer description */ renderer ? : RendererDescription ; } public export namespace CategoryDescription { /** Serialize given category to JSON */ export function toJSON ( category ) { const { parent , ... rest } = category ; return { ... rest , ... ( category . parent ? { parent : category . parent . name } : { } ) } ; } /**
     * Deserialize [[CategoryDescription]] from JSON. The `parent` is not assigned - use [[CategoryDescription.listFromJSON]]
     * to deserialize the whole categories list and set parents.
     */ export function fromJSON ( json ) { const { parent , ... rest } = json ; return rest ; } function createCategoriesHierarchy ( json , categoriesMap ) { const category = categoriesMap . get ( json . name ) ! ; if ( json . parent ) { category . parent = categoriesMap . get ( json . parent ) ; } return category ; } /** Deserialize a list of [[CategoryDescription]] from JSON. */ export function listFromJSON ( json ) { const categoriesMap = new Map < string , CategoryDescription > ( ) ; json . forEach ( ( categoryJson ) => categoriesMap . set ( categoryJson . name , CategoryDescription . fromJSON ( categoryJson ) ) ) ; return json . map ( ( categoryJson ) => createCategoriesHierarchy ( categoryJson , categoriesMap ) ) ; } } public export interface CategoryDescriptionJSON { name : string ; label : string ; description : string ; priority : number ; expand : boolean ; parent ? : string ; renderer ? : RendererDescription ; }