@bikdotai/bik-component-library 0.0.314-beta.18 → 0.0.314-beta.20

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"),t=require("../../../assets/icons/edit.svg.js"),l=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"),r=require("../../TypographyStyle.js"),d=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"),t=require("../../../assets/icons/edit.svg.js"),l=require("react"),a=require("styled-components"),n=require("../../add-variableV2/AddVariableV2SideModal.js"),o=require("../../dropdown/Dropdown.js"),i=require("../../input/Input.js"),u=require("../../template-preview/constants/regexPatterns.js"),s=require("../../template-preview/models/Channels.js"),r=require("../../TypographyStyle.js"),d=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`
2
2
  /* surface/$color-background-warning-light */
3
3
 
4
4
  background: ${e=>e.focused&&e.channel===s.CHANNEL_TYPE.EMAIL?c.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 N;const[P,T]=l.useState(!1),[y,C]=l.useState(""),[L,f]=l.useState([]),[O,S]=l.useState(),[k,V]=l.useState(!1),{device:H,channel:w,isError:M,originalVariableList:q,template:Y,templateSelectionTriggered:I,setTemplate:W,setDisplayContent:B,setOriginalVariableList:R,globalNormalizedPlaceholders:$}=v.useTemplateModalContext();function z(e,t){var l,a,n;const i=e;C(""),S(i),w===s.CHANNEL_TYPE.WHATSAPP?"custom_text"!==i.value&&"custom_link"!==i.value?(D(null!==(l=i.value)&&void 0!==l?l:"","string"),null==U||U(null!==(a=h.index)&&void 0!==a?a:0,`[[${i.value}]]`)):(null==U||U(null!==(n=h.index)&&void 0!==n?n:0,h.variableName),D("","url"===i.bikPlaceholderType?"link":"string")):"custom_text"!==i.value&&"custom_link"!==i.value?D(i.value,"url"===i.bikPlaceholderType?"link":"string"):(C(""),D("",i.value))}function D(e,t){var l,a;const n="custom_link"===t?"link":"custom_text"===t?"string":t;if(w!==s.CHANNEL_TYPE.WHATSAPP){const a=p.getVariableNameForEmailByIndex(E+1),i=null===document||void 0===document?void 0:document.getElementById("mobile"===H?"template_html_mobile":"template_html_desktop"),o=w===s.CHANNEL_TYPE.EMAIL?null===(l=null==i?void 0:i.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);o&&(o.textContent="custom_text"!==t&&"custom_link"!==t||e?e:h.variableName);const u=q.map(((t,l)=>l===E?Object.assign(Object.assign({},t),{type:n,updatedValue:e}):t));null==R||R(u)}if(w===s.CHANNEL_TYPE.WHATSAPP){const t=null===(a=q.body)||void 0===a?void 0:a.map(((t,l)=>l===E?Object.assign(Object.assign({},t),{type:n,updatedValue:e}):t));null==R||R((e=>Object.assign(Object.assign({},e),{body:t,buttons:q.buttons})))}}function U(e,t){var l;const a=Object.assign({},Y),n=null===(l=null==a?void 0:a.components)||void 0===l?void 0:l.map((l=>{var a,n,i,o,u;const s=Object.assign({},l);if("BODY"===l.type&&(null===(n=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===n?void 0:n[0])){const l=[...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:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},s.example),{body_text:[l]});return Object.assign(Object.assign({},s),{example:a})}return l}));a.components=n,null==W||W(a)}return l.useEffect((()=>{P&&(null==m||m())}),[P]),l.useEffect((()=>{!function(){var e,t,l,a,n;const i="mobile"===H?"template_html_mobile":"template_html_desktop",o=document.getElementById(i),u=(null!==(a=null===(l=null===(t=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(n=null==o?void 0:o.contentWindow)||void 0===n?void 0:n.document.head.innerHTML);w===s.CHANNEL_TYPE.EMAIL&&(null==B||B(u))}()}),[I]),l.useEffect((()=>{var e;const t=[];let l=[];if(w===s.CHANNEL_TYPE.MESSAGE){const e=null!=$?$:[];f([{label:"",options:[x,g]},...e]),l=[{label:"",options:[x,g]},...e]}else{"link"===(null==h?void 0:h.type)?(t.push({label:"",options:[g,x]}),S(g)):(t.push({label:"",options:[g,x]}),S(x));const e=null!=$?$:[];f([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:d.default.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}if((w===s.CHANNEL_TYPE.WHATSAPP||w===s.CHANNEL_TYPE.EMAIL||w===s.CHANNEL_TYPE.MESSAGE)&&h.updatedValue)if(u.placeHolderNamePattern.test(h.updatedValue)&&w===s.CHANNEL_TYPE.WHATSAPP||h.updatedValue.startsWith("{{")&&w!==s.CHANNEL_TYPE.WHATSAPP){const e=function(e,t,l){var a;let n={label:"",value:""};const i=l===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:""}:t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===i.trim()&&(n=e)}))}));return n}(h,l,w);e.value&&S(e)}else(null===(e=h.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(S(g),C(h.updatedValue.split("https://")[1])):(S(x),C(h.updatedValue))}),[]),e.jsxs(b,Object.assign({channel:w,focused:P,onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(r.BodySecondary,Object.assign({style:{color:M&&!O?c.COLORS.content.negative:c.COLORS.content.primary}},{children:[null===(N=h.variableName)||void 0===N?void 0:N.replace("{{","").replace("}}","")," ","link"===(null==h?void 0:h.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:_?e.jsx(o.Input,{state:"none",value:O?O.label:"Custom text",onChangeText:()=>{},onFocus:()=>{V(!k)},rightIcon:{icon:()=>e.jsx(t.default,{onClick:()=>{V(!k)},width:24,height:24,color:c.COLORS.content.primary})}}):e.jsx(i.Dropdown,{options:L,isSearchable:!1,onSelect:z,defaultOptions:O?[Object.assign(Object.assign({},O),{selected:!0})]:[]})})),("custom_text"===(null==O?void 0:O.value)||"custom_link"===(null==O?void 0:O.value))&&e.jsx(o.Input,{labelText:"custom_text"===(null==O?void 0:O.value)?"Custom text value":"custom_link"===(null==O?void 0:O.value)?"Custom URL value":"",id:`variable-value-${null==O?void 0:O.value}-${E}`,value:y,errorMessage:M?y?"custom_link"!==O.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(y.trim())&&0!==y.trim().length?y.length>30?"Length cannot be more that 30":30===y.trim().length?"Required field":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==O?void 0:O.value)?void 0:30,prefixText:"custom_link"===(null==O?void 0:O.value)?"https://":"",placeholder:"link"===h.type||"custom_link"===O.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>function(e,t){var l;C(t);const a="custom_link"===(null==O?void 0:O.value)?`https://${t}`:t;D(a,e),w===s.CHANNEL_TYPE.WHATSAPP&&(null==U||U(null!==(l=h.index)&&void 0!==l?l:0,a))}(O.value,e)}),k&&e.jsx(n.AddVariableV2SideModal,{zIndex:2e3,data:null!=j?j:[],showVariable:k,setShowVariable:V,placeholder:"Add a variable",customTrigger:e=>{A(!1),"{{custom.url}}"===e.actualValue?z({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?z({label:e.displayName,selected:!0,value:"custom_text"}):z({label:e.actualValue.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};
7
+ `,g={value:"custom_link",label:"Custom URL"},h={value:"custom_text",label:"Custom text"};exports.Container=b,exports.default=a=>{let{onFocus:m,variable:x,index:E,showVariableModal:_,variableList:j,setShowDiscountCheckBox:A}=a;var T;const[N,P]=l.useState(!1),[f,y]=l.useState(""),[C,L]=l.useState([]),[O,k]=l.useState(),[S,V]=l.useState(!1),{device:H,channel:w,isError:M,originalVariableList:q,template:Y,templateSelectionTriggered:I,setTemplate:W,setDisplayContent:B,setOriginalVariableList:R,globalNormalizedPlaceholders:$}=v.useTemplateModalContext();function z(e,t){var l,a,n;const o=e;y(""),k(o),w===s.CHANNEL_TYPE.WHATSAPP?"custom_text"!==o.value&&"custom_link"!==o.value?(D(null!==(l=o.value)&&void 0!==l?l:"","string"),null==U||U(null!==(a=x.index)&&void 0!==a?a:0,`[[${o.value}]]`)):(null==U||U(null!==(n=x.index)&&void 0!==n?n:0,x.variableName),D("","url"===o.bikPlaceholderType?"link":"string")):"custom_text"!==o.value&&"custom_link"!==o.value?D(o.value,"url"===o.bikPlaceholderType?"link":"string"):(y(""),D("",o.value))}function D(e,t){var l,a;const n="custom_link"===t?"link":"custom_text"===t?"string":t;if(w!==s.CHANNEL_TYPE.WHATSAPP){const a=p.getVariableNameForEmailByIndex(E+1),o=null===document||void 0===document?void 0:document.getElementById("mobile"===H?"template_html_mobile":"template_html_desktop"),i=w===s.CHANNEL_TYPE.EMAIL?null===(l=null==o?void 0:o.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);i&&(i.textContent="custom_text"!==t&&"custom_link"!==t||e?e:x.variableName);const u=q.map(((t,l)=>l===E?Object.assign(Object.assign({},t),{type:n,updatedValue:e}):t));null==R||R(u)}if(w===s.CHANNEL_TYPE.WHATSAPP){const t=null===(a=q.body)||void 0===a?void 0:a.map(((t,l)=>l===E?Object.assign(Object.assign({},t),{type:n,updatedValue:e}):t));null==R||R((e=>Object.assign(Object.assign({},e),{body:t,buttons:q.buttons})))}}function U(e,t){var l;const a=Object.assign({},Y),n=null===(l=null==a?void 0:a.components)||void 0===l?void 0:l.map((l=>{var a,n,o,i,u;const s=Object.assign({},l);if("BODY"===l.type&&(null===(n=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===n?void 0:n[0])){const l=[...null!==(u=null===(i=null===(o=s.example)||void 0===o?void 0:o.body_text)||void 0===i?void 0:i[0])&&void 0!==u?u:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},s.example),{body_text:[l]});return Object.assign(Object.assign({},s),{example:a})}return l}));a.components=n,null==W||W(a)}return l.useEffect((()=>{N&&(null==m||m())}),[N]),l.useEffect((()=>{!function(){var e,t,l,a,n;const o="mobile"===H?"template_html_mobile":"template_html_desktop",i=document.getElementById(o),u=(null!==(a=null===(l=null===(t=null===(e=null==i?void 0:i.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(n=null==i?void 0:i.contentWindow)||void 0===n?void 0:n.document.head.innerHTML);w===s.CHANNEL_TYPE.EMAIL&&(null==B||B(u))}()}),[I]),l.useEffect((()=>{var e;const t=[];let l=[];if(w===s.CHANNEL_TYPE.MESSAGE){const e=null!=$?$:[];L([{label:"",options:[h,g]},...e]),l=[{label:"",options:[h,g]},...e]}else{"link"===(null==x?void 0:x.type)?(t.push({label:"",options:[g,h]}),k(g)):(t.push({label:"",options:[g,h]}),k(h));const e=null!=$?$:[];L([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:d.default.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}if((w===s.CHANNEL_TYPE.WHATSAPP||w===s.CHANNEL_TYPE.EMAIL||w===s.CHANNEL_TYPE.MESSAGE)&&x.updatedValue)if(u.placeHolderNamePattern.test(x.updatedValue)&&w===s.CHANNEL_TYPE.WHATSAPP||x.updatedValue.startsWith("{{")&&w!==s.CHANNEL_TYPE.WHATSAPP){const e=function(e,t,l){var a;let n={label:"",value:""};const o=l===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:""}:t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===o.trim()&&(n=e)}))}));return n}(x,l,w);e.value&&k(e)}else(null===(e=x.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(k(g),y(x.updatedValue.split("https://")[1])):(k(h),y(x.updatedValue))}),[]),l.useEffect((()=>{H&&O&&f&&setTimeout((()=>{D("custom_link"===(null==O?void 0:O.value)?`https://${f}`:f,O.value)}),100)}),[H]),e.jsxs(b,Object.assign({channel:w,focused:N,onMouseEnter:()=>P(!0),onMouseLeave:()=>P(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(r.BodySecondary,Object.assign({style:{color:M&&!O?c.COLORS.content.negative:c.COLORS.content.primary}},{children:[null===(T=x.variableName)||void 0===T?void 0:T.replace("{{","").replace("}}","")," ","link"===(null==x?void 0:x.type)?"link":"variable"]}))})),e.jsx("div",Object.assign({style:{marginBottom:12}},{children:_?e.jsx(i.Input,{state:"none",value:O?O.label:"Custom text",onChangeText:e=>{},onFocus:()=>{V(!S)},rightIcon:{icon:()=>e.jsx(t.default,{onClick:()=>{V(!S)},width:24,height:24,color:c.COLORS.content.primary})}}):e.jsx(o.Dropdown,{options:C,isSearchable:!1,onSelect:z,defaultOptions:O?[Object.assign(Object.assign({},O),{selected:!0})]:[]})})),("custom_text"===(null==O?void 0:O.value)||"custom_link"===(null==O?void 0:O.value))&&e.jsx(i.Input,{labelText:"custom_text"===(null==O?void 0:O.value)?"Custom text value":"custom_link"===(null==O?void 0:O.value)?"Custom URL value":"",id:`variable-value-${null==O?void 0:O.value}-${E}`,value:f,errorMessage:M?f&&0!==f.trim().length?"custom_link"!==O.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${f.trim()}`)&&0!==f.trim().length?f.length>30?"Length cannot be more that 30":30===f.trim().length?"Required field":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==O?void 0:O.value)?void 0:30,prefixText:"custom_link"===(null==O?void 0:O.value)?"https://":"",placeholder:"link"===x.type||"custom_link"===O.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{console.log("valuevalue3: ",e),function(e,t){var l;y(t);const a="custom_link"===(null==O?void 0:O.value)?`https://${t}`:t;D(a,e),w===s.CHANNEL_TYPE.WHATSAPP&&(null==U||U(null!==(l=x.index)&&void 0!==l?l:0,a))}(O.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?z({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?z({label:e.displayName,selected:!0,value:"custom_text"}):z({label:e.actualValue.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};
@@ -4,4 +4,4 @@ import{jsxs as e,jsx as t}from"react/jsx-runtime";import l from"../../../assets/
4
4
  background: ${e=>e.focused&&e.channel===d.EMAIL?v.background.warning.light:"transparent"};
5
5
  border-radius: 4px;
6
6
  padding: 8px 10px;
7
- `,h={value:"custom_link",label:"Custom URL"},x={value:"custom_text",label:"Custom text"},f=n=>{let{onFocus:f,variable:_,index:j,showVariableModal:y,variableList:k,setShowDiscountCheckBox:A}=n;var V;const[O,T]=a(!1),[P,S]=a(""),[w,E]=a([]),[L,C]=a(),[M,W]=a(!1),{device:I,channel:H,isError:B,originalVariableList:$,template:N,templateSelectionTriggered:z,setTemplate:R,setDisplayContent:U,setOriginalVariableList:D,globalNormalizedPlaceholders:Z}=p();function q(e,t){var l,a,o;const n=e;S(""),C(n),H===d.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(F(null!==(l=n.value)&&void 0!==l?l:"","string"),null==G||G(null!==(a=_.index)&&void 0!==a?a:0,`[[${n.value}]]`)):(null==G||G(null!==(o=_.index)&&void 0!==o?o:0,_.variableName),F("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?F(n.value,"url"===n.bikPlaceholderType?"link":"string"):(S(""),F("",n.value))}function F(e,t){var l,a;const o="custom_link"===t?"link":"custom_text"===t?"string":t;if(H!==d.WHATSAPP){const a=b(j+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===I?"template_html_mobile":"template_html_desktop"),i=H===d.EMAIL?null===(l=null==n?void 0:n.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);i&&(i.textContent="custom_text"!==t&&"custom_link"!==t||e?e:_.variableName);const u=$.map(((t,l)=>l===j?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==D||D(u)}if(H===d.WHATSAPP){const t=null===(a=$.body)||void 0===a?void 0:a.map(((t,l)=>l===j?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==D||D((e=>Object.assign(Object.assign({},e),{body:t,buttons:$.buttons})))}}function G(e,t){var l;const a=Object.assign({},N),o=null===(l=null==a?void 0:a.components)||void 0===l?void 0:l.map((l=>{var a,o,n,i,u;const s=Object.assign({},l);if("BODY"===l.type&&(null===(o=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===o?void 0:o[0])){const l=[...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:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},s.example),{body_text:[l]});return Object.assign(Object.assign({},s),{example:a})}return l}));a.components=o,null==R||R(a)}return o((()=>{O&&(null==f||f())}),[O]),o((()=>{!function(){var e,t,l,a,o;const n="mobile"===I?"template_html_mobile":"template_html_desktop",i=document.getElementById(n),u=(null!==(a=null===(l=null===(t=null===(e=null==i?void 0:i.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(o=null==i?void 0:i.contentWindow)||void 0===o?void 0:o.document.head.innerHTML);H===d.EMAIL&&(null==U||U(u))}()}),[z]),o((()=>{var e;const t=[];let l=[];if(H===d.MESSAGE){const e=null!=Z?Z:[];E([{label:"",options:[x,h]},...e]),l=[{label:"",options:[x,h]},...e]}else{"link"===(null==_?void 0:_.type)?(t.push({label:"",options:[h,x]}),C(h)):(t.push({label:"",options:[h,x]}),C(x));const e=null!=Z?Z:[];E([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:m.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}if((H===d.WHATSAPP||H===d.EMAIL||H===d.MESSAGE)&&_.updatedValue)if(r.test(_.updatedValue)&&H===d.WHATSAPP||_.updatedValue.startsWith("{{")&&H!==d.WHATSAPP){const e=function(e,t,l){var a;let o={label:"",value:""};const n=l===d.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");y?o={label:e.updatedValue?e.updatedValue.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}:t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(o=e)}))}));return o}(_,l,H);e.value&&C(e)}else(null===(e=_.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(C(h),S(_.updatedValue.split("https://")[1])):(C(x),S(_.updatedValue))}),[]),e(g,Object.assign({channel:H,focused:O,onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1)},{children:[t("div",Object.assign({style:{marginBottom:8}},{children:e(c,Object.assign({style:{color:B&&!L?v.content.negative:v.content.primary}},{children:[null===(V=_.variableName)||void 0===V?void 0:V.replace("{{","").replace("}}","")," ","link"===(null==_?void 0:_.type)?"link":"variable"]}))})),t("div",Object.assign({style:{marginBottom:12}},{children:y?t(s,{state:"none",value:L?L.label:"Custom text",onChangeText:()=>{},onFocus:()=>{W(!M)},rightIcon:{icon:()=>t(l,{onClick:()=>{W(!M)},width:24,height:24,color:v.content.primary})}}):t(u,{options:w,isSearchable:!1,onSelect:q,defaultOptions:L?[Object.assign(Object.assign({},L),{selected:!0})]:[]})})),("custom_text"===(null==L?void 0:L.value)||"custom_link"===(null==L?void 0:L.value))&&t(s,{labelText:"custom_text"===(null==L?void 0:L.value)?"Custom text value":"custom_link"===(null==L?void 0:L.value)?"Custom URL value":"",id:`variable-value-${null==L?void 0:L.value}-${j}`,value:P,errorMessage:B?P?"custom_link"!==L.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(P.trim())&&0!==P.trim().length?P.length>30?"Length cannot be more that 30":30===P.trim().length?"Required field":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==L?void 0:L.value)?void 0:30,prefixText:"custom_link"===(null==L?void 0:L.value)?"https://":"",placeholder:"link"===_.type||"custom_link"===L.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>function(e,t){var l;S(t);const a="custom_link"===(null==L?void 0:L.value)?`https://${t}`:t;F(a,e),H===d.WHATSAPP&&(null==G||G(null!==(l=_.index)&&void 0!==l?l:0,a))}(L.value,e)}),M&&t(i,{zIndex:2e3,data:null!=k?k:[],showVariable:M,setShowVariable:W,placeholder:"Add a variable",customTrigger:e=>{A(!1),"{{custom.url}}"===e.actualValue?q({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?q({label:e.displayName,selected:!0,value:"custom_text"}):q({label:e.actualValue.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{g as Container,f as default};
7
+ `,h={value:"custom_link",label:"Custom URL"},x={value:"custom_text",label:"Custom text"},_=n=>{let{onFocus:_,variable:f,index:j,showVariableModal:k,variableList:y,setShowDiscountCheckBox:A}=n;var V;const[O,T]=a(!1),[P,S]=a(""),[w,E]=a([]),[L,C]=a(),[M,W]=a(!1),{device:I,channel:H,isError:$,originalVariableList:B,template:N,templateSelectionTriggered:z,setTemplate:R,setDisplayContent:U,setOriginalVariableList:D,globalNormalizedPlaceholders:Z}=p();function q(e,t){var l,a,o;const n=e;S(""),C(n),H===d.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(F(null!==(l=n.value)&&void 0!==l?l:"","string"),null==G||G(null!==(a=f.index)&&void 0!==a?a:0,`[[${n.value}]]`)):(null==G||G(null!==(o=f.index)&&void 0!==o?o:0,f.variableName),F("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?F(n.value,"url"===n.bikPlaceholderType?"link":"string"):(S(""),F("",n.value))}function F(e,t){var l,a;const o="custom_link"===t?"link":"custom_text"===t?"string":t;if(H!==d.WHATSAPP){const a=b(j+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===I?"template_html_mobile":"template_html_desktop"),i=H===d.EMAIL?null===(l=null==n?void 0:n.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);i&&(i.textContent="custom_text"!==t&&"custom_link"!==t||e?e:f.variableName);const u=B.map(((t,l)=>l===j?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==D||D(u)}if(H===d.WHATSAPP){const t=null===(a=B.body)||void 0===a?void 0:a.map(((t,l)=>l===j?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==D||D((e=>Object.assign(Object.assign({},e),{body:t,buttons:B.buttons})))}}function G(e,t){var l;const a=Object.assign({},N),o=null===(l=null==a?void 0:a.components)||void 0===l?void 0:l.map((l=>{var a,o,n,i,u;const s=Object.assign({},l);if("BODY"===l.type&&(null===(o=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===o?void 0:o[0])){const l=[...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:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},s.example),{body_text:[l]});return Object.assign(Object.assign({},s),{example:a})}return l}));a.components=o,null==R||R(a)}return o((()=>{O&&(null==_||_())}),[O]),o((()=>{!function(){var e,t,l,a,o;const n="mobile"===I?"template_html_mobile":"template_html_desktop",i=document.getElementById(n),u=(null!==(a=null===(l=null===(t=null===(e=null==i?void 0:i.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(o=null==i?void 0:i.contentWindow)||void 0===o?void 0:o.document.head.innerHTML);H===d.EMAIL&&(null==U||U(u))}()}),[z]),o((()=>{var e;const t=[];let l=[];if(H===d.MESSAGE){const e=null!=Z?Z:[];E([{label:"",options:[x,h]},...e]),l=[{label:"",options:[x,h]},...e]}else{"link"===(null==f?void 0:f.type)?(t.push({label:"",options:[h,x]}),C(h)):(t.push({label:"",options:[h,x]}),C(x));const e=null!=Z?Z:[];E([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:m.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}if((H===d.WHATSAPP||H===d.EMAIL||H===d.MESSAGE)&&f.updatedValue)if(r.test(f.updatedValue)&&H===d.WHATSAPP||f.updatedValue.startsWith("{{")&&H!==d.WHATSAPP){const e=function(e,t,l){var a;let o={label:"",value:""};const n=l===d.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:""}:t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(o=e)}))}));return o}(f,l,H);e.value&&C(e)}else(null===(e=f.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(C(h),S(f.updatedValue.split("https://")[1])):(C(x),S(f.updatedValue))}),[]),o((()=>{I&&L&&P&&setTimeout((()=>{F("custom_link"===(null==L?void 0:L.value)?`https://${P}`:P,L.value)}),100)}),[I]),e(g,Object.assign({channel:H,focused:O,onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1)},{children:[t("div",Object.assign({style:{marginBottom:8}},{children:e(c,Object.assign({style:{color:$&&!L?v.content.negative:v.content.primary}},{children:[null===(V=f.variableName)||void 0===V?void 0:V.replace("{{","").replace("}}","")," ","link"===(null==f?void 0:f.type)?"link":"variable"]}))})),t("div",Object.assign({style:{marginBottom:12}},{children:k?t(s,{state:"none",value:L?L.label:"Custom text",onChangeText:e=>{},onFocus:()=>{W(!M)},rightIcon:{icon:()=>t(l,{onClick:()=>{W(!M)},width:24,height:24,color:v.content.primary})}}):t(u,{options:w,isSearchable:!1,onSelect:q,defaultOptions:L?[Object.assign(Object.assign({},L),{selected:!0})]:[]})})),("custom_text"===(null==L?void 0:L.value)||"custom_link"===(null==L?void 0:L.value))&&t(s,{labelText:"custom_text"===(null==L?void 0:L.value)?"Custom text value":"custom_link"===(null==L?void 0:L.value)?"Custom URL value":"",id:`variable-value-${null==L?void 0:L.value}-${j}`,value:P,errorMessage:$?P&&0!==P.trim().length?"custom_link"!==L.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?P.length>30?"Length cannot be more that 30":30===P.trim().length?"Required field":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==L?void 0:L.value)?void 0:30,prefixText:"custom_link"===(null==L?void 0:L.value)?"https://":"",placeholder:"link"===f.type||"custom_link"===L.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{console.log("valuevalue3: ",e),function(e,t){var l;S(t);const a="custom_link"===(null==L?void 0:L.value)?`https://${t}`:t;F(a,e),H===d.WHATSAPP&&(null==G||G(null!==(l=f.index)&&void 0!==l?l:0,a))}(L.value,e)}}),M&&t(i,{zIndex:2e3,data:null!=y?y:[],showVariable:M,setShowVariable:W,placeholder:"Add a variable",customTrigger:e=>{A(!1),"{{custom.url}}"===e.actualValue?q({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?q({label:e.displayName,selected:!0,value:"custom_text"}):q({label:e.actualValue.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{g as Container,_ 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.18",
3
+ "version": "0.0.314-beta.20",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",