@tripetto/block-textarea
Version:
Text input (multi-line) block for Tripetto.
3 lines (2 loc) • 8.29 kB
JavaScript
/*! Tripetto Textarea Block 6.0.3 - Copyright (C) 2023 Tripetto B.V. - All Rights Reserved */
import{definition as t,affects as e,tripetto as a,pgettext as i,editor as o,ConditionBlock as l,Slots as n,isVariable as s,lookupVariable as r,makeMarkdownSafe as c,Str as d,Forms as x,populateVariables as h,insertVariable as b,NodeBlock as m,isNumber as u,isString as g,each as M,slots as p,conditions as v}from"@tripetto/builder";function I(t,e,a,i){var o,l=arguments.length,n=l<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,a):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,a,i);else for(var s=t.length-1;s>=0;s--)(o=t[s])&&(n=(l<3?o(n):l>3?o(e,a,n):o(e,a))||n);return l>3&&n&&Object.defineProperty(e,a,n),n}let k=class extends l{constructor(){super(...arguments),this.allowMarkdown=!0,this.mode="exact"}get label(){return""}get name(){var t;if(this.slot instanceof n.Text){const e=t=>t&&("contains"===this.mode||"not-contains"===this.mode||"starts"===this.mode||"ends"===this.mode)&&`_${t}_`||t,a=(s(this.match)?(null===(t=r(this,this.match))||void 0===t?void 0:t.label)&&`@${this.match}`:this.match&&e(c(d.replace(this.match,"\n","↵"))))||"\\_\\_";switch(this.mode){case"exact":case"not-exact":return`@${this.slot.id} ${"not-exact"===this.mode?"≠":"="} ${a}`;case"contains":case"not-contains":case"starts":case"ends":return`@${this.slot.id} ${"not-contains"===this.mode?i("block:textarea","does not contain"):"starts"===this.mode?i("block:textarea","starts with"):"ends"===this.mode?i("block:textarea","ends with"):i("block:textarea","contains")} ${a}`;case"defined":return`@${this.slot.id} ${i("block:textarea","not empty")}`;case"undefined":return`@${this.slot.id} ${i("block:textarea","empty")}`}}return this.type.label}get title(){var t;return null===(t=this.node)||void 0===t?void 0:t.label}defineEditor(){var t;this.editor.form({title:i("block:textarea","Compare mode"),controls:[new x.Radiobutton([{label:i("block:textarea","Text matches"),value:"exact"},{label:i("block:textarea","Text does not match"),value:"not-exact"},{label:i("block:textarea","Text contains"),value:"contains"},{label:i("block:textarea","Text does not contain"),value:"not-contains"},{label:i("block:textarea","Text starts with"),value:"starts"},{label:i("block:textarea","Text ends with"),value:"ends"},{label:i("block:textarea","Text is not empty"),value:"defined"},{label:i("block:textarea","Text is empty"),value:"undefined"}],x.Radiobutton.bind(this,"mode","exact")).on((t=>{switch(n.visible("defined"!==t.value&&"undefined"!==t.value),t.value){case"exact":n.title=i("block:textarea","If text matches");break;case"not-exact":n.title=i("block:textarea","If text does not match");break;case"contains":n.title=i("block:textarea","If text contains");break;case"not-contains":n.title=i("block:textarea","If text does not contain");break;case"starts":n.title=i("block:textarea","If text starts with");break;case"ends":n.title=i("block:textarea","If text ends with")}o.isInteractable&&o.focus()}))]});const e=this.match&&s(this.match)||!1,a=h(this,void 0,e?this.match:void 0,!1,null===(t=this.slot)||void 0===t?void 0:t.id),o=new x.Text("multiline",e?"":this.match).label(i("block:textarea","Use fixed text")).action("@",b(this,"exclude")).autoFocus().enter(this.editor.close).escape(this.editor.close).on((t=>{t.isFormVisible&&t.isObservable&&(this.match=t.value)})),l=new x.Dropdown(a,e?this.match:"").label(i("block:textarea","Use value of")).width("full").on((t=>{t.isFormVisible&&t.isObservable&&(this.match=t.value||void 0)})),n=this.editor.form({title:i("block:textarea","If text matches"),controls:[new x.Radiobutton([{label:i("block:textarea","Text"),value:"text"},{label:i("block:textarea","Value"),value:"variable",disabled:0===a.length}],e?"variable":"text").on((t=>{o.visible("text"===t.value),l.visible("variable"===t.value),o.isInteractable&&o.focus()})),o,l,new x.Checkbox(i("block:textarea","Ignore case"),x.Checkbox.bind(this,"ignoreCase",void 0,!0))]}).visible("defined"!==this.mode&&"undefined"!==this.mode)}};I([t,e("#name")],k.prototype,"mode",void 0),I([t,e("#name")],k.prototype,"match",void 0),I([t],k.prototype,"ignoreCase",void 0),I([o],k.prototype,"defineEditor",null),k=I([a({type:"condition",legacyBlock:!0,context:"@tripetto/block-textarea",identifier:"@tripetto/block-textarea",version:"6.0.3",icon:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTE3LjUgNWgtMTVhLjUuNSAwIDAgMSAwLTFoMTVhLjUuNSAwIDAgMSAwIDF6bS00IDNoLTExYS41LjUgMCAwIDEgMC0xaDExYS41LjUgMCAwIDEgMCAxem00IDNoLTE1YS41LjUgMCAwIDEgMC0xaDE1YS41LjUgMCAwIDEgMCAxem0tNCAzaC0xMWEuNS41IDAgMCAxIDAtMWgxMWEuNS41IDAgMCAxIDAgMXptNCAzaC0xNWEuNS41IDAgMCAxIDAtMWgxNWEuNS41IDAgMCAxIDAgMXoiIGNsYXNzPSJ0cmlwZXR0by1maWxsIi8+PC9zdmc+",get label(){return i("block:textarea","Text contains")}})],k);let A=class extends m{defineSlot(){this.textareaSlot=this.slots.static({type:n.Text,reference:"value",label:i("block:textarea","Multi-line text"),exchange:["required","alias","exportable","maxLength","transformation"]})}defineEditor(){this.editor.name(),this.editor.description(),this.editor.placeholder(),this.editor.explanation(),this.editor.groups.settings();const t=new x.Numeric(x.Numeric.bind(this,"minLength",void 0)).min(1).max(this.textareaSlot.maxLength).visible(u(this.minLength)).indent(32).width(75).on((()=>{e.min(this.minLength||1)})),e=new x.Numeric(x.Numeric.bind(this.textareaSlot,"maxLength",void 0)).min(this.minLength||1).visible(u(this.textareaSlot.maxLength)).indent(32).width(75).on((()=>{t.max(this.textareaSlot.maxLength)}));this.editor.option({name:i("block:textarea","Limits"),form:{title:i("block:textarea","Limits"),controls:[new x.Checkbox(i("block:textarea","Minimum"),u(this.minLength)).on((e=>{t.visible(e.isChecked)})),t,new x.Checkbox(i("block:textarea","Maximum"),u(this.textareaSlot.maxLength)).on((t=>{e.visible(t.isChecked)})),e]},activated:u(this.textareaSlot.maxLength)||u(this.minLength)}),this.editor.transformations(this.textareaSlot),this.editor.groups.options(),this.editor.option({name:i("block:textarea","Prefill"),form:{title:i("block:textarea","Prefill"),controls:[new x.Text("multiline",x.Text.bind(this,"prefill",void 0)).label(i("block:textarea","Prefill with the following text:"))]},activated:g(this.prefill)}),this.editor.required(this.textareaSlot),this.editor.visibility(),this.editor.alias(this.textareaSlot),this.editor.exportable(this.textareaSlot)}defineCondition(){M([{mode:"exact",label:i("block:textarea","Text matches")},{mode:"not-exact",label:i("block:textarea","Text does not match")},{mode:"contains",label:i("block:textarea","Text contains")},{mode:"not-contains",label:i("block:textarea","Text does not contain")},{mode:"starts",label:i("block:textarea","Text starts with")},{mode:"ends",label:i("block:textarea","Text ends with")},{mode:"defined",label:i("block:textarea","Text is not empty")},{mode:"undefined",label:i("block:textarea","Text is empty")}],(t=>{this.conditions.template({condition:k,label:t.label,autoOpen:"defined"!==t.mode&&"undefined"!==t.mode,props:{slot:this.textareaSlot,mode:t.mode}})}))}};I([t("string","optional")],A.prototype,"prefill",void 0),I([t("number","optional")],A.prototype,"minLength",void 0),I([p],A.prototype,"defineSlot",null),I([o],A.prototype,"defineEditor",null),I([v],A.prototype,"defineCondition",null),A=I([a({type:"node",legacyBlock:!0,identifier:"@tripetto/block-textarea",version:"6.0.3",icon:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTE3LjUgNWgtMTVhLjUuNSAwIDAgMSAwLTFoMTVhLjUuNSAwIDAgMSAwIDF6bTAgMTJoLTE1YS41LjUgMCAwIDEgMC0xaDE1YS41LjUgMCAwIDEgMCAxem0tMi05aC0xM2EuNS41IDAgMCAwIDAgMWgxM2MuODI3IDAgMS41LjY3MyAxLjUgMS41cy0uNjczIDEuNS0xLjUgMS41aC01LjI5M2wxLjE0Ni0xLjE0NmEuNS41IDAgMCAwLS43MDctLjcwN2wtMiAyYS41LjUgMCAwIDAgMCAuNzA3bDIgMmEuNDk4LjQ5OCAwIDAgMCAuNzA4IDAgLjUuNSAwIDAgMCAwLS43MDdsLTEuMTQ2LTEuMTQ2aDUuMjkzYzEuMzc4IDAgMi41LTEuMTIyIDIuNS0yLjVzLTEuMTIyLTIuNS0yLjUtMi41eiIgY2xhc3M9InRyaXBldHRvLWZpbGwiLz48cGF0aCBkPSJNNi41IDEzaC00YS41LjUgMCAwIDEgMC0xaDRhLjUuNSAwIDAgMSAwIDF6IiBjbGFzcz0idHJpcGV0dG8tZmlsbCIvPjwvc3ZnPg==",get label(){return i("block:textarea","Text (multiple lines)")}})],A);export{A as Textarea};