@tripetto/block-email
Version:
Email block for Tripetto.
3 lines (2 loc) • 6.24 kB
JavaScript
/*! Tripetto Email Block 6.0.3 - Copyright (C) 2023 Tripetto B.V. - All Rights Reserved */
import{definition as e,affects as i,tripetto as t,pgettext as l,editor as a,ConditionBlock as o,Slots as d,isVariable as s,lookupVariable as n,makeMarkdownSafe as r,Forms as m,populateVariables as c,insertVariable as b,slots as h,conditions as u,NodeBlock as M,each as A}from"@tripetto/builder";function j(e,i,t,l){var a,o=arguments.length,d=o<3?i:null===l?l=Object.getOwnPropertyDescriptor(i,t):l;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)d=Reflect.decorate(e,i,t,l);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(d=(o<3?a(d):o>3?a(i,t,d):a(i,t))||d);return o>3&&d&&Object.defineProperty(i,t,d),d}var g="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCI+PHBhdGggZD0iTTE3LjA3MSAyLjkyOUMxNS4xODIgMS4wNCAxMi42NzEgMCAxMCAwUzQuODE4IDEuMDQgMi45MjkgMi45MjlDMS4wNCA0LjgxOCAwIDcuMzI5IDAgMTBzMS4wNCA1LjE4MiAyLjkyOSA3LjA3MUE5LjkzNCA5LjkzNCAwIDAgMCAxMCAyMGE5Ljg5NCA5Ljg5NCAwIDAgMCA0LjQ2NS0xLjA1IDEwLjA4MyAxMC4wODMgMCAwIDAgMy40My0yLjgxMi41LjUgMCAxIDAtLjc4OS0uNjE1QTguOTUgOC45NSAwIDAgMSAxMCAxOC45OTljLTQuOTYzIDAtOS00LjAzNy05LTlzNC4wMzctOSA5LTkgOSA0LjAzNyA5IDljMCAxLjc2Ni0xLjAyOCAzLTIuNSAzYTIuNTAzIDIuNTAzIDAgMCAxLTIuNS0yLjV2LTRhLjUuNSAwIDAgMC0xIDB2Ljg1N2EzLjk5IDMuOTkgMCAwIDAtMy0xLjM1N2MtMi4yMDYgMC00IDEuNzk0LTQgNHMxLjc5NCA0IDQgNGMxLjQzIDAgMi42ODctLjc1NSAzLjM5NS0xLjg4N2EzLjUwNCAzLjUwNCAwIDAgMCAzLjEwNSAxLjg4N2MuOTY4IDAgMS44NTMtLjM5MyAyLjQ5NC0xLjEwNy42NTgtLjczNCAxLjAwNi0xLjczNCAxLjAwNi0yLjg5M2E5LjkzNCA5LjkzNCAwIDAgMC0yLjkyOS03LjA3MXpNMTAgMTNjLTEuNjU0IDAtMy0xLjM0Ni0zLTNzMS4zNDYtMyAzLTMgMyAxLjM0NiAzIDMtMS4zNDYgMy0zIDN6IiBjbGFzcz0idHJpcGV0dG8tZmlsbCIvPjwvc3ZnPg==";let L=class extends o{constructor(){super(...arguments),this.allowMarkdown=!0,this.mode="address"}get label(){return""}get name(){var e;if(this.slot instanceof d.String){const i=e=>e&&("domain"===this.mode||"not-domain"===this.mode)&&`_@${e}_`||e,t=(s(this.match)?(null===(e=n(this,this.match))||void 0===e?void 0:e.label)&&`@${this.match}`:this.match&&i(r(this.match)))||"\\_\\_";switch(this.mode){case"domain":return`@${this.slot.id} ${l("block:email","from domain")} ${t}`;case"not-domain":return`@${this.slot.id} ${l("block:email","not from domain")} ${t}`;case"address":return`@${this.slot.id} = ${t}`;case"not-address":return`@${this.slot.id} ≠ ${t}`;case"defined":return`@${this.slot.id} ${l("block:email","not empty")}`;case"undefined":return`@${this.slot.id} ${l("block:email","empty")}`}}return this.type.label}get title(){var e;return null===(e=this.node)||void 0===e?void 0:e.label}defineEditor(){var e;this.editor.form({title:l("block:email","Compare mode"),controls:[new m.Radiobutton([{label:l("block:email","Email address matches"),value:"address"},{label:l("block:email","Email address does not match"),value:"not-address"},{label:l("block:email","Email address matches domain"),value:"domain"},{label:l("block:email","Email address does not match domain"),value:"not-domain"},{label:l("block:email","Email address is not empty"),value:"defined"},{label:l("block:email","Email address is empty"),value:"undefined"}],m.Radiobutton.bind(this,"mode","address")).on((e=>{switch(n.visible("defined"!==e.value&&"undefined"!==e.value),e.value){case"address":n.title=l("block:email","If email address matches");break;case"not-address":n.title=l("block:email","If email address does not match");break;case"domain":n.title=l("block:email","If email address matches domain");break;case"not-domain":n.title=l("block:email","If email address does not match domain")}a.isInteractable&&a.focus()}))]});const i=this.match&&s(this.match)||!1,t=c(this,(e=>e instanceof d.String||e instanceof d.Text),i?this.match:void 0,!1,null===(e=this.slot)||void 0===e?void 0:e.id),a=new m.Text("singleline",i?"":this.match).label(l("block:email","Use fixed text")).action("@",b(this,"exclude")).autoFocus().enter(this.editor.close).escape(this.editor.close).on((e=>{e.isFormVisible&&e.isObservable&&(this.match=e.value)})),o=new m.Dropdown(t,i?this.match:"").label(l("block:email","Use value of")).width("full").on((e=>{e.isFormVisible&&e.isObservable&&(this.match=e.value||void 0)})),n=this.editor.form({title:l("block:email","If email address matches"),controls:[new m.Radiobutton([{label:l("block:email","Text"),value:"text"},{label:l("block:email","Value"),value:"variable",disabled:0===t.length}],i?"variable":"text").on((e=>{a.visible("text"===e.value),o.visible("variable"===e.value),a.isInteractable&&a.focus()})),a,o]}).visible("defined"!==this.mode&&"undefined"!==this.mode)}};var N;j([e,i("#name")],L.prototype,"mode",void 0),j([e,i("#name")],L.prototype,"match",void 0),j([a],L.prototype,"defineEditor",null),L=j([t({type:"condition",legacyBlock:!0,context:"@tripetto/block-email",identifier:"@tripetto/block-email",version:"6.0.3",icon:g,get label(){return l("block:email","Match email address")}})],L);let y=N=class extends M{defineSlot(){this.emailSlot=this.slots.static({type:d.String,reference:"email",label:N.label,exchange:["required","alias","exportable"]})}defineEditor(){this.editor.name(),this.editor.description(),this.editor.placeholder(),this.editor.explanation(),this.editor.groups.options(),this.editor.required(this.emailSlot),this.editor.visibility(),this.editor.alias(this.emailSlot),this.editor.exportable(this.emailSlot)}defineCondition(){A([{mode:"address",label:l("block:email","Email address match")},{mode:"not-address",label:l("block:email","Email address mismatch")},{mode:"domain",label:l("block:email","Email address on domain")},{mode:"not-domain",label:l("block:email","Email address not on domain")},{mode:"defined",label:l("block:email","Email address is not empty")},{mode:"undefined",label:l("block:email","Email address is empty")}],(e=>{this.conditions.template({condition:L,label:e.label,autoOpen:"defined"!==e.mode&&"undefined"!==e.mode,props:{slot:this.emailSlot,mode:e.mode}})}))}};j([h],y.prototype,"defineSlot",null),j([a],y.prototype,"defineEditor",null),j([u],y.prototype,"defineCondition",null),y=N=j([t({type:"node",legacyBlock:!0,identifier:"@tripetto/block-email",version:"6.0.3",icon:g,get label(){return l("block:email","Email address")}})],y);export{y as Email};