UNPKG

@tripetto/block-text

Version:

Text input (single-line) block for Tripetto.

3 lines (2 loc) 3.35 kB
/*! Tripetto Text Block 6.0.2 - Copyright (C) 2023 Tripetto B.V. - All Rights Reserved */ import{tripetto as e,condition as t,ConditionBlock as s,isVariable as r,Str as i,isString as o,Slots as n,isNumberFinite as a,Num as l,NodeBlock as u,assert as h,findFirst as c,validator as p}from"@tripetto/runner";function d(e,t,s,r){var i,o=arguments.length,n=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,s,r);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(n=(o<3?i(n):o>3?i(t,s,n):i(t,s))||n);return o>3&&n&&Object.defineProperty(t,s,n),n}let g=class extends s{getMatchString(){if(r(this.props.match)){const e=this.variableFor(this.props.match);return e&&e.hasValue?e.string:""}return this.parseVariables(this.props.match||"")}isEqual(){const e=this.valueOf();if(e){const t=this.props.ignoreCase?i.lowercase(this.getMatchString()):this.getMatchString(),s=this.props.ignoreCase?i.lowercase(e.string):e.string;switch(this.props.mode){case"exact":return s===t;case"not-exact":return s!==t;case"contains":return t&&-1!==s.indexOf(t)||!1;case"not-contains":return t&&-1===s.indexOf(t)||!1;case"starts":return t&&0===s.indexOf(t)||!1;case"ends":return t&&s.length>=t.length&&s.lastIndexOf(t)===s.length-t.length||!1;case"defined":return""!==s;case"undefined":return""===s}}return!1}};d([t],g.prototype,"isEqual",null),g=d([e({type:"condition",legacyBlock:!0,identifier:"@tripetto/block-text"})],g);let v=class extends s{getValue(e,t){if(o(t)&&e instanceof n.Numeric){const s=this.variableFor(t);return s&&s.hasValue?e.toValue(s.value):void 0}return a(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 a(t)&&e.hasValue&&e.value<t;case"above":return a(t)&&e.hasValue&&e.value>t;case"between":case"not-between":const s=this.getValue(e.slot,this.props.to);return a(t)&&a(s)&&(e.hasValue&&e.value>=l.min(t,s)&&e.value<=l.max(t,s))===("between"===this.props.mode);case"defined":return e.hasValue;case"undefined":return!e.hasValue}}return!1}};d([t],v.prototype,"verify",null),v=d([e({type:"condition",legacyBlock:!0,identifier:"@tripetto/block-text:score"})],v);class f extends u{constructor(){super(...arguments),this.scoreSlot=this.valueOf("score","feature"),this.textSlot=h(this.valueOf("value","static",{prefill:o(this.props.prefill)&&{value:this.props.prefill}||void 0,modifier:e=>{var t;if(this.props.useSuggestions)return{value:e.value,reference:e.value&&(null===(t=c(this.props.suggestions,(t=>t.name===e.value)))||void 0===t?void 0:t.id)||void 0}},onChange:e=>{if(this.scoreSlot){const t=this.props.useSuggestions&&c(this.props.suggestions,(t=>t.name===e.value))||void 0;this.scoreSlot.set(t&&((null==t?void 0:t.score)||0))}}})),this.required=this.textSlot.slot.required||!1,this.maxLength=this.textSlot.slot.maxLength,this.autoComplete=this.props.autoComplete}get suggestions(){var e;return this.props.useSuggestions&&(null===(e=this.props.suggestions)||void 0===e?void 0:e.map((e=>e.name)))||void 0}validate(){return!this.props.minLength||!this.textSlot.value.length||this.textSlot.value.length>=this.props.minLength}}d([p],f.prototype,"validate",null);export{f as Text};