import { defaultClassNames } from "./Bootstrapping/ClassNames" ; import { createElement } from "./Bootstrapping/CreateElement" ; import { getAvailableContainerHeight } from "./Bootstrapping/GetAvailableContainerHeight" ; import { defaultStyles } from "./Bootstrapping/Styles" ; import { Display } from "./Display" ; import { CompleteUserWrapprSettings , OptionalUserWrapprSettings , RequireJs , UserWrapprSettings , } from "./types" ; import { InitializeMenusView , InitializeMenusViewWrapper } from "./Menus/InitializeMenus" ; import { AbsoluteSizeSchema , RelativeSizeSchema } from "./Sizing" ; see https declare const requirejs ; /**
 * View libraries required to initialize a wrapping display.
 */ const externalViewLibraries = [ "react" , "react-dom" , "mobx" , "mobx-react" ] ; /**
 * Getters for the defaults of each optional UserWrappr setting.
 */ type OptionalUserWrapprSettingsDefaults = { [ P in keyof OptionalUserWrapprSettings ] : ( ) => OptionalUserWrapprSettings [ P ] ; } ; remarks const defaultSettings = { classNames : ( ) => defaultClassNames , createElement : ( ) => createElement , defaultSize : ( ) => ( { height : "100%" , width : "100%" , } ) , getAvailableContainerHeight : ( ) => getAvailableContainerHeight , menuInitializer : ( ) => "UserWrappr-Delayed" , menus : ( ) => [ ] , requirejs : ( ) => requirejs , styles : ( ) => defaultStyles , } ; param value param getDefault returns const ensureOptionalSetting = < TSetting > ( value , getDefault ) : TSetting => ( value === undefined ? getDefault ( ) : value ) ; param value param getDefault returns const extendDefaultSetting = < TSetting extends object > ( value , backup ) : TSetting => { if ( value === undefined ) { return backup ( ) ; } return { ... ( backup ( ) as object ) , ... ( value as object ) , } as TSetting ; } ; param value param getDefault returns const overrideDefaultSetting = < TSetting extends object > ( value , backup ) : TSetting => { if ( value === undefined ) { return backup ( ) ; } const output = backup ( ) ; for ( const key in value ) { output [ key ] = { ... ( output [ key ] as any ) , ... ( value [ key ] as any ) , } as any ; } return output as TSetting ; } ; /**
 * Creates configurable HTML displays over flexible-sized contents.
 */ export class UserWrappr { /**
     * Settings for the UserWrappr.
     */ private readonly settings : CompleteUserWrapprSettings ; /**
     * Contains generated contents and menus, once instantiated.
     */ private display : Display ; /**
     * Pending view libraries loading.
     */ private viewLibrariesLoading : Promise < InitializeMenusView > ; param settings public constructor ( settings ) { this . settings = { classNames : extendDefaultSetting ( settings . classNames , defaultSettings . classNames ) , createContents : settings . createContents , createElement : ensureOptionalSetting ( settings . createElement , defaultSettings . createElement ) , defaultSize : ensureOptionalSetting ( settings . defaultSize , defaultSettings . defaultSize ) , getAvailableContainerHeight : ensureOptionalSetting ( settings . getAvailableContainerHeight , defaultSettings . getAvailableContainerHeight ) , menuInitializer : ensureOptionalSetting ( settings . menuInitializer , defaultSettings . menuInitializer ) , menus : ensureOptionalSetting ( settings . menus , defaultSettings . menus ) , requirejs : ensureOptionalSetting ( settings . requirejs , defaultSettings . requirejs ) , styles : overrideDefaultSetting ( settings . styles , defaultSettings . styles ) , } ; } param container returns public async createDisplay ( container ) { if ( this . display !== undefined ) { throw new Error ( "Cannot create multiple displays from a UserWrappr." ) ; } this . viewLibrariesLoading = this . loadViewLibraries ( ) ; this . display = new Display ( { classNames : this . settings . classNames , container , createContents : this . settings . createContents , createElement : this . settings . createElement , getAvailableContainerHeight : this . settings . getAvailableContainerHeight , menus : this . settings . menus , styles : this . settings . styles , userWrapper : this , } ) ; await this . resetSize ( this . settings . defaultSize ) ; } param size returns public async resetSize ( size ) { if ( this . viewLibrariesLoading === undefined ) { throw new Error ( "A display must be created before resetting size." ) ; } if ( this . display === undefined ) { return false ; } const containerSize = await this . display . resetContents ( size ) ; const initializeMenusView = await this . viewLibrariesLoading ; await initializeMenusView ( { classNames : this . settings . classNames , container : this . display . getContainer ( ) , containerSize , menus : this . settings . menus , styles : this . settings . styles , } ) ; return true ; } returns private async loadViewLibraries ( ) { await this . require ( externalViewLibraries ) ; const wrapperModule = await this . require < InitializeMenusViewWrapper > ( [ this . settings . menuInitializer ] ) ; return wrapperModule . initializeMenus ; } param modules returns private async require < TResults > ( modules ) { return new Promise < TResults > ( ( resolve , reject ) => { this . settings . requirejs ( modules , resolve , reject ) ; } ) ; } }