packageDocumentation module import { BeUiEvent } from "@itwin/core-bentley" ; import { PropertyEditorParams , PropertyEditorParamTypes , SuppressLabelEditorParams } from "../properties/EditorParams" ; import { PropertyRecord } from "../properties/Record" ; import { PrimitiveValue , PropertyValueFormat } from "../properties/Value" ; import { BaseDialogItem , DialogItem , DialogPropertyItem , DialogPropertySyncItem } from "./DialogItem" ; import { PropertyChangeResult , PropertyChangeStatus , UiDataProvider } from "./UiDataProvider" ; public export enum DialogButtonType { None = "" , Close = "close" , OK = "ok" , Cancel = "cancel" , Yes = "yes" , No = "no" , Retry = "retry" , Next = "next" , Previous = "previous" } public export enum DialogButtonStyle { None = "" , Primary = "iui-cta" , Hollow = "iui-default" , Blue = "iui-high-visibility" } public export interface DialogButtonDef { /** type of button */ type : DialogButtonType ; /** Triggered on button click */ onClick : ( ) => void ; /** Which button style to decorate button width */ buttonStyle ? : DialogButtonStyle ; /** Disable the button */ disabled ? : boolean ; /** Custom label */ label ? : string ; /** Custom CSS class */ className ? : string ; } public export interface DialogRow { priority : number ; items : DialogItem [ ] ; } public export abstract class UiLayoutDataProvider extends UiDataProvider { private _items : ReadonlyArray < DialogItem > | undefined ; /** Applies changes from one or more properties - some dialogs will use this to send a bulk set of changes back to the provider */ public override processChangesInUi ( properties ) { properties . forEach ( ( property ) => this . applyUiPropertyChange ( property ) ) ; return { status : PropertyChangeStatus . Success } ; } /** Applies change of a single property - this is the default method used when property editors are dynamically generated. */ public applyUiPropertyChange = ( _updatedValue ) : void => { throw ( new Error ( "Derived UiDataProvider should implement this to apply change to a single property." ) ) ; } ; private _rows : DialogRow [ ] | undefined ; /** Array of dialog rows */ public get rows ( ) : DialogRow [ ] { if ( ! this . _rows ) { this . _rows = this . layoutDialogRows ( ) ; } return this . _rows ; } protected loadItemsInternal ( items ) { this . _items = items ? items : [ ] ; this . _rows = this . layoutDialogRows ( ) ; } /** Called by UI to request available properties that can be bound to user supplied UI components (See Tool1UiProvider for example). */ public supplyDialogItems ( ) { throw ( new Error ( "Derived UiDataProvider must implement this method to supply set of properties." ) ) ; } public get items ( ) : ReadonlyArray < DialogItem > { if ( undefined === this . _items ) { this . loadItemsInternal ( this . supplyDialogItems ( ) ) ; } return this . _items ! ; } /** Called to inform listeners that new properties are ready for display in UI. */ public reloadDialogItems ( emitEvent = true ) { this . loadItemsInternal ( this . supplyDialogItems ( ) ) ; if ( emitEvent ) this . fireItemsReloadedEvent ( ) ; } internal public layoutDialogRows ( ) { const rows = [ ] ; this . items . forEach ( ( item ) => { const row = rows . find ( ( value ) => value . priority === item . editorPosition . rowPriority ) ; if ( row ) { row . items . push ( item ) ; } else { rows . push ( { priority : item . editorPosition . rowPriority , items : [ item ] } ) ; } } ) ; rows . sort ( ( a , b ) => a . priority - b . priority ) ; rows . forEach ( ( row ) => row . items . sort ( ( a , b ) => a . editorPosition . columnIndex - b . editorPosition . columnIndex ) ) ; return rows ; } /** Determines if a dialog item editor wants a label */ public static editorWantsLabel ( item ) { if ( item . property . editor && item . property . editor . params ) { const params = item . property . editor . params . find ( ( param ) => param . type === PropertyEditorParamTypes . SuppressEditorLabel ) as SuppressLabelEditorParams ; if ( params ) return false ; } return true ; } /** Determines if a dialog items has an associated lock property */ public static hasAssociatedLockProperty ( item ) { return ! ! item . lockProperty ; } /** Gets the disabled state for a given dialog item */ public static getItemDisabledState ( baseDialogItem ) { const dialogItem = baseDialogItem as DialogItem ; if ( dialogItem === undefined || dialogItem . lockProperty === undefined ) return ! ! baseDialogItem . isDisabled ; const value = dialogItem . lockProperty . value ; if ( value === undefined ) return ! ! baseDialogItem . isDisabled ; return ! value . value ; } /** Gets a property record for a given dialog item */ public static getPropertyRecord = ( dialogItem ) : PropertyRecord => { const propertyValue = { valueFormat : PropertyValueFormat . Primitive , value : dialogItem . value . value , displayValue : dialogItem . value . displayValue } ; const record = new PropertyRecord ( propertyValue as PrimitiveValue , dialogItem . property ) ; record . isDisabled = UiLayoutDataProvider . getItemDisabledState ( dialogItem ) ; return record ; } ; /** Determines if a dialog row only contains button group editors */ public static onlyContainButtonGroupEditors ( row ) { for ( const item of row . items ) { if ( UiLayoutDataProvider . hasAssociatedLockProperty ( item ) || undefined === item . property . editor || "enum-buttongroup" !== item . property . editor . name || UiLayoutDataProvider . editorWantsLabel ( item ) ) return false ; } return true ; } } public export abstract class DialogLayoutDataProvider extends UiLayoutDataProvider { public onButtonsReloadedEvent = new BeUiEvent < void > ( ) ; /** Called to inform listeners that modal dialog button data needs to be refreshed. */ public fireDialogButtonsReloadEvent ( ) { this . onButtonsReloadedEvent . emit ( ) ; } public supplyButtonData ( ) { const buttons = [ ] ; buttons . push ( { type : DialogButtonType . OK , onClick : ( ) => { } } ) ; buttons . push ( { type : DialogButtonType . Cancel , onClick : ( ) => { } } ) ; return buttons ; } }