packageDocumentation module import { LabelDefinition , LabelDefinitionJSON } from "../LabelDefinition" ; import { NodeKey , NodeKeyJSON } from "./Key" ; public export interface Node { /** A key that uniquely identifies a node. */ key : NodeKey ; /** Definition of node display label */ label : LabelDefinition ; /** Extensive description */ description ? : string ; /** Image ID */ imageId ? : string ; /** Foreground color */ foreColor ? : string ; /** Background color */ backColor ? : string ; /** Font style */ fontStyle ? : string ; /** Does this node have child nodes */ hasChildren ? : boolean ; /** Is this node selectable */ isSelectionDisabled ? : boolean ; /** Is this node editable */ isEditable ? : boolean ; /** Is this node expanded */ isExpanded ? : boolean ; /** Is checkbox visible for this node */ isCheckboxVisible ? : boolean ; /** Is this node's checkbox checked */ isChecked ? : boolean ; /** Is this node's checkbox enabled */ isCheckboxEnabled ? : boolean ; /** Extended data injected into this node */ extendedData ? : { [ key ] : any ; } ; } public export interface NodeJSON { key : NodeKeyJSON ; labelDefinition : LabelDefinitionJSON ; description ? : string ; imageId ? : string ; foreColor ? : string ; backColor ? : string ; fontStyle ? : string ; hasChildren ? : boolean ; isSelectionDisabled ? : boolean ; isEditable ? : boolean ; isExpanded ? : boolean ; isCheckboxVisible ? : boolean ; isChecked ? : boolean ; isCheckboxEnabled ? : boolean ; extendedData ? : { [ key ] : any ; } ; } public export type PartialNode = AllOrNone < Partial < Node > , "key" | "label" > ; public export type PartialNodeJSON = AllOrNone < Partial < NodeJSON > , "key" | "labelDefinition" > ; type AllOrNone < T , P extends keyof T > = Omit < T , P > & ( { [ K in P ] ? : never ; } | Required < Pick < T , P > > ) ; public export namespace Node { /** Serialize given [[Node]] to JSON */ export function toJSON ( node ) { const { key , label , ... baseNode } = node ; return { ... baseNode , key : NodeKey . toJSON ( key ) , labelDefinition : LabelDefinition . toJSON ( label ) } ; } internal export function toPartialJSON ( node ) { if ( node . key === undefined ) { return node ; } const { key , label , ... baseNode } = node ; return { ... baseNode , key : NodeKey . toJSON ( key ) , labelDefinition : LabelDefinition . toJSON ( label ) } ; } /** Deserialize [[Node]] from JSON */ export function fromJSON ( json ) { if ( typeof json === "string" ) return JSON . parse ( json , reviver ) ; const { labelDefinition , ... baseJson } = json ; return { ... baseJson , key : NodeKey . fromJSON ( json . key ) , label : LabelDefinition . fromJSON ( labelDefinition ) } ; } internal export function fromPartialJSON ( json ) { if ( json . key === undefined ) { return json ; } const { key , labelDefinition , ... baseJson } = json ; return { ... baseJson , key : NodeKey . fromJSON ( key ) , label : LabelDefinition . fromJSON ( labelDefinition ) } ; } internal export function reviver ( key , value ) { return key === "" ? fromJSON ( value ) : value ; } param json returns internal export function listFromJSON ( json ) { if ( typeof json === "string" ) return JSON . parse ( json , listReviver ) ; return json . map ( ( m ) => fromJSON ( m ) ) ; } internal export function listReviver ( key , value ) { return key === "" ? listFromJSON ( value ) : value ; } }