UNPKG

@tripetto/block-number

Version:

Number block for Tripetto.

3 lines (2 loc) 2.04 kB
/*! Tripetto Number Block 8.0.3 - Copyright (C) 2023 Tripetto B.V. - All Rights Reserved */ import{tripetto as e,condition as t,ConditionBlock as r,isString as o,Slots as a,isNumberFinite as l,Num as s,mountNamespace as i,unmountNamespace as u,NodeBlock as n,assert as c}from"@tripetto/runner";import{calculator as p}from"@tripetto/block-calculator/runner";function h(e,t,r,o){var a,l=arguments.length,s=l<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,o);else for(var i=e.length-1;i>=0;i--)(a=e[i])&&(s=(l<3?a(s):l>3?a(t,r,s):a(t,r))||s);return l>3&&s&&Object.defineProperty(t,r,s),s}let f=class extends r{getValue(e,t){if(o(t)&&e instanceof a.Numeric){const r=this.variableFor(t);return r&&r.hasValue?e.toValue(r.value):void 0}return l(t)?t:void 0}verify(){const e=this.valueOf();if(e){const t=this.getValue(e.slot,this.props.value);switch(this.props.mode){case"equal":return(e.hasValue?e.value:void 0)===t;case"not-equal":return(e.hasValue?e.value:void 0)!==t;case"below":return l(t)&&e.hasValue&&e.value<t;case"above":return l(t)&&e.hasValue&&e.value>t;case"between":case"not-between":const r=this.getValue(e.slot,this.props.to);return l(t)&&l(r)&&(e.hasValue&&e.value>=s.min(t,r)&&e.value<=s.max(t,r))===("between"===this.props.mode);case"defined":return e.hasValue;case"undefined":return!e.hasValue}}return!1}};h([t],f.prototype,"verify",null),f=h([e({type:"condition",legacyBlock:!0,identifier:"@tripetto/block-number"})],f),i("@tripetto/block-number"),u();class v extends n{constructor(){super(...arguments),this.calculatorSlot=this.valueOf("calculator","feature"),this.numberSlot=c(this.valueOf("number","static",{prefill:l(this.props.prefill)&&{value:this.props.prefill}||void 0,onChange:e=>{this.calculatorSlot&&e.slot instanceof a.Numeric&&p(this.context,this.props.operations||[],e,this.calculatorSlot,(e=>this.variableFor(e)),(e=>this.parseVariables(e)))}})),this.required=this.numberSlot.slot.required||!1}}export{v as Number};