@bikdotai/bik-component-library 0.0.314-beta.21 → 0.0.314-beta.22

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"),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`
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"),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`
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"},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[f,N]=l.useState(!1),[P,y]=l.useState(""),[C,L]=l.useState([]),[k,O]=l.useState(),[S,V]=l.useState(!1),[H,w]=l.useState(!1),{device:M,channel:q,isError:Y,originalVariableList:I,template:W,templateSelectionTriggered:$,setTemplate:B,setDisplayContent:R,setOriginalVariableList:z,globalNormalizedPlaceholders:D}=v.useTemplateModalContext();function U(e,t){var l,a,n;const o=e;y(""),O(o),q===s.CHANNEL_TYPE.WHATSAPP?"custom_text"!==o.value&&"custom_link"!==o.value?(Z(null!==(l=o.value)&&void 0!==l?l:"","string"),null==F||F(null!==(a=x.index)&&void 0!==a?a:0,`[[${o.value}]]`)):(null==F||F(null!==(n=x.index)&&void 0!==n?n:0,x.variableName),Z("","url"===o.bikPlaceholderType?"link":"string")):"custom_text"!==o.value&&"custom_link"!==o.value?Z(o.value,"url"===o.bikPlaceholderType?"link":"string"):(y(""),Z("",o.value))}function Z(e,t){var l,a;const n="custom_link"===t?"link":"custom_text"===t?"string":t;if(q!==s.CHANNEL_TYPE.WHATSAPP){const a=p.getVariableNameForEmailByIndex(E+1),o=null===document||void 0===document?void 0:document.getElementById("mobile"===M?"template_html_mobile":"template_html_desktop"),i=q===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=I.map(((t,l)=>l===E?Object.assign(Object.assign({},t),{type:n,updatedValue:e}):t));null==z||z(u)}if(q===s.CHANNEL_TYPE.WHATSAPP){const t=null===(a=I.body)||void 0===a?void 0:a.map(((t,l)=>l===E?Object.assign(Object.assign({},t),{type:n,updatedValue:e}):t));null==z||z((e=>Object.assign(Object.assign({},e),{body:t,buttons:I.buttons})))}}function F(e,t){var l;const a=Object.assign({},W),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==B||B(a)}return l.useEffect((()=>{f&&(null==m||m())}),[f]),l.useEffect((()=>{!function(){var e,t,l,a,n;const o="mobile"===M?"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);q===s.CHANNEL_TYPE.EMAIL&&(null==R||R(u))}()}),[$]),l.useEffect((()=>{var e;const t=[];let l=[];if(q===s.CHANNEL_TYPE.MESSAGE){const e=null!=D?D:[];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]}),O(g)):(t.push({label:"",options:[g,h]}),O(h));const e=null!=D?D:[];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((q===s.CHANNEL_TYPE.WHATSAPP||q===s.CHANNEL_TYPE.EMAIL||q===s.CHANNEL_TYPE.MESSAGE)&&x.updatedValue)if(u.placeHolderNamePattern.test(x.updatedValue)&&q===s.CHANNEL_TYPE.WHATSAPP||x.updatedValue.startsWith("{{")&&q!==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,q);e.value&&O(e)}else(null===(e=x.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(O(g),y(x.updatedValue.split("https://")[1])):(O(h),y(x.updatedValue))}),[]),l.useEffect((()=>{M&&k&&P&&setTimeout((()=>{Z("custom_link"===(null==k?void 0:k.value)?`https://${P}`:P,k.value)}),100)}),[M]),l.useEffect((()=>{!H&&k&&P&&setTimeout((()=>{Z("custom_link"===(null==k?void 0:k.value)?`https://${P}`:P,k.value),w(!0)}),100)}),[H]),e.jsxs(b,Object.assign({channel:q,focused:f,onMouseEnter:()=>N(!0),onMouseLeave:()=>N(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(r.BodySecondary,Object.assign({style:{color:Y&&!k?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:k?k.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: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(i.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:P,errorMessage:Y?P&&0!==P.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://${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==k?void 0:k.value)?void 0:30,prefixText:"custom_link"===(null==k?void 0:k.value)?"https://":"",placeholder:"link"===x.type||"custom_link"===k.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==k?void 0:k.value)?`https://${t}`:t;Z(a,e),q===s.CHANNEL_TYPE.WHATSAPP&&(null==F||F(null!==(l=x.index)&&void 0!==l?l: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
+ `,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[f,N]=l.useState(!1),[P,y]=l.useState(""),[C,L]=l.useState([]),[V,O]=l.useState(),[k,S]=l.useState(!1),[H,w]=l.useState(!1),{device:M,channel:q,isError:Y,originalVariableList:I,template:W,templateSelectionTriggered:$,setTemplate:B,setDisplayContent:R,setOriginalVariableList:z,globalNormalizedPlaceholders:D}=v.useTemplateModalContext();function U(e,t){var l,a,n;const o=e;y(""),O(o),q===s.CHANNEL_TYPE.WHATSAPP?"custom_text"!==o.value&&"custom_link"!==o.value?(F(null!==(l=o.value)&&void 0!==l?l:"","string"),null==Z||Z(null!==(a=x.index)&&void 0!==a?a:0,`[[${o.value}]]`)):(null==Z||Z(null!==(n=x.index)&&void 0!==n?n:0,x.variableName),F("","url"===o.bikPlaceholderType?"link":"string")):"custom_text"!==o.value&&"custom_link"!==o.value?F(o.value,"url"===o.bikPlaceholderType?"link":"string"):(y(""),F("",o.value))}function F(e,t){var l,a;const n="custom_link"===t?"link":"custom_text"===t?"string":t;if(q!==s.CHANNEL_TYPE.WHATSAPP){const a=p.getVariableNameForEmailByIndex(E+1),o=null===document||void 0===document?void 0:document.getElementById("mobile"===M?"template_html_mobile":"template_html_desktop"),i=q===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=I.map(((t,l)=>l===E?Object.assign(Object.assign({},t),{type:n,updatedValue:e}):t));null==z||z(u)}if(q===s.CHANNEL_TYPE.WHATSAPP){const t=null===(a=I.body)||void 0===a?void 0:a.map(((t,l)=>l===E?Object.assign(Object.assign({},t),{type:n,updatedValue:e}):t));null==z||z((e=>Object.assign(Object.assign({},e),{body:t,buttons:I.buttons})))}}function Z(e,t){var l;const a=Object.assign({},W),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==B||B(a)}return l.useEffect((()=>{f&&(null==m||m())}),[f]),l.useEffect((()=>{!function(){var e,t,l,a,n;const o="mobile"===M?"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);q===s.CHANNEL_TYPE.EMAIL&&(null==R||R(u))}()}),[$]),l.useEffect((()=>{var e;const t=[];let l=[];if(q===s.CHANNEL_TYPE.MESSAGE){const e=null!=D?D:[];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]}),O(g)):(t.push({label:"",options:[g,h]}),O(h));const e=null!=D?D:[];L([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:r.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((q===s.CHANNEL_TYPE.WHATSAPP||q===s.CHANNEL_TYPE.EMAIL||q===s.CHANNEL_TYPE.MESSAGE)&&x.updatedValue)if(u.placeHolderNamePattern.test(x.updatedValue)&&q===s.CHANNEL_TYPE.WHATSAPP||x.updatedValue.startsWith("{{")&&q!==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,q);e.value&&O(e)}else(null===(e=x.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(O(g),y(x.updatedValue.split("https://")[1])):(O(h),y(x.updatedValue))}),[]),l.useEffect((()=>{M&&V&&P&&setTimeout((()=>{F("custom_link"===(null==V?void 0:V.value)?`https://${P}`:P,V.value)}),100)}),[M]),l.useEffect((()=>{console.log("renderFirstTime: ",H),console.log("selectedOption: ",V),console.log("variable.updatedValue: ",x.updatedValue),!H&&V&&x.updatedValue&&setTimeout((()=>{F("custom_link"===(null==V?void 0:V.value)?`https://${x.updatedValue}`:x.updatedValue,V.value),w(!0)}),100)}),[H]),e.jsxs(b,Object.assign({channel:q,focused:f,onMouseEnter:()=>N(!0),onMouseLeave:()=>N(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsxs(d.BodySecondary,Object.assign({style:{color:Y&&!V?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:V?V.label:"Custom text",onChangeText:e=>{},onFocus:()=>{S(!k)},rightIcon:{icon:()=>e.jsx(t.default,{onClick:()=>{S(!k)},width:24,height:24,color:c.COLORS.content.primary})}}):e.jsx(o.Dropdown,{options:C,isSearchable:!1,onSelect:U,defaultOptions:V?[Object.assign(Object.assign({},V),{selected:!0})]:[]})})),("custom_text"===(null==V?void 0:V.value)||"custom_link"===(null==V?void 0:V.value))&&e.jsx(i.Input,{labelText:"custom_text"===(null==V?void 0:V.value)?"Custom text value":"custom_link"===(null==V?void 0:V.value)?"Custom URL value":"",id:`variable-value-${null==V?void 0:V.value}-${E}`,value:P,errorMessage:Y?P&&0!==P.trim().length?"custom_link"!==V.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==V?void 0:V.value)?void 0:30,prefixText:"custom_link"===(null==V?void 0:V.value)?"https://":"",placeholder:"link"===x.type||"custom_link"===V.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==V?void 0:V.value)?`https://${t}`:t;F(a,e),q===s.CHANNEL_TYPE.WHATSAPP&&(null==Z||Z(null!==(l=x.index)&&void 0!==l?l:0,a))}(V.value,e)}}),k&&e.jsx(n.AddVariableV2SideModal,{zIndex:2e3,data:null!=j?j:[],showVariable:k,setShowVariable:S,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"})}})]}))};
@@ -1,7 +1,7 @@
1
- import{jsxs as e,jsx as t}from"react/jsx-runtime";import l 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 r}from"../../template-preview/constants/regexPatterns.js";import{CHANNEL_TYPE as d}from"../../template-preview/models/Channels.js";import{BodySecondary as c}from"../../TypographyStyle.js";import m from"../../../utils/StringUtils.js";import{COLORS as v}from"../../../constants/Theme.js";import{useTemplateModalContext as p}from"../context/templateModalContext.js";import{getVariableNameForEmailByIndex as b}from"../utils/getVariableNameEmail.js";const g=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{placeHolderNamePattern as d}from"../../template-preview/constants/regexPatterns.js";import{CHANNEL_TYPE as r}from"../../template-preview/models/Channels.js";import{BodySecondary as c}from"../../TypographyStyle.js";import m from"../../../utils/StringUtils.js";import{COLORS as v}from"../../../constants/Theme.js";import{useTemplateModalContext as p}from"../context/templateModalContext.js";import{getVariableNameForEmailByIndex as b}from"../utils/getVariableNameEmail.js";const g=n.div`
2
2
  /* surface/$color-background-warning-light */
3
3
 
4
- background: ${e=>e.focused&&e.channel===d.EMAIL?v.background.warning.light:"transparent"};
4
+ background: ${e=>e.focused&&e.channel===r.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"},_=n=>{let{onFocus:_,variable:f,index:j,showVariableModal:k,variableList:y,setShowDiscountCheckBox:A}=n;var V;const[T,O]=a(!1),[P,S]=a(""),[w,E]=a([]),[L,C]=a(),[M,W]=a(!1),[I,$]=a(!1),{device:H,channel:B,isError:N,originalVariableList:z,template:R,templateSelectionTriggered:U,setTemplate:D,setDisplayContent:Z,setOriginalVariableList:q,globalNormalizedPlaceholders:F}=p();function G(e,t){var l,a,o;const n=e;S(""),C(n),B===d.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(Y(null!==(l=n.value)&&void 0!==l?l:"","string"),null==J||J(null!==(a=f.index)&&void 0!==a?a:0,`[[${n.value}]]`)):(null==J||J(null!==(o=f.index)&&void 0!==o?o:0,f.variableName),Y("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?Y(n.value,"url"===n.bikPlaceholderType?"link":"string"):(S(""),Y("",n.value))}function Y(e,t){var l,a;const o="custom_link"===t?"link":"custom_text"===t?"string":t;if(B!==d.WHATSAPP){const a=b(j+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===H?"template_html_mobile":"template_html_desktop"),i=B===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=z.map(((t,l)=>l===j?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==q||q(u)}if(B===d.WHATSAPP){const t=null===(a=z.body)||void 0===a?void 0:a.map(((t,l)=>l===j?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==q||q((e=>Object.assign(Object.assign({},e),{body:t,buttons:z.buttons})))}}function J(e,t){var l;const a=Object.assign({},R),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==D||D(a)}return o((()=>{T&&(null==_||_())}),[T]),o((()=>{!function(){var e,t,l,a,o;const n="mobile"===H?"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);B===d.EMAIL&&(null==Z||Z(u))}()}),[U]),o((()=>{var e;const t=[];let l=[];if(B===d.MESSAGE){const e=null!=F?F:[];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!=F?F:[];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((B===d.WHATSAPP||B===d.EMAIL||B===d.MESSAGE)&&f.updatedValue)if(r.test(f.updatedValue)&&B===d.WHATSAPP||f.updatedValue.startsWith("{{")&&B!==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,B);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((()=>{H&&L&&P&&setTimeout((()=>{Y("custom_link"===(null==L?void 0:L.value)?`https://${P}`:P,L.value)}),100)}),[H]),o((()=>{!I&&L&&P&&setTimeout((()=>{Y("custom_link"===(null==L?void 0:L.value)?`https://${P}`:P,L.value),$(!0)}),100)}),[I]),e(g,Object.assign({channel:B,focused:T,onMouseEnter:()=>O(!0),onMouseLeave:()=>O(!1)},{children:[t("div",Object.assign({style:{marginBottom:8}},{children:e(c,Object.assign({style:{color:N&&!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:G,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:N?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;Y(a,e),B===d.WHATSAPP&&(null==J||J(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?G({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?G({label:e.displayName,selected:!0,value:"custom_text"}):G({label:e.actualValue.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{g as Container,_ 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:V}=n;var A;const[T,O]=a(!1),[P,S]=a(""),[w,E]=a([]),[L,C]=a(),[M,W]=a(!1),[I,$]=a(!1),{device:H,channel:B,isError:N,originalVariableList:z,template:R,templateSelectionTriggered:U,setTemplate:D,setDisplayContent:Z,setOriginalVariableList:F,globalNormalizedPlaceholders:q}=p();function G(e,l){var t,a,o;const n=e;S(""),C(n),B===r.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(Y(null!==(t=n.value)&&void 0!==t?t:"","string"),null==J||J(null!==(a=f.index)&&void 0!==a?a:0,`[[${n.value}]]`)):(null==J||J(null!==(o=f.index)&&void 0!==o?o:0,f.variableName),Y("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?Y(n.value,"url"===n.bikPlaceholderType?"link":"string"):(S(""),Y("",n.value))}function Y(e,l){var t,a;const o="custom_link"===l?"link":"custom_text"===l?"string":l;if(B!==r.WHATSAPP){const a=b(j+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===H?"template_html_mobile":"template_html_desktop"),i=B===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:f.variableName);const u=z.map(((l,t)=>t===j?Object.assign(Object.assign({},l),{type:o,updatedValue:e}):l));null==F||F(u)}if(B===r.WHATSAPP){const l=null===(a=z.body)||void 0===a?void 0:a.map(((l,t)=>t===j?Object.assign(Object.assign({},l),{type:o,updatedValue:e}):l));null==F||F((e=>Object.assign(Object.assign({},e),{body:l,buttons:z.buttons})))}}function J(e,l){var t;const a=Object.assign({},R),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==D||D(a)}return o((()=>{T&&(null==_||_())}),[T]),o((()=>{!function(){var e,l,t,a,o;const n="mobile"===H?"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);B===r.EMAIL&&(null==Z||Z(u))}()}),[U]),o((()=>{var e;const l=[];let t=[];if(B===r.MESSAGE){const e=null!=q?q:[];E([{label:"",options:[x,h]},...e]),t=[{label:"",options:[x,h]},...e]}else{"link"===(null==f?void 0:f.type)?(l.push({label:"",options:[h,x]}),C(h)):(l.push({label:"",options:[h,x]}),C(x));const e=null!=q?q:[];E([...l,...e.map((e=>{var l,t;return Object.assign(Object.assign({},e),{label:m.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((B===r.WHATSAPP||B===r.EMAIL||B===r.MESSAGE)&&f.updatedValue)if(d.test(f.updatedValue)&&B===r.WHATSAPP||f.updatedValue.startsWith("{{")&&B!==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}(f,t,B);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((()=>{H&&L&&P&&setTimeout((()=>{Y("custom_link"===(null==L?void 0:L.value)?`https://${P}`:P,L.value)}),100)}),[H]),o((()=>{console.log("renderFirstTime: ",I),console.log("selectedOption: ",L),console.log("variable.updatedValue: ",f.updatedValue),!I&&L&&f.updatedValue&&setTimeout((()=>{Y("custom_link"===(null==L?void 0:L.value)?`https://${f.updatedValue}`:f.updatedValue,L.value),$(!0)}),100)}),[I]),e(g,Object.assign({channel:B,focused:T,onMouseEnter:()=>O(!0),onMouseLeave:()=>O(!1)},{children:[l("div",Object.assign({style:{marginBottom:8}},{children:e(c,Object.assign({style:{color:N&&!L?v.content.negative:v.content.primary}},{children:[null===(A=f.variableName)||void 0===A?void 0:A.replace("{{","").replace("}}","")," ","link"===(null==f?void 0:f.type)?"link":"variable"]}))})),l("div",Object.assign({style:{marginBottom:12}},{children:k?l(s,{state:"none",value:L?L.label:"Custom text",onChangeText:e=>{},onFocus:()=>{W(!M)},rightIcon:{icon:()=>l(t,{onClick:()=>{W(!M)},width:24,height:24,color:v.content.primary})}}):l(u,{options:w,isSearchable:!1,onSelect:G,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))&&l(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:N?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,l){var t;S(l);const a="custom_link"===(null==L?void 0:L.value)?`https://${l}`:l;Y(a,e),B===r.WHATSAPP&&(null==J||J(null!==(t=f.index)&&void 0!==t?t:0,a))}(L.value,e)}}),M&&l(i,{zIndex:2e3,data:null!=y?y:[],showVariable:M,setShowVariable:W,placeholder:"Add a variable",customTrigger:e=>{V(!1),"{{custom.url}}"===e.actualValue?G({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?G({label:e.displayName,selected:!0,value:"custom_text"}):G({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.21",
3
+ "version": "0.0.314-beta.22",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",