packageDocumentation module import { BasePropertyEditorParams , ColorEditorParams , ImageCheckBoxParams , PropertyEditorParams , PropertyEditorParamTypes , RangeEditorParams , SuppressLabelEditorParams , } from "./EditorParams" ; import { StandardEditorNames } from "./StandardEditorNames" ; import { StandardTypeNames } from "./StandardTypeNames" ; public export interface EnumerationChoice { label : string ; value : string | number ; } public export interface EnumerationChoicesInfo { choices : Promise < EnumerationChoice [ ] > | EnumerationChoice [ ] ; isStrict ? : boolean ; maxDisplayedRows ? : number ; } public export interface PropertyRendererInfo { name : string ; } public export interface PropertyEditorInfo { /** Editor name used in addition to the typename to find the registered property editor */ name ? : string ; /** Editor params provided to the property editor */ params ? : PropertyEditorParams [ ] ; } public export interface PropertyConverterInfo { /** Converter name used in addition to the typename to find the registered property converter */ name ? : string ; /** map of options for type converter */ options ? : { [ key ] : any ; } ; } public export interface PropertyDescription { /** Name of the property description */ name : string ; /** Display label for the property description */ displayLabel : string ; /** Type name used to determine applicable Type Converter and Property Editor */ typename : string ; /** Additional information for enumerations */ enum ? : EnumerationChoicesInfo ; /** Information for property renderer customization */ renderer ? : PropertyRendererInfo ; /** Information for a property editor */ editor ? : PropertyEditorInfo ; /** Information for a property converter */ converter ? : PropertyConverterInfo ; alpha quantityType ? : string ; /** Get the custom DataController by this name and register it with the property editor */ dataController ? : string ; alpha hideCompositePropertyLabel ? : boolean ; } public export class PropertyDescriptionHelper { public public static buildWeightPickerDescription ( name , label , additionalParams = [ ] ) { return { name , displayLabel : label , typename : StandardTypeNames . Number , editor : { name : StandardEditorNames . WeightPicker , params : additionalParams } } ; } public public static buildNumberEditorDescription ( name , label , overrideParams ? , additionalParams = [ ] ) { const editorParams = [ { type : PropertyEditorParamTypes . Range , step : 1 , precision : 0 , ... overrideParams } as RangeEditorParams , ... additionalParams ] ; const editor = { name : StandardEditorNames . NumericInput , params : editorParams } ; return { name , displayLabel : label , typename : StandardTypeNames . Number , editor } ; } public public static buildTextEditorDescription ( name , label , additionalParams = [ ] ) { const editor = { params : additionalParams } ; return { name , displayLabel : label , typename : StandardTypeNames . String , editor } ; } public public static buildEnumPicklistEditorDescription ( name , label , choices , additionalParams = [ ] ) { const editor = additionalParams . length ? { params : additionalParams } : undefined ; return { name , displayLabel : label , typename : StandardTypeNames . Enum , editor , enum : { choices } } ; } public public static buildColorPickerDescription ( name , label , colorValues , numColumns , additionalParams = [ ] ) { const editorParams = [ { type : PropertyEditorParamTypes . ColorData , colorValues , numColumns } as ColorEditorParams , ... additionalParams , ] ; return { name , displayLabel : label , typename : StandardTypeNames . Number , editor : { name : StandardEditorNames . ColorPicker , params : editorParams } } ; } public public static buildToggleDescription ( name , label , additionalParams = [ ] ) { return { name , displayLabel : label , typename : StandardTypeNames . Boolean , editor : { name : StandardEditorNames . Toggle , params : additionalParams } } ; } public public static buildImageCheckBoxDescription ( name , label , imageOff , imageOn , additionalParams = [ ] ) { const editorParams = [ { type : PropertyEditorParamTypes . CheckBoxImages , imageOff , imageOn } as ImageCheckBoxParams , ... additionalParams ] ; return { name , displayLabel : label , typename : StandardTypeNames . Boolean , editor : { name : StandardEditorNames . ImageCheckBox , params : editorParams } } ; } public public static buildCheckboxDescription ( name , label , additionalParams = [ ] ) { const editor = { params : additionalParams } ; return { name , displayLabel : label , typename : StandardTypeNames . Boolean , editor } ; } public public static buildLockPropertyDescription ( name , additionalParams = [ ] ) { const defaultParams = { type : PropertyEditorParamTypes . SuppressEditorLabel , suppressLabelPlaceholder : true } as SuppressLabelEditorParams ; const editor = { params : [ defaultParams , ... additionalParams ] } ; return { name , displayLabel : "" , typename : StandardTypeNames . Boolean , editor } ; } public public static async bumpEnumProperty ( description , value ) { let choices ; if ( description . enum ) { if ( description . enum . choices instanceof Promise ) { choices = await description . enum . choices ; } else { choices = description . enum . choices ; } } if ( ! choices || choices . length === 0 ) return value ; let choiceIndex = choices . findIndex ( ( choice ) => choice . value === value ) ; if ( choiceIndex < 0 ) return value ; choiceIndex ++ ; if ( choiceIndex >= choices . length ) choiceIndex = 0 ; const newValue = choices [ choiceIndex ] . value ; return newValue ; } }