5 lines
40 KiB
JavaScript
5 lines
40 KiB
JavaScript
var __runInitializers=this&&this.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0},__esDecorate=this&&this.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(void 0!==f&&"function"!=typeof f)throw new TypeError("Function expected");return f}for(var _,kind=contextIn.kind,key="getter"===kind?"get":"setter"===kind?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]="access"===p?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])("accessor"===kind?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if("accessor"===kind){if(void 0===result)continue;if(null===result||"object"!=typeof result)throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&("field"===kind?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0};import{TcHmiControl}from"Beckhoff.TwinCAT.HMI.Framework/index.esm.js";import{ValueBuffer,InputProcessingPoint}from"../Helpers/TcHmiValueBuffer/ValueBuffer.js";let TcHmiNumericInput=(()=>{var _a,_b;let ___onResize_decorators,___onKeydown_decorators,___onBeforeInput_decorators,___onInput_decorators,___onPaste_decorators,___onCut_decorators,___onFocusIn_decorators,___onFocusOut_decorators,___onIndirectInputFinished_decorators,___onIndirectInputCanceled_decorators,___onResolverForContentPaddingWatchCallback_decorators,___onResolverForValueColorWatchCallback_decorators,_classSuper=TcHmiControl.Control,_instanceExtraInitializers=[];return class TcHmiNumericInput extends _classSuper{static{const _metadata="function"==typeof Symbol&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;___onResize_decorators=[TcHmi.EventHandler()],___onKeydown_decorators=[TcHmi.EventHandler({checkIsEnabled:!0,checkIsReadOnly:!0,checkAccess:"operate"})],___onBeforeInput_decorators=[TcHmi.EventHandler({checkIsEnabled:!0,checkIsReadOnly:!0,checkAccess:"operate"})],___onInput_decorators=[TcHmi.EventHandler({checkIsEnabled:!0,checkIsReadOnly:!0,checkAccess:"operate"})],___onPaste_decorators=[TcHmi.EventHandler({checkIsEnabled:!0,checkIsReadOnly:!0,checkAccess:"operate"})],___onCut_decorators=[TcHmi.EventHandler({checkIsEnabled:!0,checkIsReadOnly:!0,checkAccess:"operate"})],___onFocusIn_decorators=[TcHmi.EventHandler({checkIsEnabled:!0,checkIsReadOnly:!0,checkAccess:"operate"})],___onFocusOut_decorators=[TcHmi.EventHandler({checkIsEnabled:!0,checkIsReadOnly:!0,checkAccess:"operate"})],___onIndirectInputFinished_decorators=[TcHmi.EventHandler({checkIsEnabled:!0,checkIsReadOnly:!0,checkAccess:"operate"})],___onIndirectInputCanceled_decorators=[TcHmi.EventHandler({checkIsEnabled:!0,checkIsReadOnly:!0,checkAccess:"operate"})],___onResolverForContentPaddingWatchCallback_decorators=[(_a=TcHmi).CallbackMethod.bind(_a)],___onResolverForValueColorWatchCallback_decorators=[(_b=TcHmi).CallbackMethod.bind(_b)],__esDecorate(this,null,___onResize_decorators,{kind:"method",name:"__onResize",static:!1,private:!1,access:{has:obj=>"__onResize"in obj,get:obj=>obj.__onResize},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onKeydown_decorators,{kind:"method",name:"__onKeydown",static:!1,private:!1,access:{has:obj=>"__onKeydown"in obj,get:obj=>obj.__onKeydown},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onBeforeInput_decorators,{kind:"method",name:"__onBeforeInput",static:!1,private:!1,access:{has:obj=>"__onBeforeInput"in obj,get:obj=>obj.__onBeforeInput},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onInput_decorators,{kind:"method",name:"__onInput",static:!1,private:!1,access:{has:obj=>"__onInput"in obj,get:obj=>obj.__onInput},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onPaste_decorators,{kind:"method",name:"__onPaste",static:!1,private:!1,access:{has:obj=>"__onPaste"in obj,get:obj=>obj.__onPaste},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onCut_decorators,{kind:"method",name:"__onCut",static:!1,private:!1,access:{has:obj=>"__onCut"in obj,get:obj=>obj.__onCut},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onFocusIn_decorators,{kind:"method",name:"__onFocusIn",static:!1,private:!1,access:{has:obj=>"__onFocusIn"in obj,get:obj=>obj.__onFocusIn},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onFocusOut_decorators,{kind:"method",name:"__onFocusOut",static:!1,private:!1,access:{has:obj=>"__onFocusOut"in obj,get:obj=>obj.__onFocusOut},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onIndirectInputFinished_decorators,{kind:"method",name:"__onIndirectInputFinished",static:!1,private:!1,access:{has:obj=>"__onIndirectInputFinished"in obj,get:obj=>obj.__onIndirectInputFinished},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onIndirectInputCanceled_decorators,{kind:"method",name:"__onIndirectInputCanceled",static:!1,private:!1,access:{has:obj=>"__onIndirectInputCanceled"in obj,get:obj=>obj.__onIndirectInputCanceled},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onResolverForContentPaddingWatchCallback_decorators,{kind:"method",name:"__onResolverForContentPaddingWatchCallback",static:!1,private:!1,access:{has:obj=>"__onResolverForContentPaddingWatchCallback"in obj,get:obj=>obj.__onResolverForContentPaddingWatchCallback},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onResolverForValueColorWatchCallback_decorators,{kind:"method",name:"__onResolverForValueColorWatchCallback",static:!1,private:!1,access:{has:obj=>"__onResolverForValueColorWatchCallback"in obj,get:obj=>obj.__onResolverForValueColorWatchCallback},metadata:_metadata},null,_instanceExtraInitializers),_metadata&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static#tchmiFQN="TcHmi.Controls.Beckhoff."+this.name;constructor(element,pcElement,attrs){super(element,pcElement,attrs)}__elementTemplateRoot=__runInitializers(this,_instanceExtraInitializers);__elementInput;__elementInvalidNotificationLabel;__elementUnit;__locked=!1;__valueType;__value;__valueInit;__oldValue;__oldStringValue="";__lastValidValue;__lastReportedValue;__lastInput;__lastSelection={start:null,end:null,direction:null};__maxValue;__maxValueInit;__minValue;__minValueInit;__decimalDigits;__unit;__systemKeyboardInputMode;__valueHorizontalAlignment;__contentPadding;__valueFontSize;__valueFontSizeUnit;__valueFontFamily;__valueFontStyle;__valueFontWeight;__placeholder;__zeroPadding;__valueColor;__autoFocusOut;__autoSelectText;__ignoreInvalidValues;__resetToLastValidValue;__isValid;__valueBuffer;__numberFormatter=new Intl.NumberFormat("en-US",{useGrouping:!1,maximumFractionDigits:100});__unitPosition;__decimalPrecisionMode;__isReadOnly;__triggerUIFinishedOnBlur=!1;__internalMinValue=null;__internalMaxValue=null;__localizedInput={key:"",parameters:[]};__localizationReader=void 0;__resizeObserver;__previnit(){if(this.__elementTemplateRoot=this.__element[0].getElementsByClassName("TcHmi_Controls_Beckhoff_TcHmiNumericInput-template")[0],this.__elementInput=this.__elementTemplateRoot.getElementsByClassName("TcHmi_Controls_Beckhoff_TcHmiNumericInput-template-input")[0],this.__elementInvalidNotificationLabel=this.__elementTemplateRoot.getElementsByClassName("TcHmi_Controls_Beckhoff_TcHmiNumericInput-template-input-invalid-notification")[0],this.__elementUnit=this.__elementTemplateRoot.getElementsByClassName("TcHmi_Controls_Beckhoff_TcHmiNumericInput-template-input-unit")[0],!(this.__elementTemplateRoot&&this.__elementInput&&this.__elementInvalidNotificationLabel&&this.__elementUnit))throw new Error("Invalid Template.html");this.__destroyOnDestroy.push(this.__localization.watch(data=>{if(data.error===TcHmi.Errors.NONE&&data.reader&&(this.__localizationReader=data.reader,""!==this.__localizedInput.key)){let localizedText=data.reader.get(this.__localizedInput.key);this.__localizedInput.parameters.length>0&&(localizedText=tchmi_format_string(localizedText,...this.__localizedInput.parameters)),TCHMI_DESIGNER||this.__elementInput.setCustomValidity(tchmi_decode_control_characters(localizedText))}})),this.__resizeObserver=new ResizeObserver(this.__onResize),super.__previnit()}__init(){super.__init();const passiveEventOptions={passive:!0,capture:!1};this.__destroyOnDestroy.push(TcHmi.EventProvider.registerDomEvent(this.__elementTemplateRoot,"focusin",this.__onFocusIn,passiveEventOptions),TcHmi.EventProvider.registerDomEvent(this.__elementTemplateRoot,"focusout",this.__onFocusOut,passiveEventOptions),TcHmi.EventProvider.registerDomEvent(this.__elementInput,"keydown",this.__onKeydown,{passive:!1,capture:!1}),TcHmi.EventProvider.registerDomEvent(this.__elementInput,"beforeinput",this.__onBeforeInput,passiveEventOptions),TcHmi.EventProvider.registerDomEvent(this.__elementInput,"input",this.__onInput,passiveEventOptions),TcHmi.EventProvider.registerDomEvent(this.__elementInput,"paste",this.__onPaste,passiveEventOptions),TcHmi.EventProvider.registerDomEvent(this.__elementInput,"cut",this.__onCut,passiveEventOptions),TcHmi.EventProvider.registerDomEvent(this.__elementInput,"indirectinputfinished",this.__onIndirectInputFinished,passiveEventOptions),TcHmi.EventProvider.registerDomEvent(this.__elementInput,"indirectinputcanceled",this.__onIndirectInputCanceled,passiveEventOptions))}__attach(){super.__attach(),this.__processContentPadding(),this.__resizeObserver.observe(this.__elementUnit)}__detach(){super.__detach(),this.__resizeObserver.disconnect()}destroy(){this.__keepAlive||super.destroy()}__onResize(){this.__processContentPadding()}__setValueFromInput(){let inputValue=null;switch(this.__valueType){case"BigInt64":case"UnsignedBigInt64":try{inputValue=BigInt(this.__elementInput.value)}catch{inputValue=null}break;default:inputValue=Number(this.__elementInput.value),isNaN(inputValue)&&(inputValue=null)}this.__valueBuffer?.setValue(inputValue),this.__valueBuffer?.processingPoint===InputProcessingPoint.InteractionFinished&&this.__validateInput()}__validateInput(){if(""===this.__elementInput.value&&null===this.__value)return this.__setLocalizedInputValidity(""),void this.__setIsValid(!0);let inputValue,notNumberOrBigInt=!1;switch(this.__valueType){case"BigInt64":case"UnsignedBigInt64":try{inputValue=BigInt(this.__elementInput.value)}catch{notNumberOrBigInt=!0}break;default:inputValue=Number(this.__elementInput.value),notNumberOrBigInt=isNaN(inputValue)}if(notNumberOrBigInt)["-","+","."].includes(this.__elementInput.value)?(this.__setLocalizedInputValidity("ValueNaN"),this.__setIsValid(!1),this.__lastInput=this.__elementInput.value):this.__elementInput.value=this.__lastInput??"";else{let newValue;switch(this.__lastInput=this.__elementInput.value,this.__valueType){case"BigInt64":case"UnsignedBigInt64":try{newValue=BigInt(this.__elementInput.value)}catch{}break;default:newValue=Number(this.__elementInput.value)}!this.__elementInput.value.trim()&&this.__attributesInitialized?(this.__setLocalizedInputValidity("ValueEmpty"),this.__setIsValid(!1)):null!==this.__internalMinValue&&void 0!==newValue&&newValue<this.__internalMinValue?(this.__setLocalizedInputValidity("ValueOutOfRangeMin",[this.__internalMinValue]),this.__setIsValid(!1)):null!==this.__internalMaxValue&&void 0!==newValue&&newValue>this.__internalMaxValue?(this.__setLocalizedInputValidity("ValueOutOfRangeMax",[this.__internalMaxValue]),this.__setIsValid(!1)):(this.__setLocalizedInputValidity(""),this.__setIsValid(!0))}}__setInternalMinMaxValues(){void 0!==this.__minValue&&void 0!==this.__maxValue&&null!==this.__minValue&&null!==this.__maxValue?(this.__internalMinValue=this.__minValue>this.__maxValue?this.__maxValue:this.__minValue,this.__internalMaxValue=this.__maxValue<this.__minValue?this.__minValue:this.__maxValue):(this.__internalMinValue=this.__minValue??null,this.__internalMaxValue=this.__maxValue??null),null!==this.__internalMinValue?this.__elementInput.setAttribute("data-tchmikeyboard-min",this.__ceilToDecimals(this.__internalMinValue)):this.__elementInput.removeAttribute("data-tchmikeyboard-min"),null!==this.__internalMaxValue?this.__elementInput.setAttribute("data-tchmikeyboard-max",this.__floorToDecimals(this.__internalMaxValue)):this.__elementInput.removeAttribute("data-tchmikeyboard-max")}__onKeydown(event){this.__triggerUIFinishedOnBlur=!0,"Escape"===event.key?(this.__processValue(),TcHmi.EventProvider.raise(this.__id+".onUserInteractionCanceled"),this.__triggerUIFinishedOnBlur=!1,this.__autoFocusOut&&this.__elementInput.blur()):"Enter"===event.key&&(this.__autoFocusOut||(this.__triggerUIFinishedOnBlur=!1),this.__processCurrentValue(),this.__autoFocusOut||(this.__valueBuffer?.interactionFinished(),TcHmi.EventProvider.raise(this.__id+".onUserInteractionFinished")),event.preventDefault())}__onBeforeInput(event){this.__lastSelection={start:this.__elementInput.selectionStart,end:this.__elementInput.selectionEnd,direction:this.__elementInput.selectionDirection}}__onInput(event){this.__triggerUIFinishedOnBlur=!0;if(!new RegExp(String.raw`^[+-]?\d*(?:\.\d{0,${this.__decimalDigits??""}})?$`).test(this.__elementInput.value))return this.__elementInput.value=this.__lastInput??"",void this.__elementInput.setSelectionRange(this.__lastSelection.start,this.__lastSelection.end,this.__lastSelection.direction??void 0);this.__setValueFromInput()}__onPaste(event){this.__triggerUIFinishedOnBlur=!0,window.setTimeout(()=>{this.__setValueFromInput()})}__onCut(event){this.__triggerUIFinishedOnBlur=!0,window.setTimeout(()=>{this.__setValueFromInput()})}__onFocusIn(event){this.__triggerUIFinishedOnBlur=!0,this.__oldValue=this.__value,this.__oldStringValue=this.__elementInput.value,this.__elementInput.classList.add("tchmi-focus"),this.__autoSelectText&&(this.__elementInput.setSelectionRange(0,0),this.__elementInput.select()),TcHmi.EventProvider.raise(this.__id+".onFocusIn",event),this.__elementInput===document.activeElement&&this.__lock()}__onFocusOut(event){this.__elementInput.classList.contains("tchmi-keyboard-user-input")||this.__performFocusOut(event)}__performFocusOut(event){if(this.__unlock(),this.__elementInput.classList.remove("tchmi-focus"),this.__valueBuffer?.interactionFinished(),TcHmi.EventProvider.raise(this.__id+".onFocusOut",event),this.__elementInput.value!==this.__oldStringValue){this.__oldValue=this.__value;let newValue,notNumberOrBigInt=!1;switch(this.__valueType){case"BigInt64":case"UnsignedBigInt64":try{newValue=BigInt(this.__elementInput.value)}catch{notNumberOrBigInt=!0}break;default:newValue=Number(this.__elementInput.value),notNumberOrBigInt=isNaN(newValue)}this.__elementInput.value.trim()&&!notNumberOrBigInt&&(null===this.__internalMaxValue||void 0!==newValue&&newValue<=this.__internalMaxValue)&&(null===this.__internalMinValue||void 0!==newValue&&newValue>=this.__internalMinValue)?this.__setValue(newValue):this.__resetToLastValidValue&&this.__setValue(this.__lastValidValue)}this.__triggerUIFinishedOnBlur&&TcHmi.EventProvider.raise(this.__id+".onUserInteractionFinished"),this.__triggerUIFinishedOnBlur=!1}__onIndirectInputFinished(event){this.__valueBuffer?.interactionFinished(),this.__processCurrentValue(),TcHmi.EventProvider.raise(this.__id+".onUserInteractionFinished")}__onIndirectInputCanceled(event){TcHmi.EventProvider.raise(this.__id+".onUserInteractionCanceled"),this.__triggerUIFinishedOnBlur=!1,this.__elementInput!==document.activeElement?this.__performFocusOut(event):this.__autoFocusOut&&this.__elementInput.blur()}__setLocalizedInputValidity(key,...parameters){if(this.__localizedInput.key=key,this.__localizedInput.parameters=parameters,""===key)this.__elementInput.setCustomValidity("");else if(this.__localizationReader){let localizedText=this.__localizationReader.get(key);this.__localizedInput.parameters.length>0&&(localizedText=tchmi_format_string(localizedText,...this.__localizedInput.parameters)),TCHMI_DESIGNER||this.__elementInput.setCustomValidity(tchmi_decode_control_characters(localizedText))}else TCHMI_DESIGNER||this.__elementInput.setCustomValidity("Invalid")}__processCurrentValue(){if(this.__oldValue=this.__value,this.__autoFocusOut)this.__elementInput.blur(),this.__unlock();else if(this.__elementInput.value!==this.__oldStringValue){let newValue,notNumberOrBigInt=!1;switch(this.__valueType){case"BigInt64":case"UnsignedBigInt64":try{newValue=BigInt(this.__elementInput.value)}catch{notNumberOrBigInt=!0}break;default:newValue=Number(this.__elementInput.value),notNumberOrBigInt=isNaN(newValue)}this.__elementInput.value.trim()&&!notNumberOrBigInt&&(null===this.__internalMaxValue||void 0!==newValue&&newValue<=this.__internalMaxValue)&&(null===this.__internalMinValue||void 0!==newValue&&newValue>=this.__internalMinValue)?this.__setValue(newValue):this.__resetToLastValidValue&&this.__setValue(this.__lastValidValue)}}setValueType(valueNew){let convertedValue=TcHmi.ValueConverter.toEnum(valueNew,{Number:"Number",BigInt64:"BigInt64",UnsignedBigInt64:"UnsignedBigInt64"});null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ValueType")),this.__valueType!==convertedValue&&(this.__valueType=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ValueType"}),this.__processValueType())}__processValueType(){this.__attributesInitialized?(void 0!==this.__value&&this.setValue(this.__value),void 0!==this.__maxValue&&this.setMaxValue(this.__maxValue),void 0!==this.__minValue&&this.setMinValue(this.__minValue)):(void 0!==this.__valueInit&&this.setValue(this.__valueInit),void 0!==this.__maxValueInit&&this.setMaxValue(this.__maxValueInit),void 0!==this.__minValueInit&&this.setMinValue(this.__minValueInit))}getValueType(){}setValue(valueNew){if(this.__locked&&!this.__isReadOnly)return;if(!this.__attributesInitialized&&!this.__valueType)return void(this.__valueInit=valueNew);let convertedValue;switch(this.__valueType){case"BigInt64":convertedValue=TcHmi.ValueConverter.toBigInt64(valueNew),null===convertedValue&&(convertedValue=TcHmi.ValueConverter.toBigInt64(this.getAttributeDefaultValueInternal("Value")));break;case"UnsignedBigInt64":convertedValue=TcHmi.ValueConverter.toUnsignedBigInt64(valueNew),null===convertedValue&&(convertedValue=TcHmi.ValueConverter.toUnsignedBigInt64(this.getAttributeDefaultValueInternal("Value")));break;default:convertedValue=TcHmi.ValueConverter.toNumber(valueNew),null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("Value"))}if(this.__ignoreInvalidValues){if(null!==this.__internalMinValue&&null!==valueNew&&valueNew<this.__internalMinValue)return;if(null!==this.__internalMaxValue&&null!==valueNew&&valueNew>this.__internalMaxValue)return}this.__setValue(convertedValue)}__setValue(valueNew,options={process:!0,fromInput:!1}){let convertedValue;switch(this.__valueType){case"BigInt64":convertedValue=TcHmi.ValueConverter.toBigInt64(valueNew),null===convertedValue&&(convertedValue=TcHmi.ValueConverter.toBigInt64(this.getAttributeDefaultValueInternal("Value")));break;case"UnsignedBigInt64":convertedValue=TcHmi.ValueConverter.toUnsignedBigInt64(valueNew),null===convertedValue&&(convertedValue=TcHmi.ValueConverter.toUnsignedBigInt64(this.getAttributeDefaultValueInternal("Value")));break;default:convertedValue=TcHmi.ValueConverter.toNumber(valueNew),null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("Value"))}null===convertedValue?this.__lastValidValue=void 0:(null===this.__internalMinValue||convertedValue>=this.__internalMinValue)&&(null===this.__internalMaxValue||convertedValue<=this.__internalMaxValue)?this.__lastValidValue=convertedValue:null!==this.__value&&void 0!==this.__value&&(null===this.__internalMinValue||this.__value>=this.__internalMinValue)&&(null===this.__internalMaxValue||this.__value<=this.__internalMaxValue)&&(this.__lastValidValue=this.__value),this.__value=convertedValue,options?.process&&this.__processValue(options?.fromInput);let currentValue=this.getValue();void 0!==currentValue&¤tValue!==this.__lastReportedValue&&(this.__lastReportedValue=currentValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"Value"}),TcHmi.EventProvider.raise(this.__id+".onValueChanged",currentValue))}getValue(){return void 0===this.__value||null===this.__value?this.__value:""===this.__elementInput.value?null:this.__lastValidValue}__processValue(fromInput=!1){fromInput||(this.__elementInput.value=this.__formatValue(this.__value)),this.__validateInput()}__formatValue(value){let notNumberOrBigInt=!1;if(null!=value){let temp;switch(this.__valueType){case"BigInt64":case"UnsignedBigInt64":try{temp=BigInt(value)}catch{notNumberOrBigInt=!0}break;default:temp=Number(value),notNumberOrBigInt=isNaN(temp)}}return notNumberOrBigInt||null==value?"".padStart(this.__zeroPadding??0,"0"):this.__numberFormatter.format(value)}__floorToDecimals(value){if(null!==this.__decimalDigits&&void 0!==this.__decimalDigits&&"number"==typeof value){const factor=Math.pow(10,this.__decimalDigits);return(Math.floor(value*factor)/factor).toFixed(this.__decimalDigits)}return value.toString()}__ceilToDecimals(value){if(null!==this.__decimalDigits&&void 0!==this.__decimalDigits&&"number"==typeof value){const factor=Math.pow(10,this.__decimalDigits);return(Math.ceil(value*factor)/factor).toFixed(this.__decimalDigits)}return value.toString()}setMinValue(valueNew){if(!this.__attributesInitialized&&!this.__valueType)return void(this.__minValueInit=valueNew);let convertedValue;switch(this.__valueType){case"BigInt64":convertedValue=TcHmi.ValueConverter.toBigInt64(valueNew),null===convertedValue&&(convertedValue=TcHmi.ValueConverter.toBigInt64(this.getAttributeDefaultValueInternal("MinValue")));break;case"UnsignedBigInt64":convertedValue=TcHmi.ValueConverter.toUnsignedBigInt64(valueNew),null===convertedValue&&(convertedValue=TcHmi.ValueConverter.toUnsignedBigInt64(this.getAttributeDefaultValueInternal("MinValue")));break;default:convertedValue=TcHmi.ValueConverter.toNumber(valueNew),null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("MinValue"))}convertedValue!==this.__minValue&&(this.__minValue=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"MinValue"}),this.__processMinMaxValue())}getMinValue(){return this.__minValue}__processMinMaxValue(){this.__setInternalMinMaxValues();let newValue,notNumberOrBigInt=!1;switch(this.__valueType){case"BigInt64":case"UnsignedBigInt64":try{newValue=BigInt(this.__elementInput.value)}catch{notNumberOrBigInt=!0}break;default:newValue=Number(this.__elementInput.value),notNumberOrBigInt=isNaN(newValue)}this.__elementInput.value.trim()?!notNumberOrBigInt&&(null===this.__internalMaxValue||void 0!==newValue&&newValue<=this.__internalMaxValue)&&(null===this.__internalMinValue||void 0!==newValue&&newValue>=this.__internalMinValue)?this.__setValue(newValue):this.__setValue(this.__lastValidValue):this.__resetToLastValidValue&&this.__setValue(this.__lastValidValue)}setMaxValue(valueNew){if(!this.__attributesInitialized&&!this.__valueType)return void(this.__maxValueInit=valueNew);let convertedValue;switch(this.__valueType){case"BigInt64":convertedValue=TcHmi.ValueConverter.toBigInt64(valueNew),null===convertedValue&&(convertedValue=TcHmi.ValueConverter.toBigInt64(this.getAttributeDefaultValueInternal("MaxValue")));break;case"UnsignedBigInt64":convertedValue=TcHmi.ValueConverter.toUnsignedBigInt64(valueNew),null===convertedValue&&(convertedValue=TcHmi.ValueConverter.toUnsignedBigInt64(this.getAttributeDefaultValueInternal("MaxValue")));break;default:convertedValue=TcHmi.ValueConverter.toNumber(valueNew),null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("MaxValue"))}convertedValue!==this.__maxValue&&(this.__maxValue=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"MaxValue"}),this.__processMinMaxValue())}getMaxValue(){return this.__maxValue}setDecimalDigits(valueNew){let convertedValue=TcHmi.ValueConverter.toNumber(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("DecimalDigits")),convertedValue!==this.__decimalDigits&&(this.__decimalDigits=convertedValue,this.__decimalDigits&&this.__decimalDigits<0&&(this.__decimalDigits=0),TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"DecimalDigits"}),this.__processDecimalDigits())}getDecimalDigits(){return this.__decimalDigits}__processDecimalDigits(){this.__updateFormatter(),this.__processValue(),this.__processSystemKeyboardInputMode()}__updateFormatter(){let numberFormatOptions={useGrouping:!1,maximumFractionDigits:100};if(this.__zeroPadding&&(numberFormatOptions.minimumIntegerDigits=this.__zeroPadding),void 0!==this.__decimalDigits&&null!==this.__decimalDigits&&(numberFormatOptions.maximumFractionDigits=this.__decimalDigits,numberFormatOptions.minimumFractionDigits=this.__decimalDigits),"Round"===this.__decimalPrecisionMode);else numberFormatOptions.roundingMode="trunc";this.__numberFormatter=Intl.NumberFormat("en-US",numberFormatOptions)}setDecimalPrecisionMode(valueNew){let convertedValue=TcHmi.ValueConverter.toString(valueNew);if(null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("DecimalPrecisionMode")),convertedValue!==this.__decimalPrecisionMode){if("Round"===convertedValue)this.__decimalPrecisionMode=convertedValue;else this.__decimalPrecisionMode="Truncate";TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"DecimalPrecisionMode"}),this.__processDecimalPrecisionMode()}}getDecimalPrecisionMode(){return this.__decimalPrecisionMode}__processDecimalPrecisionMode(){this.__updateFormatter(),this.__processValue()}setUnit(valueNew){let convertedValue=TcHmi.ValueConverter.toString(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("Unit")),convertedValue!==this.__unit&&(this.__unit=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"Unit"}),this.__processUnit())}getUnit(){return this.__unit}__processUnit(){this.__elementUnit.textContent=this.__unit??"",this.__elementUnit.style.visibility=this.__unit?"visible":"collapsed",this.__elementUnit.style.right="Left"!==this.__unitPosition?"0":"",this.__processContentPadding()}setUnitPosition(valueNew){let convertedValue=TcHmi.ValueConverter.toString(valueNew);if(null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("UnitPosition")),convertedValue!==this.__unitPosition){if("Left"===convertedValue)this.__unitPosition=convertedValue;else this.__unitPosition="Right";TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"UnitPosition"}),this.__processUnitPosition()}}getUnitPosition(){return this.__unitPosition}__processUnitPosition(){this.__processUnit()}setSystemKeyboardInputMode(valueNew){let convertedValue=TcHmi.ValueConverter.toString(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("SystemKeyboardInputMode")),convertedValue!==this.__systemKeyboardInputMode&&(this.__systemKeyboardInputMode=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"SystemKeyboardInputMode"}),this.__processSystemKeyboardInputMode())}getSystemKeyboardInputMode(){return this.__systemKeyboardInputMode}__processSystemKeyboardInputMode(){this.__systemKeyboardInputMode?this.__elementInput.setAttribute("data-tchmi-input-mode",this.__systemKeyboardInputMode):0===this.__decimalDigits?this.__elementInput.setAttribute("data-tchmi-input-mode","numeric"):this.__elementInput.setAttribute("data-tchmi-input-mode","decimal")}setValueHorizontalAlignment(valueNew){let convertedValue=TcHmi.ValueConverter.toHorizontalAlignment(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ValueHorizontalAlignment")),convertedValue!==this.__valueHorizontalAlignment&&(this.__valueHorizontalAlignment=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ValueHorizontalAlignment"}),this.__processValueHorizontalAlignment())}getValueHorizontalAlignment(){return this.__valueHorizontalAlignment}__processValueHorizontalAlignment(){switch(this.__valueHorizontalAlignment){case"Left":TcHmi.StyleProvider.setSimpleElementStyle(this.__elementInput,"text-align","left");break;case"Center":TcHmi.StyleProvider.setSimpleElementStyle(this.__elementInput,"text-align","center");break;case"Right":TcHmi.StyleProvider.setSimpleElementStyle(this.__elementInput,"text-align","right");break;default:TcHmi.StyleProvider.setSimpleElementStyle(this.__elementInput,"text-align",null)}this.__elementInvalidNotificationLabel.classList.toggle("invalid-notification-alignment-left","Right"===this.__valueHorizontalAlignment)}setContentPadding(valueNew){let convertedValue=TcHmi.ValueConverter.toObject(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ContentPadding"));let resolverInfo=this.__objectResolvers.get("contentPadding");resolverInfo&&(resolverInfo.watchDestroyer&&resolverInfo.watchDestroyer(),resolverInfo.resolver.destroy());let resolver=new TcHmi.Symbol.ObjectResolver(convertedValue,{parentControl:this,type:this.getAttributeDescription("ContentPadding")?.type});this.__objectResolvers.set("contentPadding",{resolver,watchCallback:this.__onResolverForContentPaddingWatchCallback,watchDestroyer:resolver.watch(this.__onResolverForContentPaddingWatchCallback)})}__onResolverForContentPaddingWatchCallback(data){this.__isAttached||this.__suspendObjectResolver("contentPadding"),data.error===TcHmi.Errors.NONE?tchmi_equal(data.value,this.__contentPadding)||(this.__contentPadding=data.value,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ContentPadding"}),this.__processContentPadding()):TcHmi.Log.Controls.error(this,TcHmiNumericInput.#tchmiFQN,{Attribute:"ContentPadding"},`Resolving symbols from object failed with error: ${TcHmi.Log.buildMessage(data.details)}`)}getContentPadding(){return this.__contentPadding}__processContentPadding(){let padding=tchmi_clone_object(this.__contentPadding)??{bottom:0,left:0,right:0,top:0,bottomUnit:"px",leftUnit:"px",rightUnit:"px",topUnit:"px"};this.__unit&&("Left"!==this.__unitPosition?"%"!==padding.rightUnit?padding.right+=this.__elementUnit.getBoundingClientRect().width:padding.right+=this.__elementTemplateRoot.getBoundingClientRect().width/this.__elementUnit.getBoundingClientRect().width:"%"!==padding.leftUnit?padding.left+=this.__elementUnit.getBoundingClientRect().width:padding.left+=this.__elementTemplateRoot.getBoundingClientRect().width/this.__elementUnit.getBoundingClientRect().width),TcHmi.StyleProvider.processContentPadding(this.__elementInput,padding),TcHmi.StyleProvider.processContentPadding(this.__elementInvalidNotificationLabel,padding)}setValueFontSize(valueNew){let convertedValue=TcHmi.ValueConverter.toNumber(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ValueFontSize")),convertedValue!==this.__valueFontSize&&(this.__valueFontSize=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ValueFontSize"}),this.__processValueFontSize())}getValueFontSize(){return this.__valueFontSize}__processValueFontSize(){TcHmi.StyleProvider.processFontSize(this.__elementInput,this.__valueFontSize,this.__valueFontSizeUnit)}setValueFontSizeUnit(valueNew){let convertedValue=TcHmi.ValueConverter.toFontSizeUnit(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ValueFontSizeUnit")),convertedValue!==this.__valueFontSizeUnit&&(this.__valueFontSizeUnit=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ValueFontSizeUnit"}),this.__processValueFontSizeUnit())}getValueFontSizeUnit(){return this.__valueFontSizeUnit}__processValueFontSizeUnit(){TcHmi.StyleProvider.processFontSize(this.__elementInput,this.__valueFontSize,this.__valueFontSizeUnit)}setValueFontFamily(valueNew){let convertedValue=TcHmi.ValueConverter.toFontFamily(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ValueFontFamily")),convertedValue!==this.__valueFontFamily&&(this.__valueFontFamily=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ValueFontFamily"}),this.__processValueFontFamily())}getValueFontFamily(){return this.__valueFontFamily}__processValueFontFamily(){TcHmi.StyleProvider.processFontFamily(this.__elementInput,this.__valueFontFamily)}setValueFontStyle(valueNew){let convertedValue=TcHmi.ValueConverter.toFontStyle(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ValueFontStyle")),convertedValue!==this.__valueFontStyle&&(this.__valueFontStyle=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ValueFontStyle"}),this.__processValueFontStyle())}getValueFontStyle(){return this.__valueFontStyle}__processValueFontStyle(){TcHmi.StyleProvider.processFontStyle(this.__elementInput,this.__valueFontStyle)}setValueFontWeight(valueNew){let convertedValue=TcHmi.ValueConverter.toFontWeight(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ValueFontWeight")),convertedValue!==this.__valueFontWeight&&(this.__valueFontWeight=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ValueFontWeight"}),this.__processValueFontWeight())}getValueFontWeight(){return this.__valueFontWeight}__processValueFontWeight(){TcHmi.StyleProvider.processFontWeight(this.__elementInput,this.__valueFontWeight)}setPlaceholder(valueNew){let convertedValue=TcHmi.ValueConverter.toString(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("Placeholder")),convertedValue!==this.__placeholder&&(this.__placeholder=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"Placeholder"}),this.__processPlaceholder())}getPlaceholder(){return this.__placeholder}__processPlaceholder(){this.__placeholder?this.__elementInput.setAttribute("placeholder",this.__placeholder):this.__elementInput.removeAttribute("placeholder")}setZeroPadding(valueNew){let convertedValue=TcHmi.ValueConverter.toNumber(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ZeroPadding")),convertedValue!==this.__zeroPadding&&(this.__zeroPadding=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ZeroPadding"}),this.__processZeroPadding())}getZeroPadding(){return this.__zeroPadding}__processZeroPadding(){this.__updateFormatter(),this.__processValue()}setValueColor(valueNew){let convertedValue=TcHmi.ValueConverter.toObject(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ValueColor"));let resolverInfo=this.__objectResolvers.get("textColor");resolverInfo&&(resolverInfo.watchDestroyer&&resolverInfo.watchDestroyer(),resolverInfo.resolver.destroy());let resolver=new TcHmi.Symbol.ObjectResolver(convertedValue,{parentControl:this,type:this.getAttributeDescription("ValueColor")?.type});this.__objectResolvers.set("textColor",{resolver,watchCallback:this.__onResolverForValueColorWatchCallback,watchDestroyer:resolver.watch(this.__onResolverForValueColorWatchCallback)})}__onResolverForValueColorWatchCallback(data){this.__isAttached||this.__suspendObjectResolver("textColor"),data.error===TcHmi.Errors.NONE?tchmi_equal(data.value,this.__valueColor)||(this.__valueColor=data.value,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ValueColor"}),this.__processValueColor()):TcHmi.Log.Controls.error(this,TcHmiNumericInput.#tchmiFQN,{Attribute:"ValueColor"},`Resolving symbols from object failed with error: ${TcHmi.Log.buildMessage(data.details)}`)}getValueColor(){return this.__valueColor}__processValueColor(){TcHmi.StyleProvider.processTextColor(this.__elementInput,this.__valueColor)}setAutoFocusOut(valueNew){let convertedValue=TcHmi.ValueConverter.toBoolean(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("AutoFocusOut")),convertedValue!==this.__autoFocusOut&&(this.__autoFocusOut=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"AutoFocusOut"}),this.__processAutoFocusOut())}getAutoFocusOut(){return this.__autoFocusOut}__processAutoFocusOut(){}__lock(){this.__locked=!0}__unlock(){this.__locked=!1}__processControlActivation(){const valueInput=this.__elementInput;TcHmi.Access.checkAccess(this,"operate")&&this.getIsEnabled()?valueInput.disabled=!1:(this.__unlock(),valueInput.blur(),valueInput.disabled=!0)}__processIsEnabled(){super.__processIsEnabled(),this.__processControlActivation()}__processAccessConfig(){super.__processAccessConfig(),this.__processControlActivation()}
|
|
/**
|
|
* Sets the isReadOnly attribute and calls the associated process function (processIsReadOnly).
|
|
* @preserve (Part of the public API)
|
|
*/setIsReadOnly(valueNew){let convertedValue=TcHmi.ValueConverter.toBoolean(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("IsReadOnly")),convertedValue!==this.__isReadOnly&&(this.__isReadOnly=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"IsReadOnly"}),this.__processIsReadOnly())}getIsReadOnly(){return this.__isReadOnly}__processIsReadOnly(){this.__element[0].classList.toggle("read-only",this.__isReadOnly??!1),this.__elementInput.readOnly=this.__isReadOnly??!1}setAutoSelectText(valueNew){let convertedValue=TcHmi.ValueConverter.toBoolean(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("AutoSelectText")),convertedValue!==this.__autoSelectText&&(this.__autoSelectText=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"AutoSelectText"}))}getAutoSelectText(){return this.__autoSelectText}setResetToLastValidValue(valueNew){let convertedValue=TcHmi.ValueConverter.toBoolean(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("ResetToLastValidValue")),convertedValue!==this.__resetToLastValidValue&&(this.__resetToLastValidValue=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"ResetToLastValidValue"}),this.__processResetToLastValidValue())}getResetToLastValidValue(){return this.__resetToLastValidValue}__processResetToLastValidValue(){this.__resetToLastValidValue&&this.__setValue(this.__lastValidValue)}setInputProcessingPoint(valueNew){let convertedValue=TcHmi.ValueConverter.toEnum(valueNew,InputProcessingPoint);null===convertedValue&&(convertedValue=InputProcessingPoint[this.getAttributeDefaultValueInternal("InputProcessingPoint")]),convertedValue!==this.__valueBuffer?.processingPoint&&(this.__valueBuffer?this.__valueBuffer.processingPoint=convertedValue:this.__valueBuffer=new ValueBuffer(convertedValue,value=>this.__setValue(value,{process:!0,fromInput:!0})),TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"InputProcessingPoint"}),this.__processInputProcessingPoint())}getInputProcessingPoint(){return this.__valueBuffer?.processingPoint}__processInputProcessingPoint(){}setIgnoreInvalidValues(valueNew){let convertedValue=TcHmi.ValueConverter.toBoolean(valueNew);null===convertedValue&&(convertedValue=this.getAttributeDefaultValueInternal("IgnoreInvalidValues")),convertedValue!==this.__ignoreInvalidValues&&(this.__ignoreInvalidValues=convertedValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"IgnoreInvalidValues"}),this.__processIgnoreInvalidValues())}getIgnoreInvalidValues(){return this.__ignoreInvalidValues}__processIgnoreInvalidValues(){this.__ignoreInvalidValues&&this.__setValue(this.__lastValidValue)}focus(){this.__elementInput.focus()}__setIsValid(newValue){this.__isValid!==newValue&&(this.__isValid=newValue,TcHmi.EventProvider.raise(this.__id+".onPropertyChanged",{propertyName:"IsValid"}))}getIsValid(){return this.__isValid}}})();TcHmi.Controls.registerEx("TcHmiNumericInput","TcHmi.Controls.Beckhoff",TcHmiNumericInput,{injectInGlobalObject:!0});export{TcHmiNumericInput as Control}; |