packageDocumentation module import { immerable } from "immer" ; import { PropertyCategory , PropertyData } from "../PropertyDataProvider" ; import { FlatGridItem , GridCategoryItem } from "./flat-items/FlatGridItem" ; import { IMutableFlatGridItem , IMutableGridCategoryItem } from "./flat-items/MutableFlatGridItem" ; import { IMutableGridItemFactory } from "./flat-items/MutableGridItemFactory" ; beta export interface IPropertyGridModel { getItem : ( selectionKey : string ) => FlatGridItem ; getRootCategories : ( ) => GridCategoryItem [ ] ; getFlatGrid : ( ) => FlatGridItem [ ] ; getVisibleFlatGrid : ( ) => FlatGridItem [ ] ; } beta export interface IMutablePropertyGridModel { getItem : ( selectionKey : string ) => IMutableFlatGridItem ; getRootCategories : ( ) => IMutableGridCategoryItem [ ] ; getFlatGrid : ( ) => IMutableFlatGridItem [ ] ; getVisibleFlatGrid : ( ) => IMutableFlatGridItem [ ] ; } beta export class MutablePropertyGridModel implements IPropertyGridModel , IMutablePropertyGridModel { public [ immerable ] = true ; private _categories : IMutableGridCategoryItem [ ] ; public constructor ( propertyData , private _gridItemFactory ) { this . _categories = propertyData . categories . map ( ( category ) => this . _gridItemFactory . createGridCategory ( category , propertyData . records ) ) ; } param selectionKey public getItem ( selectionKey ) { const item = this . findItem ( this . _categories , selectionKey ) ; if ( ! item ) throw new Error ( `Grid item at provided key not found: ${ selectionKey }` ) ; return item ; } param items param selectionKey returns private findItem ( items , selectionKey ) { for ( const item of items ) { if ( ! selectionKey . startsWith ( item . selectionKey ) ) continue ; if ( item . selectionKey === selectionKey ) return item ; const foundItem = this . findItem ( item . getChildren ( ) , selectionKey ) ; if ( foundItem ) return foundItem ; } return undefined ; } returns public getRootCategories ( ) { return this . _categories ; } returns public getFlatGrid ( ) { const flatGrid = [ ] ; this . _categories . forEach ( ( category ) => flatGrid . push ( ... category . getDescendantsAndSelf ( ) ) ) ; return flatGrid ; } returns public getVisibleFlatGrid ( ) { const visibleItems = [ ] ; this . _categories . forEach ( ( category ) => visibleItems . push ( ... category . getVisibleDescendantsAndSelf ( ) ) ) ; return visibleItems ; } }