@bikdotai/bik-component-library 0.0.654-beta-ctv.3 → 0.0.654-beta-ctv.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/template-preview/WhatsAppTemplatePreview.js +1 -1
- package/dist/cjs/components/template-preview/helpers/TemplateCreatorHelper.d.ts +1 -0
- package/dist/cjs/components/template-preview/helpers/TemplateCreatorHelper.js +1 -1
- package/dist/esm/components/template-preview/WhatsAppTemplatePreview.js +1 -1
- package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.d.ts +1 -0
- package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),l=require("react"),a=require("../template-context-mapper/context/templateModalContext.js"),t=require("./helpers/TemplateCreatorHelper.js"),i=require("./helpers/templateMiscHelper.js"),r=require("./models/TemplateMeta.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),l=require("react"),a=require("../template-context-mapper/context/templateModalContext.js"),t=require("./helpers/TemplateCreatorHelper.js"),i=require("./helpers/templateMiscHelper.js"),r=require("./models/TemplateMeta.js"),o=require("./RCS/RCSTemplateLikePreview.js"),n=require("./utils/TemplateHelperUtils.js"),d=require("./WhatsApp/WhatsAppLikePreview.js"),s=require("./WhatsApp/WhatsAppLikePreviewV2.js");exports.default=u=>{let{template:p,extras:v,containerStyle:h,usePlaceHolderName:m,showHeader:x,zeroStateComponent:c,size:b,showSampleValues:T,carouselCardIndex:y,isWhatsappCarousel:w,isPreview:C,channel:N}=u;var V,k,P,j,S,f,L,B,A,g,q,E,F,H,R,O,W,I,M,D,U,z,_,Y,G,J,K,Q,X,Z;const{selectedCarouselIndex:$,pod:ee}=a.useTemplateModalContext(),[le,ae]=l.useState(),te=new t.TemplateCreatorHelper,ie=new n.TemplateHelperUtils,re=[];if((null===(k=null===(V=null==le?void 0:le.ctaBtn)||void 0===V?void 0:V.phoneNumber)||void 0===k?void 0:k.isChecked)&&re.push({type:"phoneNumber",text:null!==(P=le.ctaBtn.phoneNumber.btnText)&&void 0!==P?P:"",extra:null!==(j=le.ctaBtn.phoneNumber.phoneNumber)&&void 0!==j?j:""}),(null===(f=null===(S=null==le?void 0:le.ctaBtn)||void 0===S?void 0:S.websiteLinkBtn)||void 0===f?void 0:f.isChecked)&&re.push({type:"website",text:null!==(L=le.ctaBtn.websiteLinkBtn.btnText)&&void 0!==L?L:"",extra:null!==(A=null===(B=le.ctaBtn.websiteLinkBtn)||void 0===B?void 0:B.linkOpens)&&void 0!==A?A:"",placeholder:null!==(g=le.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==g?g:""}),l.useEffect((()=>{p&&te.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl,pod:ee}).then((e=>{ae(Object.assign({},e))}))}),[p,T]),l.useEffect((()=>{p&&te.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl,pod:ee}).then((e=>{ae(Object.assign({},e))}))}),[$]),!p)return e.jsx(e.Fragment,{children:c});if(i.isRCSChannel(N||(null==p?void 0:p.channel))){const l=te.parseTemplateConfiguration(p);return e.jsx(o.RCSTemplateLikePreview,{showHeader:x,containerPadding:"large"===b?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:h,textType:"html",bodyText:null==le?void 0:le.bodyText,titleText:null==le?void 0:le.titleText,footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:null==le?void 0:le.headerText,headerAssetLink:null!==(q=null==le?void 0:le.headerAssetLink)&&void 0!==q?q:"",headerAssetName:null!==(E=null==le?void 0:le.headerAssetName)&&void 0!==E?E:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(H=null===(F=null==le?void 0:le.bodyVariables)||void 0===F?void 0:F.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==H?H:[],headerVariableList:null!==(O=null===(R=null==le?void 0:le.headerVariables)||void 0===R?void 0:R.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==O?O:[],titleVariableList:null!==(I=null===(W=null==le?void 0:le.titleVariables)||void 0===W?void 0:W.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==I?I:[],buttons:null==le?void 0:le.allButtons,isWhatsappCarousel:w,isPreview:C,templateConfiguration:l})}return p.htmlContentUrl?e.jsx(d.WhatsappLikePreview,{showHeader:x,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:ie.whatsappOnlyFillVariablesValueInBodyText(null!==(G=null==le?void 0:le.bodyText)&&void 0!==G?G:"",null!==(J=null==le?void 0:le.bodyVariables)&&void 0!==J?J:[],m),footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:ie.fillVariablesValInBodyText(null!==(K=null==le?void 0:le.headerText)&&void 0!==K?K:"",null!==(Q=null==le?void 0:le.headerVariables)&&void 0!==Q?Q:[],m),headerAssetLink:null!==(X=null==le?void 0:le.headerAssetLink)&&void 0!==X?X:"",headerAssetName:null!==(Z=null==le?void 0:le.headerAssetName)&&void 0!==Z?Z:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=c?c:e.jsx(e.Fragment,{children:" "}),isPreview:C}):e.jsx(s.WhatsappLikePreviewV2,{showHeader:x,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:null==le?void 0:le.bodyText,footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:null==le?void 0:le.headerText,headerAssetLink:null!==(M=null==le?void 0:le.headerAssetLink)&&void 0!==M?M:"",headerAssetName:null!==(D=null==le?void 0:le.headerAssetName)&&void 0!==D?D:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(z=null===(U=null==le?void 0:le.bodyVariables)||void 0===U?void 0:U.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==z?z:[],headerVariableList:null!==(Y=null===(_=null==le?void 0:le.headerVariables)||void 0===_?void 0:_.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==Y?Y:[],buttons:null==le?void 0:le.allButtons,limitedTimeOfferComponent:null==le?void 0:le.limitedTimeOfferComponent,isWhatsappCarousel:w,isPreview:C})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("date-fns"),i=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),l=require("../constants/TemplateConstants.js"),o=require("../models/TemplateMeta.js"),a=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e,t){var i,n,l,a,d,r,s,v,u,p;const E={headerType:o.HEADER_TYPES.NONE,headerVariables:[]},T=null===(i=null==e?void 0:e.components)||void 0===i?void 0:i.find((e=>"HEADER"===e.type));if(T){E.headerType=T.format,E.headerText=T.text,E.headerAssetLink=null===(l=null===(n=T.example)||void 0===n?void 0:n.header_handle)||void 0===l?void 0:l[0];const i=null===(d=null===(a=T.example)||void 0===a?void 0:a.header_text)||void 0===d?void 0:d[0],o=null===(s=null===(r=e.mapping)||void 0===r?void 0:r.header)||void 0===s?void 0:s[0],c=o;if(i&&o){const e=null==o?void 0:o.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),n=/\(\(/.test(o),l={idx:0,variableVal:t?i:c,editable:n,editableDefaultValues:n?void 0:i,variableName:e};E.headerVariables=[l],(null===(u=null===(v=T.example)||void 0===v?void 0:v.header_text)||void 0===u?void 0:u.length)&&(E.headerText=null===(p=E.headerText)||void 0===p?void 0:p.replace("{{1}}",`{{${e}}}`))}}return E}validateState(e){var t,i,d,r,s,v,u,p,E,T,c,m,_,h,b,R,y,I,L,N,C,x,O;const B=/\p{Extended_Pictographic}/u;let f="valid";const D={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},A=new a.TemplateHelperUtils;let P=!1;const S=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>l.NAME_LEN_LIMIT?(D.meta.name=l.NAME_LEN_ERROR,f="invalid"):n.specialCharPattern.test(null===(d=e.meta.name)||void 0===d?void 0:d.trim())&&(D.meta.name=l.NO_SPECIAL_CHAR,f="invalid"):(D.meta.name=l.REQUIRED_FIELD,f="invalid"),D.meta.name&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.name),P=!0),e.headerType===o.HEADER_TYPES.TEXT){const t=null!==(s=null===(r=e.headerText)||void 0===r?void 0:r.trim())&&void 0!==s?s:"";if(t)if(t.length>l.HEADER_TEXT_LEN_LIMIT)D.header=l.HEADER_LEN_ERROR,f="invalid";else{const e=A.getTemplateVariablesFromState(t);e&&e.length>1&&(D.header=l.ONE_VAR_ALLOWED,f="invalid")}else D.header=l.REQUIRED_FIELD,f="invalid"}else e.headerType===o.HEADER_TYPES.DOCUMENT||e.headerType===o.HEADER_TYPES.IMAGE||(e.headerType,o.HEADER_TYPES.VIDEO);if(e.headerType!==o.HEADER_TYPES.DOCUMENT&&e.headerType!==o.HEADER_TYPES.IMAGE&&e.headerType!==o.HEADER_TYPES.VIDEO||e.headerAssetLink||(D.header=l.HEADER_ASSET_LINK_ERROR,f="invalid"),D.header&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.header),P=!0),e.bodyText?e.bodyTextRaw&&(null===(v=e.bodyTextRaw)||void 0===v?void 0:v.trim().length)>l.BODY_TEXT_LEN_LIMIT&&(D.body=l.BODY_LEN_ERROR,f="invalid"):(D.body=l.REQUIRED_FIELD,f="invalid"),D.body&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.body),P=!0),e.footerText&&e.footerText.length>l.HEADER_TEXT_LEN_LIMIT&&(D.footer=l.HEADER_LEN_ERROR,f="invalid"),(null==D?void 0:D.footer)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.footer),P=!0),e.actionsType===o.ACTIONS_TYPES.CTA_BTN){if(null===(p=null===(u=e.ctaBtn)||void 0===u?void 0:u.phoneNumber)||void 0===p?void 0:p.isChecked){const t=null===(E=e.ctaBtn.phoneNumber.btnText)||void 0===E?void 0:E.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;D.ctaBtn&&!t?(D.ctaBtn.phoneNumber.btnText=l.REQUIRED_FIELD,f="invalid"):D.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(D.ctaBtn.phoneNumber.btnText=l.QUICK_REPLY_LEN_ERROR,f="invalid"):D.ctaBtn&&t&&B.test(t)&&(D.ctaBtn.phoneNumber.btnText=l.BUTTON_EMOJI_ERROR,f="invalid"),D.ctaBtn&&!i?(D.ctaBtn.phoneNumber.link=l.REQUIRED_FIELD,f="invalid"):D.ctaBtn&&i&&i.length<10&&(D.ctaBtn.phoneNumber.link=l.VALID_PHONE_NUMBER,f="invalid")}if(null===(c=null===(T=e.ctaBtn)||void 0===T?void 0:T.websiteLinkBtn)||void 0===c?void 0:c.isChecked){const t=null===(m=e.ctaBtn.websiteLinkBtn.btnText)||void 0===m?void 0:m.trim(),i=null===(_=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===_?void 0:_.trim(),n=null===(h=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===h?void 0:h.trim();D.ctaBtn&&!t?(D.ctaBtn.websiteLink.btnText=l.REQUIRED_FIELD,f="invalid"):D.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(D.ctaBtn.websiteLink.btnText=l.QUICK_REPLY_LEN_ERROR,f="invalid"):D.ctaBtn&&t&&B.test(t)&&(D.ctaBtn.websiteLink.btnText=l.BUTTON_EMOJI_ERROR,f="invalid"),!D.ctaBtn||i||n||(D.ctaBtn.websiteLink.link=l.REQUIRED_FIELD,f="invalid")}}else if(e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var o;const a=null===(o=i.text)||void 0===o?void 0:o.trim();if(a)if(a.length>l.QUICK_REPLY_NAME_LEN_LIMIT)t[n]=l.QUICK_REPLY_LEN_ERROR,f="invalid";else if(B.test(a))t[n]=l.BUTTON_EMOJI_ERROR,f="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===a))&&(t[n]=l.QUICK_REPLY_NAME_ERROR,f="invalid")}else t[n]=l.REQUIRED_FIELD,f="invalid"})),D.quickReply=t}if(e.actionsType===o.ACTIONS_TYPES.CTA_BTN||e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const e=null===(b=D.quickReply)||void 0===b?void 0:b.reduce(((e,t)=>e||!!t),!1);((null===(y=null===(R=null==D?void 0:D.ctaBtn)||void 0===R?void 0:R.websiteLink)||void 0===y?void 0:y.link)||(null===(L=null===(I=D.ctaBtn)||void 0===I?void 0:I.websiteLink)||void 0===L?void 0:L.btnText)||(null===(C=null===(N=D.ctaBtn)||void 0===N?void 0:N.phoneNumber)||void 0===C?void 0:C.link)||(null===(O=null===(x=D.ctaBtn)||void 0===x?void 0:x.phoneNumber)||void 0===O?void 0:O.btnText)||e)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.actionButtons),P=!0)}return{status:f,errors:D}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const u=[];let p="";const E=null===(o=e.components)||void 0===o?void 0:o.find((e=>"BODY"===e.type));return E&&(null===(r=null===(d=null===(a=E.example)||void 0===a?void 0:a.body_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(n.placeHolderNamePattern);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),u.push({idx:i,variableVal:l?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),p=e.htmlContentUrl?e.htmlContentUrl:(null===(s=E.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=E.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:u,bodyText:p}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const u=[];let p="";const E=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return E&&(null===(r=null===(d=null===(a=E.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(n.placeHolderNamePattern);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),u.push({idx:i,variableVal:l?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),p=e.htmlContentUrl?e.htmlContentUrl:(null===(s=E.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=E.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:p,titleVariables:u}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,l,a,d,r,s;const v={actionsType:o.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},u=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(u&&(null===(i=null==u?void 0:u.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(l=null==u?void 0:u.buttons)||void 0===l?void 0:l[0].type)?o.ACTIONS_TYPES.QUICK_REPLY:o.ACTIONS_TYPES.CTA_BTN;if(v.actionsType=t,t===o.ACTIONS_TYPES.QUICK_REPLY){const e=null!==(d=null===(a=null==u?void 0:u.buttons)||void 0===a?void 0:a.map((e=>e)))&&void 0!==d?d:[];v.quickReply=e}else t===o.ACTIONS_TYPES.CTA_BTN&&(null===(r=null==u?void 0:u.buttons)||void 0===r||r.forEach((t=>{var i,l,o,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(o=null===(l=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===l?void 0:l[0])&&void 0!==o?o:void 0;let r=!1;d&&n.editableVarPattern.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));v.allButtons=null===(s=u.buttons)||void 0===s?void 0:s.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return v}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t.format(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e.__awaiter(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o}=t,{headerType:a,headerAssetLink:d,headerAssetName:r,headerText:s,headerVariables:v}=yield this.parseDataFromHeaderComponent(e),{bodyText:u,bodyVariable:p}=yield this.parseBodyComponent(e,l,o),{titleText:E,titleVariables:T}=yield this.parseTitleComponent(e,l,o),{actionsType:c,quickReply:m,ctaBtn:_,allButtons:h}=yield this.parseButtonComponent(e),b=this.parseLimitedTimeOfferComponent(e,h),R={quickReply:m,ctaBtn:_,allButtons:h,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:c,footerText:this.parseFooterComponent(e),bodyVariables:p,bodyText:u,headerType:a,headerAssetLink:d,headerAssetName:r,headerText:s,headerVariables:v,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:b,titleText:E,titleVariables:T},{errors:y}=this.validateState(R);return R.error=y,R}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("date-fns"),i=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),l=require("../constants/TemplateConstants.js"),o=require("../models/TemplateMeta.js"),a=require("../models/WhatsAppTemplate.js"),d=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e,t,i){var n,l,d,r,s,v,u,p,E,T;const c={headerType:o.HEADER_TYPES.NONE,headerVariables:[]},m=null===(n=null==e?void 0:e.components)||void 0===n?void 0:n.find((e=>"HEADER"===e.type));if(m){c.headerType=m.format,c.headerText=m.text,c.headerAssetLink=null===(d=null===(l=m.example)||void 0===l?void 0:l.header_handle)||void 0===d?void 0:d[0];const n=null===(s=null===(r=m.example)||void 0===r?void 0:r.header_text)||void 0===s?void 0:s[0],o=null===(u=null===(v=e.mapping)||void 0===v?void 0:v.header)||void 0===u?void 0:u[0],_=o;if(o){const e=null==o?void 0:o.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),l=/\(\(/.test(o),d=i===a.POD.CHATBOT&&_&&(null==_?void 0:_.startsWith("(("))&&(null==_?void 0:_.endsWith("))")),r={idx:0,variableVal:t||d?n:_,editable:l,editableDefaultValues:l?void 0:n,variableName:e};c.headerVariables=[r],(null===(E=null===(p=m.example)||void 0===p?void 0:p.header_text)||void 0===E?void 0:E.length)&&(c.headerText=null===(T=c.headerText)||void 0===T?void 0:T.replace("{{1}}",`{{${e}}}`))}}return c}validateState(e){var t,i,a,r,s,v,u,p,E,T,c,m,_,h,b,R,y,I,L,C,N,O,B;const x=/\p{Extended_Pictographic}/u;let D="valid";const f={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},A=new d.TemplateHelperUtils;let P=!1;const S=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>l.NAME_LEN_LIMIT?(f.meta.name=l.NAME_LEN_ERROR,D="invalid"):n.specialCharPattern.test(null===(a=e.meta.name)||void 0===a?void 0:a.trim())&&(f.meta.name=l.NO_SPECIAL_CHAR,D="invalid"):(f.meta.name=l.REQUIRED_FIELD,D="invalid"),f.meta.name&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.name),P=!0),e.headerType===o.HEADER_TYPES.TEXT){const t=null!==(s=null===(r=e.headerText)||void 0===r?void 0:r.trim())&&void 0!==s?s:"";if(t)if(t.length>l.HEADER_TEXT_LEN_LIMIT)f.header=l.HEADER_LEN_ERROR,D="invalid";else{const e=A.getTemplateVariablesFromState(t);e&&e.length>1&&(f.header=l.ONE_VAR_ALLOWED,D="invalid")}else f.header=l.REQUIRED_FIELD,D="invalid"}else e.headerType===o.HEADER_TYPES.DOCUMENT||e.headerType===o.HEADER_TYPES.IMAGE||(e.headerType,o.HEADER_TYPES.VIDEO);if(e.headerType!==o.HEADER_TYPES.DOCUMENT&&e.headerType!==o.HEADER_TYPES.IMAGE&&e.headerType!==o.HEADER_TYPES.VIDEO||e.headerAssetLink||(f.header=l.HEADER_ASSET_LINK_ERROR,D="invalid"),f.header&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.header),P=!0),e.bodyText?e.bodyTextRaw&&(null===(v=e.bodyTextRaw)||void 0===v?void 0:v.trim().length)>l.BODY_TEXT_LEN_LIMIT&&(f.body=l.BODY_LEN_ERROR,D="invalid"):(f.body=l.REQUIRED_FIELD,D="invalid"),f.body&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.body),P=!0),e.footerText&&e.footerText.length>l.HEADER_TEXT_LEN_LIMIT&&(f.footer=l.HEADER_LEN_ERROR,D="invalid"),(null==f?void 0:f.footer)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.footer),P=!0),e.actionsType===o.ACTIONS_TYPES.CTA_BTN){if(null===(p=null===(u=e.ctaBtn)||void 0===u?void 0:u.phoneNumber)||void 0===p?void 0:p.isChecked){const t=null===(E=e.ctaBtn.phoneNumber.btnText)||void 0===E?void 0:E.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;f.ctaBtn&&!t?(f.ctaBtn.phoneNumber.btnText=l.REQUIRED_FIELD,D="invalid"):f.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(f.ctaBtn.phoneNumber.btnText=l.QUICK_REPLY_LEN_ERROR,D="invalid"):f.ctaBtn&&t&&x.test(t)&&(f.ctaBtn.phoneNumber.btnText=l.BUTTON_EMOJI_ERROR,D="invalid"),f.ctaBtn&&!i?(f.ctaBtn.phoneNumber.link=l.REQUIRED_FIELD,D="invalid"):f.ctaBtn&&i&&i.length<10&&(f.ctaBtn.phoneNumber.link=l.VALID_PHONE_NUMBER,D="invalid")}if(null===(c=null===(T=e.ctaBtn)||void 0===T?void 0:T.websiteLinkBtn)||void 0===c?void 0:c.isChecked){const t=null===(m=e.ctaBtn.websiteLinkBtn.btnText)||void 0===m?void 0:m.trim(),i=null===(_=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===_?void 0:_.trim(),n=null===(h=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===h?void 0:h.trim();f.ctaBtn&&!t?(f.ctaBtn.websiteLink.btnText=l.REQUIRED_FIELD,D="invalid"):f.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(f.ctaBtn.websiteLink.btnText=l.QUICK_REPLY_LEN_ERROR,D="invalid"):f.ctaBtn&&t&&x.test(t)&&(f.ctaBtn.websiteLink.btnText=l.BUTTON_EMOJI_ERROR,D="invalid"),!f.ctaBtn||i||n||(f.ctaBtn.websiteLink.link=l.REQUIRED_FIELD,D="invalid")}}else if(e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var o;const a=null===(o=i.text)||void 0===o?void 0:o.trim();if(a)if(a.length>l.QUICK_REPLY_NAME_LEN_LIMIT)t[n]=l.QUICK_REPLY_LEN_ERROR,D="invalid";else if(x.test(a))t[n]=l.BUTTON_EMOJI_ERROR,D="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===a))&&(t[n]=l.QUICK_REPLY_NAME_ERROR,D="invalid")}else t[n]=l.REQUIRED_FIELD,D="invalid"})),f.quickReply=t}if(e.actionsType===o.ACTIONS_TYPES.CTA_BTN||e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const e=null===(b=f.quickReply)||void 0===b?void 0:b.reduce(((e,t)=>e||!!t),!1);((null===(y=null===(R=null==f?void 0:f.ctaBtn)||void 0===R?void 0:R.websiteLink)||void 0===y?void 0:y.link)||(null===(L=null===(I=f.ctaBtn)||void 0===I?void 0:I.websiteLink)||void 0===L?void 0:L.btnText)||(null===(N=null===(C=f.ctaBtn)||void 0===C?void 0:C.phoneNumber)||void 0===N?void 0:N.link)||(null===(B=null===(O=f.ctaBtn)||void 0===O?void 0:O.phoneNumber)||void 0===B?void 0:B.btnText)||e)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.actionButtons),P=!0)}return{status:D,errors:f}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0;var d,r,s,v,u,p;const E=[];let T="";const c=null===(d=e.components)||void 0===d?void 0:d.find((e=>"BODY"===e.type));return c&&(null===(v=null===(s=null===(r=c.example)||void 0===r?void 0:r.body_text)||void 0===s?void 0:s[0])||void 0===v||v.forEach(((t,i)=>{var d,r;let s=null===(r=null===(d=e.mapping)||void 0===d?void 0:d.body)||void 0===r?void 0:r[i];const v=s,u=s&&/\(\(/.test(s),p=null==s?void 0:s.match(n.placeHolderNamePattern);(null==p?void 0:p[2])&&(s=null==p?void 0:p[2]);const T=o===a.POD.CHATBOT&&v&&(null==v?void 0:v.startsWith("(("))&&(null==v?void 0:v.endsWith("))"));E.push({idx:i,variableVal:l||T?t:v,editable:!!u,editableDefaultValues:u?void 0:t,variableName:null!=s?s:""})})),T=e.htmlContentUrl?e.htmlContentUrl:(null===(u=c.text)||void 0===u?void 0:u.split(/\{\{[0-9]+\}\}/).length)?null===(p=c.text)||void 0===p?void 0:p.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==E?void 0:E[n]){const l=E[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:E,bodyText:T}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const u=[];let p="";const E=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return E&&(null===(r=null===(d=null===(a=E.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(n.placeHolderNamePattern);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),u.push({idx:i,variableVal:l?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),p=e.htmlContentUrl?e.htmlContentUrl:(null===(s=E.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=E.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:p,titleVariables:u}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,l,a,d,r,s;const v={actionsType:o.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},u=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(u&&(null===(i=null==u?void 0:u.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(l=null==u?void 0:u.buttons)||void 0===l?void 0:l[0].type)?o.ACTIONS_TYPES.QUICK_REPLY:o.ACTIONS_TYPES.CTA_BTN;if(v.actionsType=t,t===o.ACTIONS_TYPES.QUICK_REPLY){const e=null!==(d=null===(a=null==u?void 0:u.buttons)||void 0===a?void 0:a.map((e=>e)))&&void 0!==d?d:[];v.quickReply=e}else t===o.ACTIONS_TYPES.CTA_BTN&&(null===(r=null==u?void 0:u.buttons)||void 0===r||r.forEach((t=>{var i,l,o,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(o=null===(l=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===l?void 0:l[0])&&void 0!==o?o:void 0;let r=!1;d&&n.editableVarPattern.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));v.allButtons=null===(s=u.buttons)||void 0===s?void 0:s.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return v}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t.format(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e.__awaiter(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o,pod:a}=t,{headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:u}=yield this.parseDataFromHeaderComponent(e,void 0,a),{bodyText:p,bodyVariable:E}=yield this.parseBodyComponent(e,l,o,a),{titleText:T,titleVariables:c}=yield this.parseTitleComponent(e,l,o),{actionsType:m,quickReply:_,ctaBtn:h,allButtons:b}=yield this.parseButtonComponent(e),R=this.parseLimitedTimeOfferComponent(e,b),y={quickReply:_,ctaBtn:h,allButtons:b,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:m,footerText:this.parseFooterComponent(e),bodyVariables:E,bodyText:p,headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:u,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:R,titleText:T,titleVariables:c},{errors:I}=this.validateState(y);return y.error=I,y}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,Fragment as l}from"react/jsx-runtime";import{useState as a,useEffect as t}from"react";import{useTemplateModalContext as i}from"../template-context-mapper/context/templateModalContext.js";import{TemplateCreatorHelper as o}from"./helpers/TemplateCreatorHelper.js";import{isRCSChannel as r}from"./helpers/templateMiscHelper.js";import{HEADER_TYPES as n}from"./models/TemplateMeta.js";import{RCSTemplateLikePreview as d}from"./RCS/RCSTemplateLikePreview.js";import{TemplateHelperUtils as
|
|
1
|
+
import{jsx as e,Fragment as l}from"react/jsx-runtime";import{useState as a,useEffect as t}from"react";import{useTemplateModalContext as i}from"../template-context-mapper/context/templateModalContext.js";import{TemplateCreatorHelper as o}from"./helpers/TemplateCreatorHelper.js";import{isRCSChannel as r}from"./helpers/templateMiscHelper.js";import{HEADER_TYPES as n}from"./models/TemplateMeta.js";import{RCSTemplateLikePreview as d}from"./RCS/RCSTemplateLikePreview.js";import{TemplateHelperUtils as p}from"./utils/TemplateHelperUtils.js";import{WhatsappLikePreview as s}from"./WhatsApp/WhatsAppLikePreview.js";import{WhatsappLikePreviewV2 as u}from"./WhatsApp/WhatsAppLikePreviewV2.js";const v=v=>{let{template:m,extras:h,containerStyle:x,usePlaceHolderName:c,showHeader:b,zeroStateComponent:T,size:y,showSampleValues:w,carouselCardIndex:N,isWhatsappCarousel:V,isPreview:f,channel:C}=v;var k,B,L,P,A,S,j,g,F,O,H,I,R,W,q,M,U,z,D,E,G,J,K,Q,X,Y,Z,$,_,ee;const{selectedCarouselIndex:le,pod:ae}=i(),[te,ie]=a(),oe=new o,re=new p,ne=[];if((null===(B=null===(k=null==te?void 0:te.ctaBtn)||void 0===k?void 0:k.phoneNumber)||void 0===B?void 0:B.isChecked)&&ne.push({type:"phoneNumber",text:null!==(L=te.ctaBtn.phoneNumber.btnText)&&void 0!==L?L:"",extra:null!==(P=te.ctaBtn.phoneNumber.phoneNumber)&&void 0!==P?P:""}),(null===(S=null===(A=null==te?void 0:te.ctaBtn)||void 0===A?void 0:A.websiteLinkBtn)||void 0===S?void 0:S.isChecked)&&ne.push({type:"website",text:null!==(j=te.ctaBtn.websiteLinkBtn.btnText)&&void 0!==j?j:"",extra:null!==(F=null===(g=te.ctaBtn.websiteLinkBtn)||void 0===g?void 0:g.linkOpens)&&void 0!==F?F:"",placeholder:null!==(O=te.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==O?O:""}),t((()=>{m&&oe.parseUITemplateFromDBFormat({dbFormattedTemplate:m,isDuplicate:!1,showSampleValues:w,isV2:!m.htmlContentUrl,pod:ae}).then((e=>{ie(Object.assign({},e))}))}),[m,w]),t((()=>{m&&oe.parseUITemplateFromDBFormat({dbFormattedTemplate:m,isDuplicate:!1,showSampleValues:w,isV2:!m.htmlContentUrl,pod:ae}).then((e=>{ie(Object.assign({},e))}))}),[le]),!m)return e(l,{children:T});if(r(C||(null==m?void 0:m.channel))){const a=oe.parseTemplateConfiguration(m);return e(d,{showHeader:b,containerPadding:"large"===y?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:x,textType:"html",bodyText:null==te?void 0:te.bodyText,titleText:null==te?void 0:te.titleText,footerText:null==te?void 0:te.footerText,headerMediaType:(null==te?void 0:te.headerType)||n.NONE,headerText:null==te?void 0:te.headerText,headerAssetLink:null!==(H=null==te?void 0:te.headerAssetLink)&&void 0!==H?H:"",headerAssetName:null!==(I=null==te?void 0:te.headerAssetName)&&void 0!==I?I:"",quickReplybtn:null==te?void 0:te.quickReply,ctaBtn:ne,actionTypes:null==te?void 0:te.actionsType,extras:h,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:N,zeroStateComponent:null!=T?T:e(l,{children:" "}),bodyVariableList:null!==(W=null===(R=null==te?void 0:te.bodyVariables)||void 0===R?void 0:R.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==W?W:[],headerVariableList:null!==(M=null===(q=null==te?void 0:te.headerVariables)||void 0===q?void 0:q.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==M?M:[],titleVariableList:null!==(z=null===(U=null==te?void 0:te.titleVariables)||void 0===U?void 0:U.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==z?z:[],buttons:null==te?void 0:te.allButtons,isWhatsappCarousel:V,isPreview:f,templateConfiguration:a})}return m.htmlContentUrl?e(s,{showHeader:b,containerPadding:"large"===y?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:re.whatsappOnlyFillVariablesValueInBodyText(null!==(X=null==te?void 0:te.bodyText)&&void 0!==X?X:"",null!==(Y=null==te?void 0:te.bodyVariables)&&void 0!==Y?Y:[],c),footerText:null==te?void 0:te.footerText,headerMediaType:(null==te?void 0:te.headerType)||n.NONE,headerText:re.fillVariablesValInBodyText(null!==(Z=null==te?void 0:te.headerText)&&void 0!==Z?Z:"",null!==($=null==te?void 0:te.headerVariables)&&void 0!==$?$:[],c),headerAssetLink:null!==(_=null==te?void 0:te.headerAssetLink)&&void 0!==_?_:"",headerAssetName:null!==(ee=null==te?void 0:te.headerAssetName)&&void 0!==ee?ee:"",quickReplybtn:null==te?void 0:te.quickReply,ctaBtn:ne,actionTypes:null==te?void 0:te.actionsType,extras:h,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=T?T:e(l,{children:" "}),isPreview:f}):e(u,{showHeader:b,containerPadding:"large"===y?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:null==te?void 0:te.bodyText,footerText:null==te?void 0:te.footerText,headerMediaType:(null==te?void 0:te.headerType)||n.NONE,headerText:null==te?void 0:te.headerText,headerAssetLink:null!==(D=null==te?void 0:te.headerAssetLink)&&void 0!==D?D:"",headerAssetName:null!==(E=null==te?void 0:te.headerAssetName)&&void 0!==E?E:"",quickReplybtn:null==te?void 0:te.quickReply,ctaBtn:ne,actionTypes:null==te?void 0:te.actionsType,extras:h,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:N,zeroStateComponent:null!=T?T:e(l,{children:" "}),bodyVariableList:null!==(J=null===(G=null==te?void 0:te.bodyVariables)||void 0===G?void 0:G.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==J?J:[],headerVariableList:null!==(Q=null===(K=null==te?void 0:te.headerVariables)||void 0===K?void 0:K.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==Q?Q:[],buttons:null==te?void 0:te.allButtons,limitedTimeOfferComponent:null==te?void 0:te.limitedTimeOfferComponent,isWhatsappCarousel:V,isPreview:f})};export{v as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"../../../_virtual/_tslib.js";import{format as t}from"date-fns";import{COLORS as i}from"../../../constants/Theme.js";import{specialCharPattern as n,placeHolderNamePattern as l,editableVarPattern as o}from"../constants/regexPatterns.js";import{REQUIRED_FIELD as a,NAME_LEN_LIMIT as d,NAME_LEN_ERROR as r,NO_SPECIAL_CHAR as v,HEADER_TEXT_LEN_LIMIT as s,HEADER_LEN_ERROR as p,ONE_VAR_ALLOWED as u,HEADER_ASSET_LINK_ERROR as m,BODY_TEXT_LEN_LIMIT as c,BODY_LEN_ERROR as h,QUICK_REPLY_BTN_TEXT_LIMIT as b,QUICK_REPLY_LEN_ERROR as T,BUTTON_EMOJI_ERROR as y,VALID_PHONE_NUMBER as f,QUICK_REPLY_NAME_LEN_LIMIT as x,CREATE_TEMPLATE_DOM_IDS as B,QUICK_REPLY_NAME_ERROR as C}from"../constants/TemplateConstants.js";import{HEADER_TYPES as g,ACTIONS_TYPES as k}from"../models/TemplateMeta.js";import{TemplateHelperUtils as N}from"../utils/TemplateHelperUtils.js";class E{parseDataFromHeaderComponent(e,t){var i,n,l,o,a,d,r,v,s,p;const u={headerType:g.NONE,headerVariables:[]},m=null===(i=null==e?void 0:e.components)||void 0===i?void 0:i.find((e=>"HEADER"===e.type));if(m){u.headerType=m.format,u.headerText=m.text,u.headerAssetLink=null===(l=null===(n=m.example)||void 0===n?void 0:n.header_handle)||void 0===l?void 0:l[0];const i=null===(a=null===(o=m.example)||void 0===o?void 0:o.header_text)||void 0===a?void 0:a[0],c=null===(r=null===(d=e.mapping)||void 0===d?void 0:d.header)||void 0===r?void 0:r[0],h=c;if(i&&c){const e=null==c?void 0:c.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),n=/\(\(/.test(c),l={idx:0,variableVal:t?i:h,editable:n,editableDefaultValues:n?void 0:i,variableName:e};u.headerVariables=[l],(null===(s=null===(v=m.example)||void 0===v?void 0:v.header_text)||void 0===s?void 0:s.length)&&(u.headerText=null===(p=u.headerText)||void 0===p?void 0:p.replace("{{1}}",`{{${e}}}`))}}return u}validateState(e){var t,i,l,o,E,L,_,O,V,w,R,D,A,I,U,j,$,q,F,P,M,Y,S;const K=/\p{Extended_Pictographic}/u;let Q="valid";const H={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},G=new N;let J=!1;const W=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>d?(H.meta.name=r,Q="invalid"):n.test(null===(l=e.meta.name)||void 0===l?void 0:l.trim())&&(H.meta.name=v,Q="invalid"):(H.meta.name=a,Q="invalid"),H.meta.name&&!J&&(W(B.name),J=!0),e.headerType===g.TEXT){const t=null!==(E=null===(o=e.headerText)||void 0===o?void 0:o.trim())&&void 0!==E?E:"";if(t)if(t.length>s)H.header=p,Q="invalid";else{const e=G.getTemplateVariablesFromState(t);e&&e.length>1&&(H.header=u,Q="invalid")}else H.header=a,Q="invalid"}else e.headerType===g.DOCUMENT||e.headerType===g.IMAGE||(e.headerType,g.VIDEO);if(e.headerType!==g.DOCUMENT&&e.headerType!==g.IMAGE&&e.headerType!==g.VIDEO||e.headerAssetLink||(H.header=m,Q="invalid"),H.header&&!J&&(W(B.header),J=!0),e.bodyText?e.bodyTextRaw&&(null===(L=e.bodyTextRaw)||void 0===L?void 0:L.trim().length)>c&&(H.body=h,Q="invalid"):(H.body=a,Q="invalid"),H.body&&!J&&(W(B.body),J=!0),e.footerText&&e.footerText.length>s&&(H.footer=p,Q="invalid"),(null==H?void 0:H.footer)&&!J&&(W(B.footer),J=!0),e.actionsType===k.CTA_BTN){if(null===(O=null===(_=e.ctaBtn)||void 0===_?void 0:_.phoneNumber)||void 0===O?void 0:O.isChecked){const t=null===(V=e.ctaBtn.phoneNumber.btnText)||void 0===V?void 0:V.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;H.ctaBtn&&!t?(H.ctaBtn.phoneNumber.btnText=a,Q="invalid"):H.ctaBtn&&t&&t.length>b?(H.ctaBtn.phoneNumber.btnText=T,Q="invalid"):H.ctaBtn&&t&&K.test(t)&&(H.ctaBtn.phoneNumber.btnText=y,Q="invalid"),H.ctaBtn&&!i?(H.ctaBtn.phoneNumber.link=a,Q="invalid"):H.ctaBtn&&i&&i.length<10&&(H.ctaBtn.phoneNumber.link=f,Q="invalid")}if(null===(R=null===(w=e.ctaBtn)||void 0===w?void 0:w.websiteLinkBtn)||void 0===R?void 0:R.isChecked){const t=null===(D=e.ctaBtn.websiteLinkBtn.btnText)||void 0===D?void 0:D.trim(),i=null===(A=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===A?void 0:A.trim(),n=null===(I=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===I?void 0:I.trim();H.ctaBtn&&!t?(H.ctaBtn.websiteLink.btnText=a,Q="invalid"):H.ctaBtn&&t&&t.length>b?(H.ctaBtn.websiteLink.btnText=T,Q="invalid"):H.ctaBtn&&t&&K.test(t)&&(H.ctaBtn.websiteLink.btnText=y,Q="invalid"),!H.ctaBtn||i||n||(H.ctaBtn.websiteLink.link=a,Q="invalid")}}else if(e.actionsType===k.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var l;const o=null===(l=i.text)||void 0===l?void 0:l.trim();if(o)if(o.length>x)t[n]=T,Q="invalid";else if(K.test(o))t[n]=y,Q="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===o))&&(t[n]=C,Q="invalid")}else t[n]=a,Q="invalid"})),H.quickReply=t}if(e.actionsType===k.CTA_BTN||e.actionsType===k.QUICK_REPLY){const e=null===(U=H.quickReply)||void 0===U?void 0:U.reduce(((e,t)=>e||!!t),!1);((null===($=null===(j=null==H?void 0:H.ctaBtn)||void 0===j?void 0:j.websiteLink)||void 0===$?void 0:$.link)||(null===(F=null===(q=H.ctaBtn)||void 0===q?void 0:q.websiteLink)||void 0===F?void 0:F.btnText)||(null===(M=null===(P=H.ctaBtn)||void 0===P?void 0:P.phoneNumber)||void 0===M?void 0:M.link)||(null===(S=null===(Y=H.ctaBtn)||void 0===Y?void 0:Y.phoneNumber)||void 0===S?void 0:S.btnText)||e)&&!J&&(W(B.actionButtons),J=!0)}return{status:Q,errors:H}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0;var o,a,d,r,v,s;const p=[];let u="";const m=null===(o=e.components)||void 0===o?void 0:o.find((e=>"BODY"===e.type));return m&&(null===(r=null===(d=null===(a=m.example)||void 0===a?void 0:a.body_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,v=d&&/\(\(/.test(d),s=null==d?void 0:d.match(l);(null==s?void 0:s[2])&&(d=null==s?void 0:s[2]),p.push({idx:i,variableVal:n?t:r,editable:!!v,editableDefaultValues:v?void 0:t,variableName:null!=d?d:""})})),u=e.htmlContentUrl?e.htmlContentUrl:(null===(v=m.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).length)?null===(s=m.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==p?void 0:p[n]){const l=p[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:p,bodyText:u}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0;var o,a,d,r,v,s;const p=[];let u="";const m=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return m&&(null===(r=null===(d=null===(a=m.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,v=d&&/\(\(/.test(d),s=null==d?void 0:d.match(l);(null==s?void 0:s[2])&&(d=null==s?void 0:s[2]),p.push({idx:i,variableVal:n?t:r,editable:!!v,editableDefaultValues:v?void 0:t,variableName:null!=d?d:""})})),u=e.htmlContentUrl?e.htmlContentUrl:(null===(v=m.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).length)?null===(s=m.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==p?void 0:p[n]){const l=p[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:u,titleVariables:p}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,n,l,a,d,r;const v={actionsType:k.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},s=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(s&&(null===(i=null==s?void 0:s.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(n=null==s?void 0:s.buttons)||void 0===n?void 0:n[0].type)?k.QUICK_REPLY:k.CTA_BTN;if(v.actionsType=t,t===k.QUICK_REPLY){const e=null!==(a=null===(l=null==s?void 0:s.buttons)||void 0===l?void 0:l.map((e=>e)))&&void 0!==a?a:[];v.quickReply=e}else t===k.CTA_BTN&&(null===(d=null==s?void 0:s.buttons)||void 0===d||d.forEach((t=>{var i,n,l,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(l=null===(n=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===n?void 0:n[0])&&void 0!==l?l:void 0;let r=!1;d&&o.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));v.allButtons=null===(r=s.buttons)||void 0===r?void 0:r.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return v}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o}=t,{headerType:a,headerAssetLink:d,headerAssetName:r,headerText:v,headerVariables:s}=yield this.parseDataFromHeaderComponent(e),{bodyText:p,bodyVariable:u}=yield this.parseBodyComponent(e,l,o),{titleText:m,titleVariables:c}=yield this.parseTitleComponent(e,l,o),{actionsType:h,quickReply:b,ctaBtn:T,allButtons:y}=yield this.parseButtonComponent(e),f=this.parseLimitedTimeOfferComponent(e,y),x={quickReply:b,ctaBtn:T,allButtons:y,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:h,footerText:this.parseFooterComponent(e),bodyVariables:u,bodyText:p,headerType:a,headerAssetLink:d,headerAssetName:r,headerText:v,headerVariables:s,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:f,titleText:m,titleVariables:c},{errors:B}=this.validateState(x);return x.error=B,x}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}}export{E as TemplateCreatorHelper};
|
|
1
|
+
import{__awaiter as e}from"../../../_virtual/_tslib.js";import{format as t}from"date-fns";import{COLORS as i}from"../../../constants/Theme.js";import{specialCharPattern as n,placeHolderNamePattern as l,editableVarPattern as o}from"../constants/regexPatterns.js";import{REQUIRED_FIELD as a,NAME_LEN_LIMIT as d,NAME_LEN_ERROR as r,NO_SPECIAL_CHAR as s,HEADER_TEXT_LEN_LIMIT as v,HEADER_LEN_ERROR as p,ONE_VAR_ALLOWED as u,HEADER_ASSET_LINK_ERROR as m,BODY_TEXT_LEN_LIMIT as c,BODY_LEN_ERROR as h,QUICK_REPLY_BTN_TEXT_LIMIT as b,QUICK_REPLY_LEN_ERROR as T,BUTTON_EMOJI_ERROR as y,VALID_PHONE_NUMBER as f,QUICK_REPLY_NAME_LEN_LIMIT as x,CREATE_TEMPLATE_DOM_IDS as B,QUICK_REPLY_NAME_ERROR as C}from"../constants/TemplateConstants.js";import{HEADER_TYPES as g,ACTIONS_TYPES as k}from"../models/TemplateMeta.js";import{POD as N}from"../models/WhatsAppTemplate.js";import{TemplateHelperUtils as E}from"../utils/TemplateHelperUtils.js";class L{parseDataFromHeaderComponent(e,t,i){var n,l,o,a,d,r,s,v,p,u;const m={headerType:g.NONE,headerVariables:[]},c=null===(n=null==e?void 0:e.components)||void 0===n?void 0:n.find((e=>"HEADER"===e.type));if(c){m.headerType=c.format,m.headerText=c.text,m.headerAssetLink=null===(o=null===(l=c.example)||void 0===l?void 0:l.header_handle)||void 0===o?void 0:o[0];const n=null===(d=null===(a=c.example)||void 0===a?void 0:a.header_text)||void 0===d?void 0:d[0],h=null===(s=null===(r=e.mapping)||void 0===r?void 0:r.header)||void 0===s?void 0:s[0],b=h;if(h){const e=null==h?void 0:h.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),l=/\(\(/.test(h),o=i===N.CHATBOT&&b&&(null==b?void 0:b.startsWith("(("))&&(null==b?void 0:b.endsWith("))")),a={idx:0,variableVal:t||o?n:b,editable:l,editableDefaultValues:l?void 0:n,variableName:e};m.headerVariables=[a],(null===(p=null===(v=c.example)||void 0===v?void 0:v.header_text)||void 0===p?void 0:p.length)&&(m.headerText=null===(u=m.headerText)||void 0===u?void 0:u.replace("{{1}}",`{{${e}}}`))}}return m}validateState(e){var t,i,l,o,N,L,O,_,V,A,w,R,D,I,U,j,$,q,F,P,M,Y,S;const W=/\p{Extended_Pictographic}/u;let H="valid";const K={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},Q=new E;let G=!1;const J=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>d?(K.meta.name=r,H="invalid"):n.test(null===(l=e.meta.name)||void 0===l?void 0:l.trim())&&(K.meta.name=s,H="invalid"):(K.meta.name=a,H="invalid"),K.meta.name&&!G&&(J(B.name),G=!0),e.headerType===g.TEXT){const t=null!==(N=null===(o=e.headerText)||void 0===o?void 0:o.trim())&&void 0!==N?N:"";if(t)if(t.length>v)K.header=p,H="invalid";else{const e=Q.getTemplateVariablesFromState(t);e&&e.length>1&&(K.header=u,H="invalid")}else K.header=a,H="invalid"}else e.headerType===g.DOCUMENT||e.headerType===g.IMAGE||(e.headerType,g.VIDEO);if(e.headerType!==g.DOCUMENT&&e.headerType!==g.IMAGE&&e.headerType!==g.VIDEO||e.headerAssetLink||(K.header=m,H="invalid"),K.header&&!G&&(J(B.header),G=!0),e.bodyText?e.bodyTextRaw&&(null===(L=e.bodyTextRaw)||void 0===L?void 0:L.trim().length)>c&&(K.body=h,H="invalid"):(K.body=a,H="invalid"),K.body&&!G&&(J(B.body),G=!0),e.footerText&&e.footerText.length>v&&(K.footer=p,H="invalid"),(null==K?void 0:K.footer)&&!G&&(J(B.footer),G=!0),e.actionsType===k.CTA_BTN){if(null===(_=null===(O=e.ctaBtn)||void 0===O?void 0:O.phoneNumber)||void 0===_?void 0:_.isChecked){const t=null===(V=e.ctaBtn.phoneNumber.btnText)||void 0===V?void 0:V.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;K.ctaBtn&&!t?(K.ctaBtn.phoneNumber.btnText=a,H="invalid"):K.ctaBtn&&t&&t.length>b?(K.ctaBtn.phoneNumber.btnText=T,H="invalid"):K.ctaBtn&&t&&W.test(t)&&(K.ctaBtn.phoneNumber.btnText=y,H="invalid"),K.ctaBtn&&!i?(K.ctaBtn.phoneNumber.link=a,H="invalid"):K.ctaBtn&&i&&i.length<10&&(K.ctaBtn.phoneNumber.link=f,H="invalid")}if(null===(w=null===(A=e.ctaBtn)||void 0===A?void 0:A.websiteLinkBtn)||void 0===w?void 0:w.isChecked){const t=null===(R=e.ctaBtn.websiteLinkBtn.btnText)||void 0===R?void 0:R.trim(),i=null===(D=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===D?void 0:D.trim(),n=null===(I=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===I?void 0:I.trim();K.ctaBtn&&!t?(K.ctaBtn.websiteLink.btnText=a,H="invalid"):K.ctaBtn&&t&&t.length>b?(K.ctaBtn.websiteLink.btnText=T,H="invalid"):K.ctaBtn&&t&&W.test(t)&&(K.ctaBtn.websiteLink.btnText=y,H="invalid"),!K.ctaBtn||i||n||(K.ctaBtn.websiteLink.link=a,H="invalid")}}else if(e.actionsType===k.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var l;const o=null===(l=i.text)||void 0===l?void 0:l.trim();if(o)if(o.length>x)t[n]=T,H="invalid";else if(W.test(o))t[n]=y,H="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===o))&&(t[n]=C,H="invalid")}else t[n]=a,H="invalid"})),K.quickReply=t}if(e.actionsType===k.CTA_BTN||e.actionsType===k.QUICK_REPLY){const e=null===(U=K.quickReply)||void 0===U?void 0:U.reduce(((e,t)=>e||!!t),!1);((null===($=null===(j=null==K?void 0:K.ctaBtn)||void 0===j?void 0:j.websiteLink)||void 0===$?void 0:$.link)||(null===(F=null===(q=K.ctaBtn)||void 0===q?void 0:q.websiteLink)||void 0===F?void 0:F.btnText)||(null===(M=null===(P=K.ctaBtn)||void 0===P?void 0:P.phoneNumber)||void 0===M?void 0:M.link)||(null===(S=null===(Y=K.ctaBtn)||void 0===Y?void 0:Y.phoneNumber)||void 0===S?void 0:S.btnText)||e)&&!G&&(J(B.actionButtons),G=!0)}return{status:H,errors:K}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0;var a,d,r,s,v,p;const u=[];let m="";const c=null===(a=e.components)||void 0===a?void 0:a.find((e=>"BODY"===e.type));return c&&(null===(s=null===(r=null===(d=c.example)||void 0===d?void 0:d.body_text)||void 0===r?void 0:r[0])||void 0===s||s.forEach(((t,i)=>{var a,d;let r=null===(d=null===(a=e.mapping)||void 0===a?void 0:a.body)||void 0===d?void 0:d[i];const s=r,v=r&&/\(\(/.test(r),p=null==r?void 0:r.match(l);(null==p?void 0:p[2])&&(r=null==p?void 0:p[2]);const m=o===N.CHATBOT&&s&&(null==s?void 0:s.startsWith("(("))&&(null==s?void 0:s.endsWith("))"));u.push({idx:i,variableVal:n||m?t:s,editable:!!v,editableDefaultValues:v?void 0:t,variableName:null!=r?r:""})})),m=e.htmlContentUrl?e.htmlContentUrl:(null===(v=c.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).length)?null===(p=c.text)||void 0===p?void 0:p.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:u,bodyText:m}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const p=[];let u="";const m=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return m&&(null===(r=null===(d=null===(a=m.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(l);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),p.push({idx:i,variableVal:n?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),u=e.htmlContentUrl?e.htmlContentUrl:(null===(s=m.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=m.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==p?void 0:p[n]){const l=p[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:u,titleVariables:p}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,n,l,a,d,r;const s={actionsType:k.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},v=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(v&&(null===(i=null==v?void 0:v.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(n=null==v?void 0:v.buttons)||void 0===n?void 0:n[0].type)?k.QUICK_REPLY:k.CTA_BTN;if(s.actionsType=t,t===k.QUICK_REPLY){const e=null!==(a=null===(l=null==v?void 0:v.buttons)||void 0===l?void 0:l.map((e=>e)))&&void 0!==a?a:[];s.quickReply=e}else t===k.CTA_BTN&&(null===(d=null==v?void 0:v.buttons)||void 0===d||d.forEach((t=>{var i,n,l,a;if(t.phone_number&&(s.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(l=null===(n=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===n?void 0:n[0])&&void 0!==l?l:void 0;let r=!1;d&&o.test(d)&&(r=!0),s.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));s.allButtons=null===(r=v.buttons)||void 0===r?void 0:r.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return s}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o,pod:a}=t,{headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:p}=yield this.parseDataFromHeaderComponent(e,void 0,a),{bodyText:u,bodyVariable:m}=yield this.parseBodyComponent(e,l,o,a),{titleText:c,titleVariables:h}=yield this.parseTitleComponent(e,l,o),{actionsType:b,quickReply:T,ctaBtn:y,allButtons:f}=yield this.parseButtonComponent(e),x=this.parseLimitedTimeOfferComponent(e,f),B={quickReply:T,ctaBtn:y,allButtons:f,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:b,footerText:this.parseFooterComponent(e),bodyVariables:m,bodyText:u,headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:p,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:x,titleText:c,titleVariables:h},{errors:C}=this.validateState(B);return B.error=C,B}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}}export{L as TemplateCreatorHelper};
|