@bikdotai/bik-component-library 0.0.314-beta.32 → 0.0.314-beta.34

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.
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),l=require("../../../assets/icons/edit.svg.js"),t=require("react"),a=require("styled-components"),n=require("../../add-variableV2/AddVariableV2SideModal.js"),i=require("../../dropdown/Dropdown.js"),o=require("../../input/Input.js"),u=require("../../template-preview/constants/regexPatterns.js"),s=require("../../template-preview/models/Channels.js"),d=require("../../TypographyStyle.js"),r=require("../../../utils/StringUtils.js"),c=require("../../../constants/Theme.js"),v=require("../context/templateModalContext.js"),p=require("../utils/getVariableNameEmail.js");function m(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const b=m(a).default.div`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),l=require("../../../assets/icons/edit.svg.js"),t=require("react"),a=require("styled-components"),n=require("../../add-variableV2/AddVariableV2SideModal.js"),i=require("../../dropdown/Dropdown.js"),o=require("../../input/Input.js"),u=require("../../product-picker-v2/collectionScreen.js"),s=require("../../template-preview/constants/regexPatterns.js"),d=require("../../template-preview/models/Channels.js"),r=require("../../TypographyStyle.js"),c=require("../../../utils/StringUtils.js"),v=require("../../../constants/Theme.js"),p=require("../context/templateModalContext.js"),m=require("../utils/getVariableNameEmail.js");function b(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}const g=b(a).default.div`
2
2
  /* surface/$color-background-warning-light */
3
3
 
4
- background: ${e=>e.focused&&e.channel===s.CHANNEL_TYPE.EMAIL?c.COLORS.background.warning.light:"transparent"};
4
+ background: ${e=>e.focused&&e.channel===d.CHANNEL_TYPE.EMAIL?v.COLORS.background.warning.light:"transparent"};
5
5
  border-radius: 4px;
6
6
  padding: 8px 10px;
7
- `,g={value:"custom_link",label:"Custom URL"},x={value:"custom_text",label:"Custom text"};exports.Container=b,exports.default=a=>{let{onFocus:m,variable:h,index:E,showVariableModal:_,variableList:j,setShowDiscountCheckBox:A}=a;var y;const[f,P]=t.useState(!1),[T,N]=t.useState(""),[C,L]=t.useState([]),[k,O]=t.useState(),[S,V]=t.useState(!1),[H,w]=t.useState(!1),{device:M,channel:q,isError:Y,originalVariableList:W,template:I,templateSelectionTriggered:B,setTemplate:$,setDisplayContent:R,setOriginalVariableList:z,globalNormalizedPlaceholders:D}=v.useTemplateModalContext();function U(e,l){var t,a,n;const i=e;N(""),O(i),q===s.CHANNEL_TYPE.WHATSAPP?"custom_text"!==i.value&&"custom_link"!==i.value?(Z(null!==(t=i.value)&&void 0!==t?t:"","string"),null==F||F(null!==(a=h.index)&&void 0!==a?a:0,`[[${i.value}]]`)):(null==F||F(null!==(n=h.index)&&void 0!==n?n:0,h.variableName),Z("","url"===i.bikPlaceholderType?"link":"string")):"custom_text"!==i.value&&"custom_link"!==i.value?Z(i.value,"url"===i.bikPlaceholderType?"link":"string"):(N(""),Z("",i.value))}function Z(e,l){var t,a;const n="custom_link"===l?"link":"custom_text"===l?"string":l;if(q!==s.CHANNEL_TYPE.WHATSAPP){const a=p.getVariableNameForEmailByIndex(E+1),i=null===document||void 0===document?void 0:document.getElementById("mobile"===M?"template_html_mobile":"template_html_desktop"),o=q===s.CHANNEL_TYPE.EMAIL?null===(t=null==i?void 0:i.contentWindow)||void 0===t?void 0:t.document.getElementById(a):document.getElementById(a);o&&(o.textContent="custom_text"!==l&&"custom_link"!==l||e?e:h.variableName);const u=W.map(((l,t)=>t===E?Object.assign(Object.assign({},l),{type:n,updatedValue:e}):l));null==z||z(u)}if(q===s.CHANNEL_TYPE.WHATSAPP){const l=null===(a=W.body)||void 0===a?void 0:a.map(((l,t)=>t===E?Object.assign(Object.assign({},l),{type:n,updatedValue:e}):l));null==z||z((e=>Object.assign(Object.assign({},e),{body:l,buttons:W.buttons})))}}function F(e,l){var t;const a=Object.assign({},I),n=null===(t=null==a?void 0:a.components)||void 0===t?void 0:t.map((t=>{var a,n,i,o,u;const s=Object.assign({},t);if("BODY"===t.type&&(null===(n=null===(a=t.example)||void 0===a?void 0:a.body_text)||void 0===n?void 0:n[0])){const t=[...null!==(u=null===(o=null===(i=s.example)||void 0===i?void 0:i.body_text)||void 0===o?void 0:o[0])&&void 0!==u?u:[]];t[e]=l.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},s.example),{body_text:[t]});return Object.assign(Object.assign({},s),{example:a})}return t}));a.components=n,null==$||$(a)}return t.useEffect((()=>{f&&(null==m||m())}),[f]),t.useEffect((()=>{!function(){var e,l,t,a,n;const i="mobile"===M?"template_html_mobile":"template_html_desktop",o=document.getElementById(i),u=(null!==(a=null===(t=null===(l=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===l?void 0:l.body)||void 0===t?void 0:t.innerHTML)&&void 0!==a?a:"")+(null===(n=null==o?void 0:o.contentWindow)||void 0===n?void 0:n.document.head.innerHTML);q===s.CHANNEL_TYPE.EMAIL&&(null==R||R(u))}()}),[B]),t.useEffect((()=>{var e;const l=[];let t=[];if(q===s.CHANNEL_TYPE.MESSAGE){const e=null!=D?D:[];L([{label:"",options:[x,g]},...e]),t=[{label:"",options:[x,g]},...e]}else{"link"===(null==h?void 0:h.type)?(l.push({label:"",options:[g,x]}),O(g)):(l.push({label:"",options:[g,x]}),O(x));const e=null!=D?D:[];L([...l,...e.map((e=>{var l,t;return Object.assign(Object.assign({},e),{label:r.default.toCapitilize(null===(t=null===(l=e.label)||void 0===l?void 0:l.replace(/([A-Z])/g," $1"))||void 0===t?void 0:t.toLowerCase())})}))]),t=[...l,...e]}if((q===s.CHANNEL_TYPE.WHATSAPP||q===s.CHANNEL_TYPE.EMAIL||q===s.CHANNEL_TYPE.MESSAGE)&&h.updatedValue)if(u.placeHolderNamePattern.test(h.updatedValue)&&q===s.CHANNEL_TYPE.WHATSAPP||h.updatedValue.startsWith("{{")&&q!==s.CHANNEL_TYPE.WHATSAPP){const e=function(e,l,t){var a;let n={label:"",value:""};const i=t===s.CHANNEL_TYPE.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");_?n={label:e.updatedValue?e.updatedValue.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}:l.map((e=>{e.options.map((e=>{var l;(null===(l=e.value)||void 0===l?void 0:l.replace("{{","").replace("}}","").trim())===i.trim()&&(n=e)}))}));return n}(h,t,q);e.value&&O(e)}else(null===(e=h.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(O(g),N(h.updatedValue.split("https://")[1])):(O(x),N(h.updatedValue))}),[]),t.useEffect((()=>{M&&k&&T&&setTimeout((()=>{Z("custom_link"===(null==k?void 0:k.value)?`https://${T}`:T,k.value)}),100)}),[M]),t.useEffect((()=>{!H&&k&&h.updatedValue&&setTimeout((()=>{Z("custom_link"===(null==k?void 0:k.value)?`https://${h.updatedValue}`:h.updatedValue,k.value),w(!0)}),100)}),[k]),e.jsxs(b,Object.assign({channel:q,focused:f,onMouseEnter:()=>P(!0),onMouseLeave:()=>P(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(d.BodySecondary,Object.assign({style:{color:Y&&!k?c.COLORS.content.negative:c.COLORS.content.primary}},{children:[null===(y=h.variableName)||void 0===y?void 0:y.replace("{{","").replace("}}","")," ","link"===(null==h?void 0:h.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:_?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==k?void 0:k.label)?"space-between":"flex-end"}},{children:[e.jsx(d.BodyPrimary,{children:null==k?void 0:k.label}),e.jsx(l.default,{onClick:()=>{V(!S)},width:24,height:24,color:c.COLORS.content.primary})]})):e.jsx(i.Dropdown,{options:C,isSearchable:!1,onSelect:U,defaultOptions:k?[Object.assign(Object.assign({},k),{selected:!0})]:[]})})),("custom_text"===(null==k?void 0:k.value)||"custom_link"===(null==k?void 0:k.value))&&e.jsx(o.Input,{labelText:"custom_text"===(null==k?void 0:k.value)?"Custom text value":"custom_link"===(null==k?void 0:k.value)?"Custom URL value":"",id:`variable-value-${null==k?void 0:k.value}-${E}`,value:T,errorMessage:Y?T&&0!==T.trim().length?"custom_link"!==k.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${T.trim()}`)&&0!==T.trim().length?"custom_link"!==k.value&&T.length>30?"Length cannot be more that 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==k?void 0:k.value)?void 0:30,prefixText:"custom_link"===(null==k?void 0:k.value)?"https://":"",placeholder:"link"===h.type||"custom_link"===k.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{console.log("valuevalue3: ",e),function(e,l){var t;N(l);const a="custom_link"===(null==k?void 0:k.value)?`https://${l}`:l;Z(a,e),q===s.CHANNEL_TYPE.WHATSAPP&&(null==F||F(null!==(t=h.index)&&void 0!==t?t:0,a))}(k.value,e)}}),S&&e.jsx(n.AddVariableV2SideModal,{zIndex:2e3,data:null!=j?j:[],showVariable:S,setShowVariable:V,placeholder:"Add a variable",customTrigger:e=>{A(!1),"{{custom.url}}"===e.actualValue?U({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?U({label:e.displayName,selected:!0,value:"custom_text"}):U({label:e.actualValue.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};
7
+ `,x={value:"custom_link",label:"Custom URL"},h={value:"custom_text",label:"Custom text"};exports.Container=g,exports.default=a=>{let{onFocus:b,variable:E,index:_,showVariableModal:j,variableList:A,setShowDiscountCheckBox:y}=a;var f,P;const[T,N]=t.useState(!1),[C,L]=t.useState(""),[k,O]=t.useState([]),[S,V]=t.useState(),[H,w]=t.useState(!1),[M,q]=t.useState(!1),{device:Y,channel:W,isError:I,originalVariableList:B,template:$,templateSelectionTriggered:R,setTemplate:z,setDisplayContent:D,setOriginalVariableList:U,globalNormalizedPlaceholders:Z}=p.useTemplateModalContext();function F(e,l){var t,a,n;const i=e;L(""),V(i),W===d.CHANNEL_TYPE.WHATSAPP?"custom_text"!==i.value&&"custom_link"!==i.value?(G(null!==(t=i.value)&&void 0!==t?t:"","string"),null==J||J(null!==(a=E.index)&&void 0!==a?a:0,`[[${i.value}]]`)):(null==J||J(null!==(n=E.index)&&void 0!==n?n:0,E.variableName),G("","url"===i.bikPlaceholderType?"link":"string")):"custom_text"!==i.value&&"custom_link"!==i.value?G(i.value,"url"===i.bikPlaceholderType?"link":"string"):(L(""),G("",i.value))}function G(e,l){var t,a;const n="custom_link"===l?"link":"custom_text"===l?"string":l;if(W!==d.CHANNEL_TYPE.WHATSAPP){const a=m.getVariableNameForEmailByIndex(_+1),i=null===document||void 0===document?void 0:document.getElementById("mobile"===Y?"template_html_mobile":"template_html_desktop"),o=W===d.CHANNEL_TYPE.EMAIL?null===(t=null==i?void 0:i.contentWindow)||void 0===t?void 0:t.document.getElementById(a):document.getElementById(a);o&&(o.textContent="custom_text"!==l&&"custom_link"!==l||e?e:E.variableName);const u=B.map(((l,t)=>t===_?Object.assign(Object.assign({},l),{type:n,updatedValue:e}):l));null==U||U(u)}if(W===d.CHANNEL_TYPE.WHATSAPP){const l=null===(a=B.body)||void 0===a?void 0:a.map(((l,t)=>t===_?Object.assign(Object.assign({},l),{type:n,updatedValue:e}):l));null==U||U((e=>Object.assign(Object.assign({},e),{body:l,buttons:B.buttons})))}}function J(e,l){var t;const a=Object.assign({},$),n=null===(t=null==a?void 0:a.components)||void 0===t?void 0:t.map((t=>{var a,n,i,o,u;const s=Object.assign({},t);if("BODY"===t.type&&(null===(n=null===(a=t.example)||void 0===a?void 0:a.body_text)||void 0===n?void 0:n[0])){const t=[...null!==(u=null===(o=null===(i=s.example)||void 0===i?void 0:i.body_text)||void 0===o?void 0:o[0])&&void 0!==u?u:[]];t[e]=l.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},s.example),{body_text:[t]});return Object.assign(Object.assign({},s),{example:a})}return t}));a.components=n,null==z||z(a)}return t.useEffect((()=>{T&&(null==b||b())}),[T]),t.useEffect((()=>{!function(){var e,l,t,a,n;const i="mobile"===Y?"template_html_mobile":"template_html_desktop",o=document.getElementById(i),u=(null!==(a=null===(t=null===(l=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===l?void 0:l.body)||void 0===t?void 0:t.innerHTML)&&void 0!==a?a:"")+(null===(n=null==o?void 0:o.contentWindow)||void 0===n?void 0:n.document.head.innerHTML);W===d.CHANNEL_TYPE.EMAIL&&(null==D||D(u))}()}),[R]),t.useEffect((()=>{var e;const l=[];let t=[];if(W===d.CHANNEL_TYPE.MESSAGE){const e=null!=Z?Z:[];O([{label:"",options:[h,x]},...e]),t=[{label:"",options:[h,x]},...e]}else{"link"===(null==E?void 0:E.type)?(l.push({label:"",options:[x,h]}),V(x)):(l.push({label:"",options:[x,h]}),V(h));const e=null!=Z?Z:[];O([...l,...e.map((e=>{var l,t;return Object.assign(Object.assign({},e),{label:c.default.toCapitilize(null===(t=null===(l=e.label)||void 0===l?void 0:l.replace(/([A-Z])/g," $1"))||void 0===t?void 0:t.toLowerCase())})}))]),t=[...l,...e]}if((W===d.CHANNEL_TYPE.WHATSAPP||W===d.CHANNEL_TYPE.EMAIL||W===d.CHANNEL_TYPE.MESSAGE)&&E.updatedValue)if(s.placeHolderNamePattern.test(E.updatedValue)&&W===d.CHANNEL_TYPE.WHATSAPP||E.updatedValue.startsWith("{{")&&W!==d.CHANNEL_TYPE.WHATSAPP){const e=function(e,l,t){var a;let n={label:"",value:""};const i=t===d.CHANNEL_TYPE.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");j?n={label:e.updatedValue?e.updatedValue.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}:l.map((e=>{e.options.map((e=>{var l;(null===(l=e.value)||void 0===l?void 0:l.replace("{{","").replace("}}","").trim())===i.trim()&&(n=e)}))}));return n}(E,t,W);e.value&&V(e)}else(null===(e=E.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(V(x),L(E.updatedValue.split("https://")[1])):(V(h),L(E.updatedValue))}),[]),t.useEffect((()=>{Y&&S&&C&&setTimeout((()=>{G("custom_link"===(null==S?void 0:S.value)?`https://${C}`:C,S.value)}),100)}),[Y]),t.useEffect((()=>{!M&&S&&E.updatedValue&&setTimeout((()=>{G("custom_link"===(null==S?void 0:S.value)?`https://${E.updatedValue}`:E.updatedValue,S.value),q(!0)}),100)}),[S]),e.jsxs(g,Object.assign({channel:W,focused:T,onMouseEnter:()=>N(!0),onMouseLeave:()=>N(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(r.BodySecondary,Object.assign({style:{color:I&&!S?v.COLORS.content.negative:v.COLORS.content.primary}},{children:[null===(f=E.variableName)||void 0===f?void 0:f.replace("{{","").replace("}}","")," ","link"===(null==E?void 0:E.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:j?e.jsxs("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==S?void 0:S.label)?"space-between":"flex-end"}},{children:[e.jsx(r.BodyPrimary,{children:u.truncate(null!==(P=null==S?void 0:S.label)&&void 0!==P?P:"",20,!0)}),e.jsx(l.default,{onClick:()=>{w(!H)},width:24,height:24,color:v.COLORS.content.primary})]})):e.jsx(i.Dropdown,{options:k,isSearchable:!1,onSelect:F,defaultOptions:S?[Object.assign(Object.assign({},S),{selected:!0})]:[]})})),("custom_text"===(null==S?void 0:S.value)||"custom_link"===(null==S?void 0:S.value))&&e.jsx(o.Input,{labelText:"custom_text"===(null==S?void 0:S.value)?"Custom text value":"custom_link"===(null==S?void 0:S.value)?"Custom URL value":"",id:`variable-value-${null==S?void 0:S.value}-${_}`,value:C,errorMessage:I?C&&0!==C.trim().length?"custom_link"!==S.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${C.trim()}`)&&0!==C.trim().length?"custom_link"!==S.value&&C.length>30?"Length cannot be more that 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==S?void 0:S.value)?void 0:30,prefixText:"custom_link"===(null==S?void 0:S.value)?"https://":"",placeholder:"link"===E.type||"custom_link"===S.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{console.log("valuevalue3: ",e),function(e,l){var t;L(l);const a="custom_link"===(null==S?void 0:S.value)?`https://${l}`:l;G(a,e),W===d.CHANNEL_TYPE.WHATSAPP&&(null==J||J(null!==(t=E.index)&&void 0!==t?t:0,a))}(S.value,e)}}),H&&e.jsx(n.AddVariableV2SideModal,{zIndex:2e3,data:null!=A?A:[],showVariable:H,setShowVariable:w,placeholder:"Add a variable",customTrigger:e=>{y(!1),"{{custom.url}}"===e.actualValue?F({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?F({label:e.displayName,selected:!0,value:"custom_text"}):F({label:e.actualValue.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),i=require("../shimmer/ShimmerComponent/BikShimmer.js"),r=require("../button/Button.js"),n=require("../TypographyStyle.js"),a=require("./EmailTemplatePreview.styled.js");exports.default=s=>{let{template:l,handleViewTemplate:o,hideHeader:d,hideViewButton:m,containerStyle:h,emailHtmlContainerId:u,emailDisplayContent:j}=s;const[c,x]=t.useState(!1);return e.jsxs(a.EmailContainer,Object.assign({hideHeader:d,style:Object.assign({},null!=h?h:{})},{children:[!d&&e.jsx(a.Header,{children:e.jsx(n.TitleRegular,Object.assign({style:{maxWidth:"100%"}},{children:l.name}))}),e.jsx(a.IframeContainer,{children:j?c?e.jsx("iframe",{title:"Email template preview",id:null!=u?u:"",width:"100%",srcDoc:j,height:"100%",style:{pointerEvents:"none"},onLoad:()=>x(!0)}):e.jsx(i.BikShimmer,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]}):e.jsx(a.ImageContainer,Object.assign({hideHeader:d},{children:e.jsx(a.CardLoadingContainer,{})}))}),!m&&e.jsx(a.ViewButton,{children:e.jsx(r.Button,{buttonType:"tertiary",buttonText:"View",onClick:()=>{o&&o()}})})]}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../button/Button.js"),i=require("../TypographyStyle.js"),r=require("./EmailTemplatePreview.styled.js");exports.default=n=>{let{template:a,handleViewTemplate:l,hideHeader:s,hideViewButton:d,containerStyle:o,emailHtmlContainerId:u,emailDisplayContent:j}=n;return e.jsxs(r.EmailContainer,Object.assign({hideHeader:s,style:Object.assign({},null!=o?o:{})},{children:[!s&&e.jsx(r.Header,{children:e.jsx(i.TitleRegular,Object.assign({style:{maxWidth:"100%"}},{children:a.name}))}),e.jsx(r.IframeContainer,{children:j?e.jsx("iframe",{title:"Email template preview",id:null!=u?u:"",width:"100%",srcDoc:j,height:"100%",style:{pointerEvents:"none"}}):e.jsx(r.ImageContainer,Object.assign({hideHeader:s},{children:e.jsx(r.CardLoadingContainer,{})}))}),!d&&e.jsx(r.ViewButton,{children:e.jsx(t.Button,{buttonType:"tertiary",buttonText:"View",onClick:()=>{l&&l()}})})]}))};
@@ -1,7 +1,7 @@
1
- import{jsxs as e,jsx as l}from"react/jsx-runtime";import t from"../../../assets/icons/edit.svg.js";import{useState as a,useEffect as o}from"react";import n from"styled-components";import{AddVariableV2SideModal as i}from"../../add-variableV2/AddVariableV2SideModal.js";import{Dropdown as u}from"../../dropdown/Dropdown.js";import{Input as s}from"../../input/Input.js";import{placeHolderNamePattern as d}from"../../template-preview/constants/regexPatterns.js";import{CHANNEL_TYPE as r}from"../../template-preview/models/Channels.js";import{BodySecondary as c,BodyPrimary as m}from"../../TypographyStyle.js";import v from"../../../utils/StringUtils.js";import{COLORS as p}from"../../../constants/Theme.js";import{useTemplateModalContext as b}from"../context/templateModalContext.js";import{getVariableNameForEmailByIndex as g}from"../utils/getVariableNameEmail.js";const h=n.div`
1
+ import{jsxs as e,jsx as l}from"react/jsx-runtime";import t from"../../../assets/icons/edit.svg.js";import{useState as a,useEffect as o}from"react";import n from"styled-components";import{AddVariableV2SideModal as i}from"../../add-variableV2/AddVariableV2SideModal.js";import{Dropdown as u}from"../../dropdown/Dropdown.js";import{Input as s}from"../../input/Input.js";import{truncate as d}from"../../product-picker-v2/collectionScreen.js";import{placeHolderNamePattern as r}from"../../template-preview/constants/regexPatterns.js";import{CHANNEL_TYPE as c}from"../../template-preview/models/Channels.js";import{BodySecondary as m,BodyPrimary as v}from"../../TypographyStyle.js";import p from"../../../utils/StringUtils.js";import{COLORS as b}from"../../../constants/Theme.js";import{useTemplateModalContext as g}from"../context/templateModalContext.js";import{getVariableNameForEmailByIndex as h}from"../utils/getVariableNameEmail.js";const x=n.div`
2
2
  /* surface/$color-background-warning-light */
3
3
 
4
- background: ${e=>e.focused&&e.channel===r.EMAIL?p.background.warning.light:"transparent"};
4
+ background: ${e=>e.focused&&e.channel===c.EMAIL?b.background.warning.light:"transparent"};
5
5
  border-radius: 4px;
6
6
  padding: 8px 10px;
7
- `,x={value:"custom_link",label:"Custom URL"},_={value:"custom_text",label:"Custom text"},f=n=>{let{onFocus:f,variable:j,index:y,showVariableModal:k,variableList:V,setShowDiscountCheckBox:A}=n;var O;const[T,E]=a(!1),[P,S]=a(""),[w,L]=a([]),[C,M]=a(),[W,$]=a(!1),[H,I]=a(!1),{device:B,channel:N,isError:z,originalVariableList:R,template:U,templateSelectionTriggered:D,setTemplate:Z,setDisplayContent:G,setOriginalVariableList:q,globalNormalizedPlaceholders:F}=b();function Y(e,l){var t,a,o;const n=e;S(""),M(n),N===r.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(J(null!==(t=n.value)&&void 0!==t?t:"","string"),null==K||K(null!==(a=j.index)&&void 0!==a?a:0,`[[${n.value}]]`)):(null==K||K(null!==(o=j.index)&&void 0!==o?o:0,j.variableName),J("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?J(n.value,"url"===n.bikPlaceholderType?"link":"string"):(S(""),J("",n.value))}function J(e,l){var t,a;const o="custom_link"===l?"link":"custom_text"===l?"string":l;if(N!==r.WHATSAPP){const a=g(y+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===B?"template_html_mobile":"template_html_desktop"),i=N===r.EMAIL?null===(t=null==n?void 0:n.contentWindow)||void 0===t?void 0:t.document.getElementById(a):document.getElementById(a);i&&(i.textContent="custom_text"!==l&&"custom_link"!==l||e?e:j.variableName);const u=R.map(((l,t)=>t===y?Object.assign(Object.assign({},l),{type:o,updatedValue:e}):l));null==q||q(u)}if(N===r.WHATSAPP){const l=null===(a=R.body)||void 0===a?void 0:a.map(((l,t)=>t===y?Object.assign(Object.assign({},l),{type:o,updatedValue:e}):l));null==q||q((e=>Object.assign(Object.assign({},e),{body:l,buttons:R.buttons})))}}function K(e,l){var t;const a=Object.assign({},U),o=null===(t=null==a?void 0:a.components)||void 0===t?void 0:t.map((t=>{var a,o,n,i,u;const s=Object.assign({},t);if("BODY"===t.type&&(null===(o=null===(a=t.example)||void 0===a?void 0:a.body_text)||void 0===o?void 0:o[0])){const t=[...null!==(u=null===(i=null===(n=s.example)||void 0===n?void 0:n.body_text)||void 0===i?void 0:i[0])&&void 0!==u?u:[]];t[e]=l.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},s.example),{body_text:[t]});return Object.assign(Object.assign({},s),{example:a})}return t}));a.components=o,null==Z||Z(a)}return o((()=>{T&&(null==f||f())}),[T]),o((()=>{!function(){var e,l,t,a,o;const n="mobile"===B?"template_html_mobile":"template_html_desktop",i=document.getElementById(n),u=(null!==(a=null===(t=null===(l=null===(e=null==i?void 0:i.contentWindow)||void 0===e?void 0:e.document)||void 0===l?void 0:l.body)||void 0===t?void 0:t.innerHTML)&&void 0!==a?a:"")+(null===(o=null==i?void 0:i.contentWindow)||void 0===o?void 0:o.document.head.innerHTML);N===r.EMAIL&&(null==G||G(u))}()}),[D]),o((()=>{var e;const l=[];let t=[];if(N===r.MESSAGE){const e=null!=F?F:[];L([{label:"",options:[_,x]},...e]),t=[{label:"",options:[_,x]},...e]}else{"link"===(null==j?void 0:j.type)?(l.push({label:"",options:[x,_]}),M(x)):(l.push({label:"",options:[x,_]}),M(_));const e=null!=F?F:[];L([...l,...e.map((e=>{var l,t;return Object.assign(Object.assign({},e),{label:v.toCapitilize(null===(t=null===(l=e.label)||void 0===l?void 0:l.replace(/([A-Z])/g," $1"))||void 0===t?void 0:t.toLowerCase())})}))]),t=[...l,...e]}if((N===r.WHATSAPP||N===r.EMAIL||N===r.MESSAGE)&&j.updatedValue)if(d.test(j.updatedValue)&&N===r.WHATSAPP||j.updatedValue.startsWith("{{")&&N!==r.WHATSAPP){const e=function(e,l,t){var a;let o={label:"",value:""};const n=t===r.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");k?o={label:e.updatedValue?e.updatedValue.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}:l.map((e=>{e.options.map((e=>{var l;(null===(l=e.value)||void 0===l?void 0:l.replace("{{","").replace("}}","").trim())===n.trim()&&(o=e)}))}));return o}(j,t,N);e.value&&M(e)}else(null===(e=j.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(M(x),S(j.updatedValue.split("https://")[1])):(M(_),S(j.updatedValue))}),[]),o((()=>{B&&C&&P&&setTimeout((()=>{J("custom_link"===(null==C?void 0:C.value)?`https://${P}`:P,C.value)}),100)}),[B]),o((()=>{!H&&C&&j.updatedValue&&setTimeout((()=>{J("custom_link"===(null==C?void 0:C.value)?`https://${j.updatedValue}`:j.updatedValue,C.value),I(!0)}),100)}),[C]),e(h,Object.assign({channel:N,focused:T,onMouseEnter:()=>E(!0),onMouseLeave:()=>E(!1)},{children:[l("div",Object.assign({style:{marginBottom:8}},{children:e(c,Object.assign({style:{color:z&&!C?p.content.negative:p.content.primary}},{children:[null===(O=j.variableName)||void 0===O?void 0:O.replace("{{","").replace("}}","")," ","link"===(null==j?void 0:j.type)?"link":"variable"]}))})),l("div",Object.assign({style:{marginBottom:12}},{children:k?e("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==C?void 0:C.label)?"space-between":"flex-end"}},{children:[l(m,{children:null==C?void 0:C.label}),l(t,{onClick:()=>{$(!W)},width:24,height:24,color:p.content.primary})]})):l(u,{options:w,isSearchable:!1,onSelect:Y,defaultOptions:C?[Object.assign(Object.assign({},C),{selected:!0})]:[]})})),("custom_text"===(null==C?void 0:C.value)||"custom_link"===(null==C?void 0:C.value))&&l(s,{labelText:"custom_text"===(null==C?void 0:C.value)?"Custom text value":"custom_link"===(null==C?void 0:C.value)?"Custom URL value":"",id:`variable-value-${null==C?void 0:C.value}-${y}`,value:P,errorMessage:z?P&&0!==P.trim().length?"custom_link"!==C.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${P.trim()}`)&&0!==P.trim().length?"custom_link"!==C.value&&P.length>30?"Length cannot be more that 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==C?void 0:C.value)?void 0:30,prefixText:"custom_link"===(null==C?void 0:C.value)?"https://":"",placeholder:"link"===j.type||"custom_link"===C.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{console.log("valuevalue3: ",e),function(e,l){var t;S(l);const a="custom_link"===(null==C?void 0:C.value)?`https://${l}`:l;J(a,e),N===r.WHATSAPP&&(null==K||K(null!==(t=j.index)&&void 0!==t?t:0,a))}(C.value,e)}}),W&&l(i,{zIndex:2e3,data:null!=V?V:[],showVariable:W,setShowVariable:$,placeholder:"Add a variable",customTrigger:e=>{A(!1),"{{custom.url}}"===e.actualValue?Y({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?Y({label:e.displayName,selected:!0,value:"custom_text"}):Y({label:e.actualValue.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{h as Container,f as default};
7
+ `,f={value:"custom_link",label:"Custom URL"},_={value:"custom_text",label:"Custom text"},j=n=>{let{onFocus:j,variable:k,index:y,showVariableModal:V,variableList:A,setShowDiscountCheckBox:O}=n;var T,E;const[P,S]=a(!1),[w,L]=a(""),[C,M]=a([]),[W,$]=a(),[H,I]=a(!1),[B,N]=a(!1),{device:z,channel:R,isError:U,originalVariableList:D,template:Z,templateSelectionTriggered:G,setTemplate:q,setDisplayContent:F,setOriginalVariableList:Y,globalNormalizedPlaceholders:J}=g();function K(e,l){var t,a,o;const n=e;L(""),$(n),R===c.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(Q(null!==(t=n.value)&&void 0!==t?t:"","string"),null==X||X(null!==(a=k.index)&&void 0!==a?a:0,`[[${n.value}]]`)):(null==X||X(null!==(o=k.index)&&void 0!==o?o:0,k.variableName),Q("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?Q(n.value,"url"===n.bikPlaceholderType?"link":"string"):(L(""),Q("",n.value))}function Q(e,l){var t,a;const o="custom_link"===l?"link":"custom_text"===l?"string":l;if(R!==c.WHATSAPP){const a=h(y+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===z?"template_html_mobile":"template_html_desktop"),i=R===c.EMAIL?null===(t=null==n?void 0:n.contentWindow)||void 0===t?void 0:t.document.getElementById(a):document.getElementById(a);i&&(i.textContent="custom_text"!==l&&"custom_link"!==l||e?e:k.variableName);const u=D.map(((l,t)=>t===y?Object.assign(Object.assign({},l),{type:o,updatedValue:e}):l));null==Y||Y(u)}if(R===c.WHATSAPP){const l=null===(a=D.body)||void 0===a?void 0:a.map(((l,t)=>t===y?Object.assign(Object.assign({},l),{type:o,updatedValue:e}):l));null==Y||Y((e=>Object.assign(Object.assign({},e),{body:l,buttons:D.buttons})))}}function X(e,l){var t;const a=Object.assign({},Z),o=null===(t=null==a?void 0:a.components)||void 0===t?void 0:t.map((t=>{var a,o,n,i,u;const s=Object.assign({},t);if("BODY"===t.type&&(null===(o=null===(a=t.example)||void 0===a?void 0:a.body_text)||void 0===o?void 0:o[0])){const t=[...null!==(u=null===(i=null===(n=s.example)||void 0===n?void 0:n.body_text)||void 0===i?void 0:i[0])&&void 0!==u?u:[]];t[e]=l.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},s.example),{body_text:[t]});return Object.assign(Object.assign({},s),{example:a})}return t}));a.components=o,null==q||q(a)}return o((()=>{P&&(null==j||j())}),[P]),o((()=>{!function(){var e,l,t,a,o;const n="mobile"===z?"template_html_mobile":"template_html_desktop",i=document.getElementById(n),u=(null!==(a=null===(t=null===(l=null===(e=null==i?void 0:i.contentWindow)||void 0===e?void 0:e.document)||void 0===l?void 0:l.body)||void 0===t?void 0:t.innerHTML)&&void 0!==a?a:"")+(null===(o=null==i?void 0:i.contentWindow)||void 0===o?void 0:o.document.head.innerHTML);R===c.EMAIL&&(null==F||F(u))}()}),[G]),o((()=>{var e;const l=[];let t=[];if(R===c.MESSAGE){const e=null!=J?J:[];M([{label:"",options:[_,f]},...e]),t=[{label:"",options:[_,f]},...e]}else{"link"===(null==k?void 0:k.type)?(l.push({label:"",options:[f,_]}),$(f)):(l.push({label:"",options:[f,_]}),$(_));const e=null!=J?J:[];M([...l,...e.map((e=>{var l,t;return Object.assign(Object.assign({},e),{label:p.toCapitilize(null===(t=null===(l=e.label)||void 0===l?void 0:l.replace(/([A-Z])/g," $1"))||void 0===t?void 0:t.toLowerCase())})}))]),t=[...l,...e]}if((R===c.WHATSAPP||R===c.EMAIL||R===c.MESSAGE)&&k.updatedValue)if(r.test(k.updatedValue)&&R===c.WHATSAPP||k.updatedValue.startsWith("{{")&&R!==c.WHATSAPP){const e=function(e,l,t){var a;let o={label:"",value:""};const n=t===c.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");V?o={label:e.updatedValue?e.updatedValue.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}:l.map((e=>{e.options.map((e=>{var l;(null===(l=e.value)||void 0===l?void 0:l.replace("{{","").replace("}}","").trim())===n.trim()&&(o=e)}))}));return o}(k,t,R);e.value&&$(e)}else(null===(e=k.updatedValue)||void 0===e?void 0:e.startsWith("https"))?($(f),L(k.updatedValue.split("https://")[1])):($(_),L(k.updatedValue))}),[]),o((()=>{z&&W&&w&&setTimeout((()=>{Q("custom_link"===(null==W?void 0:W.value)?`https://${w}`:w,W.value)}),100)}),[z]),o((()=>{!B&&W&&k.updatedValue&&setTimeout((()=>{Q("custom_link"===(null==W?void 0:W.value)?`https://${k.updatedValue}`:k.updatedValue,W.value),N(!0)}),100)}),[W]),e(x,Object.assign({channel:R,focused:P,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1)},{children:[l("div",Object.assign({style:{marginBottom:8}},{children:e(m,Object.assign({style:{color:U&&!W?b.content.negative:b.content.primary}},{children:[null===(T=k.variableName)||void 0===T?void 0:T.replace("{{","").replace("}}","")," ","link"===(null==k?void 0:k.type)?"link":"variable"]}))})),l("div",Object.assign({style:{marginBottom:12}},{children:V?e("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==W?void 0:W.label)?"space-between":"flex-end"}},{children:[l(v,{children:d(null!==(E=null==W?void 0:W.label)&&void 0!==E?E:"",20,!0)}),l(t,{onClick:()=>{I(!H)},width:24,height:24,color:b.content.primary})]})):l(u,{options:C,isSearchable:!1,onSelect:K,defaultOptions:W?[Object.assign(Object.assign({},W),{selected:!0})]:[]})})),("custom_text"===(null==W?void 0:W.value)||"custom_link"===(null==W?void 0:W.value))&&l(s,{labelText:"custom_text"===(null==W?void 0:W.value)?"Custom text value":"custom_link"===(null==W?void 0:W.value)?"Custom URL value":"",id:`variable-value-${null==W?void 0:W.value}-${y}`,value:w,errorMessage:U?w&&0!==w.trim().length?"custom_link"!==W.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${w.trim()}`)&&0!==w.trim().length?"custom_link"!==W.value&&w.length>30?"Length cannot be more that 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==W?void 0:W.value)?void 0:30,prefixText:"custom_link"===(null==W?void 0:W.value)?"https://":"",placeholder:"link"===k.type||"custom_link"===W.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{console.log("valuevalue3: ",e),function(e,l){var t;L(l);const a="custom_link"===(null==W?void 0:W.value)?`https://${l}`:l;Q(a,e),R===c.WHATSAPP&&(null==X||X(null!==(t=k.index)&&void 0!==t?t:0,a))}(W.value,e)}}),H&&l(i,{zIndex:2e3,data:null!=A?A:[],showVariable:H,setShowVariable:I,placeholder:"Add a variable",customTrigger:e=>{O(!1),"{{custom.url}}"===e.actualValue?K({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?K({label:e.displayName,selected:!0,value:"custom_text"}):K({label:e.actualValue.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{x as Container,j as default};
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useState as i}from"react";import{BikShimmer as r}from"../shimmer/ShimmerComponent/BikShimmer.js";import{Button as n}from"../button/Button.js";import{TitleRegular as o}from"../TypographyStyle.js";import{EmailContainer as m,Header as l,IframeContainer as a,ImageContainer as s,CardLoadingContainer as d,ViewButton as h}from"./EmailTemplatePreview.styled.js";const p=p=>{let{template:c,handleViewTemplate:y,hideHeader:u,hideViewButton:j,containerStyle:b,emailHtmlContainerId:f,emailDisplayContent:g}=p;const[w,x]=i(!1);return e(m,Object.assign({hideHeader:u,style:Object.assign({},null!=b?b:{})},{children:[!u&&t(l,{children:t(o,Object.assign({style:{maxWidth:"100%"}},{children:c.name}))}),t(a,{children:g?w?t("iframe",{title:"Email template preview",id:null!=f?f:"",width:"100%",srcDoc:g,height:"100%",style:{pointerEvents:"none"},onLoad:()=>x(!0)}):t(r,{boxes:[{height:"64px",width:"100%",marginTop:"0px"}]}):t(s,Object.assign({hideHeader:u},{children:t(d,{})}))}),!j&&t(h,{children:t(n,{buttonType:"tertiary",buttonText:"View",onClick:()=>{y&&y()}})})]}))};export{p as default};
1
+ import{jsxs as e,jsx as t}from"react/jsx-runtime";import{Button as i}from"../button/Button.js";import{TitleRegular as n}from"../TypographyStyle.js";import{EmailContainer as r,Header as l,IframeContainer as a,ImageContainer as o,CardLoadingContainer as m,ViewButton as s}from"./EmailTemplatePreview.styled.js";const d=d=>{let{template:c,handleViewTemplate:h,hideHeader:p,hideViewButton:y,containerStyle:u,emailHtmlContainerId:j,emailDisplayContent:b}=d;return e(r,Object.assign({hideHeader:p,style:Object.assign({},null!=u?u:{})},{children:[!p&&t(l,{children:t(n,Object.assign({style:{maxWidth:"100%"}},{children:c.name}))}),t(a,{children:b?t("iframe",{title:"Email template preview",id:null!=j?j:"",width:"100%",srcDoc:b,height:"100%",style:{pointerEvents:"none"}}):t(o,Object.assign({hideHeader:p},{children:t(m,{})}))}),!y&&t(s,{children:t(i,{buttonType:"tertiary",buttonText:"View",onClick:()=>{h&&h()}})})]}))};export{d as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.314-beta.32",
3
+ "version": "0.0.314-beta.34",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",