UNPKG

@tripetto/block-text

Version:

Text input (single-line) block for Tripetto.

3 lines (2 loc) 17.9 kB
/*! Tripetto Text Block 6.0.2 - Copyright (C) 2023 Tripetto B.V. - All Rights Reserved */ import{definition as e,affects as t,tripetto as o,pgettext as i,editor as l,ConditionBlock as s,Slots as n,isVariable as a,lookupVariable as c,makeMarkdownSafe as d,Forms as r,populateVariables as b,insertVariable as u,Collection as h,name as x,score as m,isNumberFinite as g,L10n as v,isString as p,supplies as k,NodeBlock as w,npgettext as f,isNumber as S,each as I,slots as M,conditions as A}from"@tripetto/builder";function N(e,t,o,i){var l,s=arguments.length,n=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,o,i);else for(var a=e.length-1;a>=0;a--)(l=e[a])&&(n=(s<3?l(n):s>3?l(t,o,n):l(t,o))||n);return s>3&&n&&Object.defineProperty(t,o,n),n}let y=class extends s{constructor(){super(...arguments),this.allowMarkdown=!0,this.mode="exact"}get block(){var e;return(null===(e=this.node)||void 0===e?void 0:e.block)instanceof T&&this.node.block||void 0}get label(){return""}get name(){var e;if(this.slot instanceof n.Text){const t=e=>e&&("contains"===this.mode||"not-contains"===this.mode||"starts"===this.mode||"ends"===this.mode)&&`_${e}_`||e,o=(a(this.match)?(null===(e=c(this,this.match))||void 0===e?void 0:e.label)&&`@${this.match}`:this.match&&t(d(this.match)))||"\\_\\_";switch(this.mode){case"exact":case"not-exact":return`@${this.slot.id} ${"not-exact"===this.mode?"≠":"="} ${o}`;case"contains":case"not-contains":case"starts":case"ends":return`@${this.slot.id} ${"not-contains"===this.mode?i("block:text","does not contain"):"starts"===this.mode?i("block:text","starts with"):"ends"===this.mode?i("block:text","ends with"):i("block:text","contains")} ${o}`;case"defined":return`@${this.slot.id} ${i("block:text","not empty")}`;case"undefined":return`@${this.slot.id} ${i("block:text","empty")}`}}return this.type.label}get title(){var e;return null===(e=this.node)||void 0===e?void 0:e.label}defineEditor(){var e,t;this.editor.form({title:i("block:text","Compare mode"),controls:[new r.Radiobutton([{label:i("block:text","Text matches"),value:"exact"},{label:i("block:text","Text does not match"),value:"not-exact"},{label:i("block:text","Text contains"),value:"contains"},{label:i("block:text","Text does not contain"),value:"not-contains"},{label:i("block:text","Text starts with"),value:"starts"},{label:i("block:text","Text ends with"),value:"ends"},{label:i("block:text","Text is not empty"),value:"defined"},{label:i("block:text","Text is empty"),value:"undefined"}],r.Radiobutton.bind(this,"mode","exact")).on((e=>{switch(c.visible("defined"!==e.value&&"undefined"!==e.value),e.value){case"exact":c.title=i("block:text","If text matches");break;case"not-exact":c.title=i("block:text","If text does not match");break;case"contains":c.title=i("block:text","If text contains");break;case"not-contains":c.title=i("block:text","If text does not contain");break;case"starts":c.title=i("block:text","If text starts with");break;case"ends":c.title=i("block:text","If text ends with")}s.isInteractable&&s.focus()}))]});const o=this.match&&a(this.match)||!1,l=b(this,void 0,o?this.match:void 0,!1,null===(e=this.slot)||void 0===e?void 0:e.id),s=new r.Text("singleline",o?"":this.match).label(i("block:text","Use fixed text")).action("@",u(this,"exclude")).suggestions(null===(t=this.block)||void 0===t?void 0:t.suggestions.all).autoFocus().enter(this.editor.close).escape(this.editor.close).on((e=>{e.isFormVisible&&e.isVisible&&(this.match=e.value)})),n=new r.Dropdown(l,o?this.match:"").label(i("block:text","Use value of")).width("full").on((e=>{e.isFormVisible&&e.isObservable&&(this.match=e.value||void 0)})),c=this.editor.form({title:i("block:text","If text matches"),controls:[new r.Radiobutton([{label:i("block:text","Text"),value:"text"},{label:i("block:text","Value"),value:"variable",disabled:0===l.length}],o?"variable":"text").on((e=>{s.visible("text"===e.value),n.visible("variable"===e.value),s.isInteractable&&s.focus()})),s,n,new r.Checkbox(i("block:text","Ignore case"),r.Checkbox.bind(this,"ignoreCase",void 0,!0))]}).visible("defined"!==this.mode&&"undefined"!==this.mode)}};N([e,t("#name")],y.prototype,"mode",void 0),N([e,t("#name")],y.prototype,"match",void 0),N([e],y.prototype,"ignoreCase",void 0),N([l],y.prototype,"defineEditor",null),y=N([o({type:"condition",legacyBlock:!0,context:"@tripetto/block-text",identifier:"@tripetto/block-text",version:"6.0.2",icon:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTE3LjUgNWgtMTVhLjUuNSAwIDAgMSAwLTFoMTVhLjUuNSAwIDAgMSAwIDF6bS00IDNoLTExYS41LjUgMCAwIDEgMC0xaDExYS41LjUgMCAwIDEgMCAxem00IDNoLTE1YS41LjUgMCAwIDEgMC0xaDE1YS41LjUgMCAwIDEgMCAxem0tNCAzaC0xMWEuNS41IDAgMCAxIDAtMWgxMWEuNS41IDAgMCAxIDAgMXptNCAzaC0xNWEuNS41IDAgMCAxIDAtMWgxNWEuNS41IDAgMCAxIDAgMXoiIGNsYXNzPSJ0cmlwZXR0by1maWxsIi8+PC9zdmc+",get label(){return i("block:text","Text match")}})],y);class D extends h.Item{constructor(){super(...arguments),this.name=""}defineEditor(){this.editor.option({name:i("block:text","Suggestion"),form:{title:i("block:text","Suggestion"),controls:[new r.Text("singleline",r.Text.bind(this,"name","")).autoFocus().autoSelect().enter(this.editor.close).escape(this.editor.close)]},locked:!0});const e=this.ref.slots.select("score","feature");this.editor.group(i("block:text","Options")),this.editor.option({name:i("block:text","Score"),form:{title:i("block:text","Score"),controls:[new r.Numeric(r.Numeric.bind(this,"score",void 0)).precision((null==e?void 0:e.precision)||0).digits((null==e?void 0:e.digits)||0).decimalSign((null==e?void 0:e.decimal)||"").thousands(!!(null==e?void 0:e.separator),(null==e?void 0:e.separator)||"").prefix((null==e?void 0:e.prefix)||"").prefixPlural((null==e?void 0:e.prefixPlural)||void 0).suffix((null==e?void 0:e.suffix)||"").suffixPlural((null==e?void 0:e.suffixPlural)||void 0)]},activated:!0,locked:!!e,disabled:!e})}}N([e("string"),x],D.prototype,"name",void 0),N([e("number","optional"),m],D.prototype,"score",void 0),N([l],D.prototype,"defineEditor",null);var L="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTE4LjUgOEgxM1YzLjVhLjUuNSAwIDAgMC0uNS0uNWgtNmEuNS41IDAgMCAwLS41LjVWNkguNWEuNS41IDAgMCAwLS41LjV2MTBhLjUuNSAwIDAgMCAuNS41aDE4YS41LjUgMCAwIDAgLjUtLjV2LThhLjUuNSAwIDAgMC0uNS0uNXpNNyA0aDV2MTJIN1Y0ek0xIDdoNXY5SDFWN3ptMTcgOWgtNVY5aDV2N3oiIGNsYXNzPSJ0cmlwZXR0by1maWxsIi8+PHBhdGggZD0iTTkuNSAxMGEuNS41IDAgMCAxLS41LS41di00YS41LjUgMCAwIDEgMSAwdjRhLjUuNSAwIDAgMS0uNS41em0tNSAzaC0yYS41LjUgMCAwIDEtLjUtLjV2LTJhLjUuNSAwIDAgMSAuNS0uNUg0VjlIMi41YS41LjUgMCAwIDEgMC0xaDJhLjUuNSAwIDAgMSAuNS41djJhLjUuNSAwIDAgMS0uNS41SDN2MWgxLjVhLjUuNSAwIDAgMSAwIDF6bTEyLTNoLTJhLjUuNSAwIDAgMCAwIDFIMTZ2MWgtMS41YS41LjUgMCAwIDAgMCAxSDE2djFoLTEuNWEuNS41IDAgMCAwIDAgMWgyYS41LjUgMCAwIDAgLjUtLjV2LTRhLjUuNSAwIDAgMC0uNS0uNXoiIGNsYXNzPSJ0cmlwZXR0by1maWxsIi8+PC9zdmc+";let C=class extends s{constructor(){super(...arguments),this.allowMarkdown=!0,this.mode="equal"}get label(){return""}get name(){const e=this.slot;if(e instanceof n.Numeric){const t=this.parse(e,this.value);switch(this.mode){case"between":return`${t} ≤ @${e.id} ≤ ${this.parse(e,this.to)}`;case"not-between":return`@${e.id} < ${t} ${i("block:text","or")} @${e.id} > ${this.parse(e,this.to)}`;case"defined":return`@${e.id} ${i("block:text","calculated")}`;case"undefined":return`@${e.id} ${i("block:text","not calculated")}`;case"not-equal":return`@${e.id} ≠ ${t}`;case"above":case"below":case"equal":return`@${e.id} ${"above"===this.mode?">":"below"===this.mode?"<":"="} ${t}`}}return this.type.label}get title(){var e,t;return(null===(e=this.slot)||void 0===e?void 0:e.label)||(null===(t=this.node)||void 0===t?void 0:t.label)}parse(e,t){var o;return g(t)?e.toString(t,((e,t)=>v.locale.number(e,t,!1))):p(t)&&t&&(null===(o=c(this,t))||void 0===o?void 0:o.label)?`@${t}`:"\\_\\_"}defineEditor(){this.editor.form({title:i("block:text","Compare mode"),controls:[new r.Radiobutton([{label:i("block:text","Score is equal to"),value:"equal"},{label:i("block:text","Score is not equal to"),value:"not-equal"},{label:i("block:text","Score is lower than"),value:"below"},{label:i("block:text","Score is higher than"),value:"above"},{label:i("block:text","Score is between"),value:"between"},{label:i("block:text","Score is not between"),value:"not-between"},{label:i("block:text","Score is calculated"),value:"defined"},{label:i("block:text","Score is not calculated"),value:"undefined"}],r.Radiobutton.bind(this,"mode","equal")).on((e=>{switch(t.visible("defined"!==e.value&&"undefined"!==e.value),o.visible("between"===e.value||"not-between"===e.value),e.value){case"equal":t.title=i("block:text","If score equals");break;case"not-equal":t.title=i("block:text","If score not equals");break;case"below":t.title=i("block:text","If score is lower than");break;case"above":t.title=i("block:text","If score is higher than");break;case"between":t.title=i("block:text","If score is between");break;case"not-between":t.title=i("block:text","If score is not between")}}))]});const e=(e,t,o)=>{var l;const s=this[e],a=this.slot,c=new r.Numeric(g(s)?s:0).label(i("block:text","Use fixed number")).precision((null==a?void 0:a.precision)||0).digits((null==a?void 0:a.digits)||0).decimalSign((null==a?void 0:a.decimal)||"").thousands(!!(null==a?void 0:a.separator),(null==a?void 0:a.separator)||"").prefix((null==a?void 0:a.prefix)||"").prefixPlural((null==a?void 0:a.prefixPlural)||void 0).suffix((null==a?void 0:a.suffix)||"").suffixPlural((null==a?void 0:a.suffixPlural)||void 0).autoFocus("value"===e).escape(this.editor.close).enter((()=>("between"!==this.mode&&"not-between"!==this.mode||"to"===e)&&this.editor.close())).on((t=>{t.isFormVisible&&t.isObservable&&(this[e]=t.value)})),d=b(this,(e=>e instanceof n.Number||e instanceof n.Numeric),p(s)?s:void 0,!0,null===(l=this.slot)||void 0===l?void 0:l.id),u=new r.Dropdown(d,p(s)?s:"").label(i("block:text","Use value of")).width("full").on((t=>{t.isFormVisible&&t.isObservable&&(this[e]=t.value||"")}));return this.editor.form({title:t,controls:[new r.Radiobutton([{label:i("block:text","Number"),value:"number"},{label:i("block:text","Value"),value:"variable",disabled:0===d.length}],p(s)?"variable":"number").on((e=>{c.visible("number"===e.value),u.visible("variable"===e.value),c.isObservable&&c.focus()})),c,u]}).visible(o)},t=e("value",i("block:text","If score equals"),"defined"!==this.mode&&"undefined"!==this.mode),o=e("to",i("block:text","And"),"between"===this.mode||"not-between"===this.mode)}};N([e,t("#name")],C.prototype,"mode",void 0),N([e,t("#name")],C.prototype,"value",void 0),N([e,t("#name")],C.prototype,"to",void 0),N([l],C.prototype,"defineEditor",null),C=N([o({type:"condition",legacyBlock:!0,context:"@tripetto/block-text",identifier:"@tripetto/block-text:score",version:"6.0.2",icon:L,get label(){return i("block:text","Verify score")}})],C);let T=class extends w{constructor(){super(...arguments),this.suggestions=h.of(D,this)}get label(){return this.useSuggestions?f("block:text","Text (%1 suggestion)","Text (%1 suggestions)",this.suggestions.count):this.type.label}defineSlot(){this.textSlot=this.slots.static({type:n.Text,reference:"value",label:i("block:text","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 e=new r.Numeric(r.Numeric.bind(this,"minLength",void 0)).min(1).max(this.textSlot.maxLength).visible(S(this.minLength)).indent(32).width(75).on((()=>{t.min(this.minLength||1)})),t=new r.Numeric(r.Numeric.bind(this.textSlot,"maxLength",void 0)).min(this.minLength||1).visible(S(this.textSlot.maxLength)).indent(32).width(75).on((()=>{e.max(this.textSlot.maxLength)}));this.editor.option({name:i("block:text","Limits"),form:{title:i("block:text","Limits"),controls:[new r.Checkbox(i("block:text","Minimum"),S(this.minLength)).on((t=>{e.visible(t.isChecked)})),e,new r.Checkbox(i("block:text","Maximum"),S(this.textSlot.maxLength)).on((e=>{t.visible(e.isChecked)})),t]},activated:S(this.textSlot.maxLength)||S(this.minLength)}),this.editor.option({name:i("block:text","Autocomplete"),form:{title:i("block:text","Autocomplete"),controls:[new r.Radiobutton([{label:i("block:text","Name"),value:"name",description:i("block:text","Person's full name.")},{label:i("block:text","Organization"),value:"organization",description:i("block:text","Company or organization name.")},{label:i("block:text","Job/organization title"),value:"organization-title",description:i("block:text","Job title, or the title a person has within an organization.")},{label:i("block:text","Street address"),value:"street-address",description:i("block:text","Location of the address within a city or town.")},{label:i("block:text","Postal code"),value:"postal-code",description:i("block:text","Postal code (in the United States, this is the ZIP code).")},{label:i("block:text","City (address level 2)"),value:"address-level2",description:i("block:text","City, town, village, or other locality in which the address is located.")},{label:i("block:text","Province or state (address level 1)"),value:"address-level1",description:i("block:text","Typically the province in which the address is located. In the United States, this would be the state. In Switzerland, the canton. In the United Kingdom, the post town.")},{label:i("block:text","Country"),value:"country-name",description:i("block:text","Name of the country.")},{label:i("block:text","Telephone number"),value:"tel",description:i("block:text","Full telephone number, including the country code.")},{label:i("block:text","Gender identity"),value:"sex",description:i("block:text","Gender identity as freeform text.")},{label:i("block:text","Username"),value:"username",description:i("block:text","Username or account name for the active domain.")}],r.Radiobutton.bind(this,"autoComplete",void 0)).label(i("block:text","Use the following autocomplete attribute for autocompletion:"))]},activated:p(this.autoComplete)});const o=this.editor.option({name:i("block:text","Suggestions"),collection:{collection:this.suggestions,title:i("block:text","Suggestions"),placeholder:i("block:text","Unnamed suggestion"),autoOpen:!0,editable:!0,allowImport:!0,allowExport:!0,allowDedupe:!0,showScores:!0,sorting:"manual",emptyMessage:i("block:text","Click the + button to add an suggestion...")},activated:!0===this.useSuggestions}).onToggle((()=>{this.useSuggestions=!!o.isActivated||void 0}));this.editor.transformations(this.textSlot),this.editor.groups.options(),this.editor.option({name:i("block:text","Prefill"),form:{title:i("block:text","Prefill"),controls:[new r.Text("singleline",r.Text.bind(this,"prefill",void 0)).label(i("block:text","Prefill with the following text:"))]},activated:p(this.prefill)}),this.editor.required(this.textSlot),this.editor.visibility(),this.editor.scores({target:this,collection:o,description:i("block:text","Generates a score based on the selected suggestion. Open the settings panel for each suggestion to set the score.")}),this.editor.alias(this.textSlot),this.editor.exportable(this.textSlot)}defineCondition(){I([{mode:"exact",label:i("block:text","Text matches")},{mode:"not-exact",label:i("block:text","Text does not match")},{mode:"contains",label:i("block:text","Text contains")},{mode:"not-contains",label:i("block:text","Text does not contain")},{mode:"starts",label:i("block:text","Text starts with")},{mode:"ends",label:i("block:text","Text ends with")},{mode:"defined",label:i("block:text","Text is not empty")},{mode:"undefined",label:i("block:text","Text is empty")}],(e=>{this.conditions.template({condition:y,label:e.label,autoOpen:"defined"!==e.mode&&"undefined"!==e.mode,props:{slot:this.textSlot,mode:e.mode}})}));const e=this.slots.select("score","feature");if(e&&e.label){const t=this.conditions.group(e.label,L,!1,!0);I([{mode:"equal",label:i("block:text","Score is equal to")},{mode:"not-equal",label:i("block:text","Score is not equal to")},{mode:"below",label:i("block:text","Score is lower than")},{mode:"above",label:i("block:text","Score is higher than")},{mode:"between",label:i("block:text","Score is between")},{mode:"not-between",label:i("block:text","Score is not between")},{mode:"defined",label:i("block:text","Score is calculated")},{mode:"undefined",label:i("block:text","Score is not calculated")}],(o=>{t.template({condition:C,label:o.label,autoOpen:"defined"!==o.mode&&"undefined"!==o.mode,props:{slot:e,mode:o.mode,value:0,to:"between"===o.mode||"not-between"===o.mode?0:void 0}})}))}}};N([e],T.prototype,"autoComplete",void 0),N([e,t("#label")],T.prototype,"useSuggestions",void 0),N([e("items"),t("#label"),k("#slot","value",!1,"useSuggestions")],T.prototype,"suggestions",void 0),N([e("string","optional")],T.prototype,"prefill",void 0),N([e("number","optional")],T.prototype,"minLength",void 0),N([M],T.prototype,"defineSlot",null),N([l],T.prototype,"defineEditor",null),N([A],T.prototype,"defineCondition",null),T=N([o({type:"node",legacyBlock:!0,identifier:"@tripetto/block-text",version:"6.0.2",icon:"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbDpzcGFjZT0icHJlc2VydmUiIHdpZHRoPSI1ODAiIGhlaWdodD0iNTgwIiBzaGFwZS1yZW5kZXJpbmc9Imdlb21ldHJpY1ByZWNpc2lvbiIgdGV4dC1yZW5kZXJpbmc9Imdlb21ldHJpY1ByZWNpc2lvbiIgaW1hZ2UtcmVuZGVyaW5nPSJvcHRpbWl6ZVF1YWxpdHkiIHZpZXdCb3g9IjAgMCA1ODAwIDU4MDAiPjxwYXRoIGNsYXNzPSJ0cmlwZXR0by1maWxsIiBkPSJNNTAwIDMzMDBoMjAwVjIzMDBINTAwdi0yMDBoNjAwdjIwMEg5MDB2MTAwMGgyMDB2MjAwSDUwMHYtMjAwem01MjAwLTE2MDB2MjIwMEgxMDBWMTcwMGg1NjAwem0tMjAwIDIwMEgzMDB2MTgwMGg1MjAwVjE5MDB6Ii8+PC9zdmc+",get label(){return i("block:text","Text (single line)")}})],T);export{T as Text};