@bikdotai/bik-component-library 0.0.359-beta.4 → 0.0.359-beta.6

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,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -4,4 +4,4 @@
4
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
- `,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;const[T,P]=t.useState(!1),[N,C]=t.useState(""),[O,L]=t.useState([]),[k,S]=t.useState(),[V,H]=t.useState(!1),[w,M]=t.useState(!1),{device:q,channel:Y,isError:W,originalVariableList:I,template:B,templateSelectionTriggered:$,setTemplate:R,setDisplayContent:z,setOriginalVariableList:D,globalNormalizedPlaceholders:U,enabledCustomText:Z}=p.useTemplateModalContext();function F(e,l){var t,a,n;const o=e;C(""),S(o),Y===d.CHANNEL_TYPE.WHATSAPP?"custom_text"!==o.value&&"custom_link"!==o.value?(G(null!==(t=o.value)&&void 0!==t?t:"","string"),null==J||J(null!==(a=E.index)&&void 0!==a?a:0,`[[${o.value}]]`)):(null==J||J(null!==(n=E.index)&&void 0!==n?n:0,E.variableName),G("","url"===o.bikPlaceholderType?"link":"string")):"custom_text"!==o.value&&"custom_link"!==o.value?G(o.value,"url"===o.bikPlaceholderType?"link":"string"):(C(""),G("",o.value))}function G(e,l){var t,a;const n="custom_link"===l?"link":"custom_text"===l?"string":l;if(Y!==d.CHANNEL_TYPE.WHATSAPP){const a=m.getVariableNameForEmailByIndex(_+1),o=null===document||void 0===document?void 0:document.getElementById("mobile"===q?"template_html_mobile":"template_html_desktop"),i=Y===d.CHANNEL_TYPE.EMAIL?null===(t=null==o?void 0:o.contentWindow)||void 0===t?void 0:t.document.getElementById(a):document.getElementById(a);i&&(i.textContent="custom_text"!==l&&"custom_link"!==l||e?e:E.variableName);const u=I.map(((l,t)=>t===_?Object.assign(Object.assign({},l),{type:n,updatedValue:e}):l));null==D||D(u)}if(Y===d.CHANNEL_TYPE.WHATSAPP){const l=null===(a=I.body)||void 0===a?void 0:a.map(((l,t)=>t===_?Object.assign(Object.assign({},l),{type:n,updatedValue:e}):l));null==D||D((e=>Object.assign(Object.assign({},e),{body:l,buttons:I.buttons})))}}function J(e,l){var t;const a=Object.assign({},B),n=null===(t=null==a?void 0:a.components)||void 0===t?void 0:t.map((t=>{var a,n,o,i,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===(i=null===(o=s.example)||void 0===o?void 0:o.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=n,null==R||R(a)}return t.useEffect((()=>{T&&(null==b||b())}),[T]),t.useEffect((()=>{!function(){var e,l,t,a,n;const o="mobile"===q?"template_html_mobile":"template_html_desktop",i=document.getElementById(o),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===(n=null==i?void 0:i.contentWindow)||void 0===n?void 0:n.document.head.innerHTML);Y===d.CHANNEL_TYPE.EMAIL&&(null==z||z(u))}()}),[$]),t.useEffect((()=>{var e;const l=[];let t=[];if(Y!==d.CHANNEL_TYPE.MESSAGE||Z){"link"===(null==E?void 0:E.type)?(l.push({label:"",options:[x,h]}),S(x)):(l.push({label:"",options:[x,h]}),S(h));const e=null!=U?U:[];console.log("globalOptions",e),L([...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]}else{const e=null!=U?U:[];console.log("globalOptions",e),L([{label:"",options:[h,x]},...e]),t=[{label:"",options:[h,x]},...e]}if((Y===d.CHANNEL_TYPE.WHATSAPP||Y===d.CHANNEL_TYPE.EMAIL||Y===d.CHANNEL_TYPE.MESSAGE)&&E.updatedValue)if(s.placeHolderNamePattern.test(E.updatedValue)&&Y===d.CHANNEL_TYPE.WHATSAPP||E.updatedValue.startsWith("{{")&&Y!==d.CHANNEL_TYPE.WHATSAPP){const e=function(e,l,t){var a;let n={label:"",value:""};const o=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())===o.trim()&&(n=e)}))}));return console.log("preSelectedOption",n),n}(E,t,Y);e.value&&S(e)}else(null===(e=E.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(S(x),C(E.updatedValue.split("https://")[1])):(S(h),C(E.updatedValue))}),[]),t.useEffect((()=>{q&&k&&N&&setTimeout((()=>{G("custom_link"===(null==k?void 0:k.value)?`https://${N}`:N,k.value)}),100)}),[q]),t.useEffect((()=>{!w&&k&&E.updatedValue&&setTimeout((()=>{G("custom_link"===(null==k?void 0:k.value)?`https://${E.updatedValue}`:E.updatedValue,k.value),M(!0)}),100)}),[k]),e.jsxs(g,Object.assign({channel:Y,focused:T,onMouseEnter:()=>P(!0),onMouseLeave:()=>P(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsx(r.BodySecondary,Object.assign({style:{color:W&&!k?v.COLORS.content.negative:v.COLORS.content.primary}},{children:"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==k?void 0:k.label)?"space-between":"flex-end"}},{children:[e.jsx(r.BodyPrimary,{children:u.truncate(null!==(f=null==k?void 0:k.label)&&void 0!==f?f:"",20,!0)}),e.jsx(l.default,{onClick:()=>{H(!V)},width:24,height:24,color:v.COLORS.content.primary})]})):e.jsx(o.Dropdown,{options:O,isSearchable:!1,onSelect:F,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}-${_}`,value:N,errorMessage:W?N&&0!==N.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://${N.trim()}`)&&0!==N.trim().length?"custom_link"!==k.value&&N.length>30?"Length cannot be more than 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"===E.type||"custom_link"===k.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{!function(e,l){var t;C(l);const a="custom_link"===(null==k?void 0:k.value)?`https://${l}`:l;G(a,e),Y===d.CHANNEL_TYPE.WHATSAPP&&(null==J||J(null!==(t=E.index)&&void 0!==t?t:0,a))}(k.value,e)}}),V&&e.jsx(n.AddVariableV2SideModal,{zIndex:2e3,data:null!=A?A:[],showVariable:V,setShowVariable:H,placeholder:"Add a variable",customTrigger:e=>{console.log("variable",e),null==y||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.defaultValue||e.displayName,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:f}=a;var y;const[T,P]=t.useState(!1),[C,N]=t.useState(""),[O,L]=t.useState([]),[k,S]=t.useState(),[V,H]=t.useState(!1),[w,M]=t.useState(!1),{device:q,channel:Y,isError:W,originalVariableList:I,template:B,templateSelectionTriggered:$,setTemplate:R,setDisplayContent:z,setOriginalVariableList:D,globalNormalizedPlaceholders:U,enabledCustomText:Z}=p.useTemplateModalContext();function F(e,l){var t,a,n;const o=e;N(""),S(o),Y===d.CHANNEL_TYPE.WHATSAPP?"custom_text"!==o.value&&"custom_link"!==o.value?(G(null!==(t=o.value)&&void 0!==t?t:"","string"),null==J||J(null!==(a=E.index)&&void 0!==a?a:0,`{{${o.value}}}`)):(null==J||J(null!==(n=E.index)&&void 0!==n?n:0,E.variableName),G("","url"===o.bikPlaceholderType?"link":"string")):"custom_text"!==o.value&&"custom_link"!==o.value?G(o.value,"url"===o.bikPlaceholderType?"link":"string"):(N(""),G("",o.value))}function G(e,l){var t,a;const n="custom_link"===l?"link":"custom_text"===l?"string":l;if(Y!==d.CHANNEL_TYPE.WHATSAPP){const a=m.getVariableNameForEmailByIndex(_+1),o=null===document||void 0===document?void 0:document.getElementById("mobile"===q?"template_html_mobile":"template_html_desktop"),i=Y===d.CHANNEL_TYPE.EMAIL?null===(t=null==o?void 0:o.contentWindow)||void 0===t?void 0:t.document.getElementById(a):document.getElementById(a);i&&(i.textContent="custom_text"!==l&&"custom_link"!==l||e?e:E.variableName);const u=I.map(((l,t)=>t===_?Object.assign(Object.assign({},l),{type:n,updatedValue:e}):l));null==D||D(u)}if(Y===d.CHANNEL_TYPE.WHATSAPP){const l=null===(a=I.body)||void 0===a?void 0:a.map(((l,t)=>t===_?Object.assign(Object.assign({},l),{type:n,updatedValue:e}):l));null==D||D((e=>Object.assign(Object.assign({},e),{body:l,buttons:I.buttons})))}}function J(e,l){var t;const a=Object.assign({},B),n=null===(t=null==a?void 0:a.components)||void 0===t?void 0:t.map((t=>{var a,n,o,i,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===(i=null===(o=s.example)||void 0===o?void 0:o.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=n,null==R||R(a)}return t.useEffect((()=>{T&&(null==b||b())}),[T]),t.useEffect((()=>{!function(){var e,l,t,a,n;const o="mobile"===q?"template_html_mobile":"template_html_desktop",i=document.getElementById(o),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===(n=null==i?void 0:i.contentWindow)||void 0===n?void 0:n.document.head.innerHTML);Y===d.CHANNEL_TYPE.EMAIL&&(null==z||z(u))}()}),[$]),t.useEffect((()=>{var e;const l=[];let t=[];if(Y!==d.CHANNEL_TYPE.MESSAGE||Z){"link"===(null==E?void 0:E.type)?(l.push({label:"",options:[x,h]}),S(x)):(l.push({label:"",options:[x,h]}),S(h));const e=null!=U?U:[];console.log("globalOptions",e),L([...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]}else{const e=null!=U?U:[];console.log("globalOptions",e),L([{label:"",options:[h,x]},...e]),t=[{label:"",options:[h,x]},...e]}if((Y===d.CHANNEL_TYPE.WHATSAPP||Y===d.CHANNEL_TYPE.EMAIL||Y===d.CHANNEL_TYPE.MESSAGE)&&E.updatedValue)if(s.placeHolderNamePattern.test(E.updatedValue)&&Y===d.CHANNEL_TYPE.WHATSAPP||E.updatedValue.startsWith("{{")&&Y!==d.CHANNEL_TYPE.WHATSAPP){const e=function(e,l,t){var a;let n={label:"",value:""};const o=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())===o.trim()&&(n=e)}))}));return console.log("preSelectedOption",n),n}(E,t,Y);e.value&&S(e)}else(null===(e=E.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(S(x),N(E.updatedValue.split("https://")[1])):(S(h),N(E.updatedValue))}),[]),t.useEffect((()=>{q&&k&&C&&setTimeout((()=>{G("custom_link"===(null==k?void 0:k.value)?`https://${C}`:C,k.value)}),100)}),[q]),t.useEffect((()=>{!w&&k&&E.updatedValue&&setTimeout((()=>{G("custom_link"===(null==k?void 0:k.value)?`https://${E.updatedValue}`:E.updatedValue,k.value),M(!0)}),100)}),[k]),e.jsxs(g,Object.assign({channel:Y,focused:T,onMouseEnter:()=>P(!0),onMouseLeave:()=>P(!1)},{children:[e.jsx("div",Object.assign({style:{marginBottom:8}},{children:e.jsx(r.BodySecondary,Object.assign({style:{color:W&&!k?v.COLORS.content.negative:v.COLORS.content.primary}},{children:"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==k?void 0:k.label)?"space-between":"flex-end"}},{children:[e.jsx(r.BodyPrimary,{children:u.truncate(null!==(y=null==k?void 0:k.label)&&void 0!==y?y:"",20,!0)}),e.jsx(l.default,{onClick:()=>{H(!V)},width:24,height:24,color:v.COLORS.content.primary})]})):e.jsx(o.Dropdown,{options:O,isSearchable:!1,onSelect:F,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}-${_}`,value:C,errorMessage:W?C&&0!==C.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://${C.trim()}`)&&0!==C.trim().length?"custom_link"!==k.value&&C.length>30?"Length cannot be more than 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"===E.type||"custom_link"===k.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{!function(e,l){var t;N(l);const a="custom_link"===(null==k?void 0:k.value)?`https://${l}`:l;G(a,e),Y===d.CHANNEL_TYPE.WHATSAPP&&(null==J||J(null!==(t=E.index)&&void 0!==t?t:0,a))}(k.value,e)}}),V&&e.jsx(n.AddVariableV2SideModal,{zIndex:2e3,data:null!=A?A:[],showVariable:V,setShowVariable:H,placeholder:"Add a variable",customTrigger:e=>{console.log("variable",e),null==f||f(!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,selected:!0,value:e.defaultValue||e.actualValue,bikPlaceholderType:"string"})}})]}))};
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare const Menus: ({
2
3
  displayName: string;
3
4
  key: number;
@@ -4,4 +4,4 @@ import{jsxs as e,jsx as l}from"react/jsx-runtime";import t from"../../../assets/
4
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
- `,f={value:"custom_link",label:"Custom URL"},_={value:"custom_text",label:"Custom text"},j=n=>{let{onFocus:j,variable:y,index:k,showVariableModal:V,variableList:A,setShowDiscountCheckBox:O}=n;var T;const[S,E]=o(!1),[P,w]=o(""),[L,C]=o([]),[M,W]=o(),[$,H]=o(!1),[I,B]=o(!1),{device:N,channel:z,isError:R,originalVariableList:U,template:D,templateSelectionTriggered:Z,setTemplate:G,setDisplayContent:q,setOriginalVariableList:F,globalNormalizedPlaceholders:Y,enabledCustomText:J}=g();function K(e,l){var t,o,a;const n=e;w(""),W(n),z===c.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(Q(null!==(t=n.value)&&void 0!==t?t:"","string"),null==X||X(null!==(o=y.index)&&void 0!==o?o:0,`[[${n.value}]]`)):(null==X||X(null!==(a=y.index)&&void 0!==a?a:0,y.variableName),Q("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?Q(n.value,"url"===n.bikPlaceholderType?"link":"string"):(w(""),Q("",n.value))}function Q(e,l){var t,o;const a="custom_link"===l?"link":"custom_text"===l?"string":l;if(z!==c.WHATSAPP){const o=h(k+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===N?"template_html_mobile":"template_html_desktop"),i=z===c.EMAIL?null===(t=null==n?void 0:n.contentWindow)||void 0===t?void 0:t.document.getElementById(o):document.getElementById(o);i&&(i.textContent="custom_text"!==l&&"custom_link"!==l||e?e:y.variableName);const u=U.map(((l,t)=>t===k?Object.assign(Object.assign({},l),{type:a,updatedValue:e}):l));null==F||F(u)}if(z===c.WHATSAPP){const l=null===(o=U.body)||void 0===o?void 0:o.map(((l,t)=>t===k?Object.assign(Object.assign({},l),{type:a,updatedValue:e}):l));null==F||F((e=>Object.assign(Object.assign({},e),{body:l,buttons:U.buttons})))}}function X(e,l){var t;const o=Object.assign({},D),a=null===(t=null==o?void 0:o.components)||void 0===t?void 0:t.map((t=>{var o,a,n,i,u;const s=Object.assign({},t);if("BODY"===t.type&&(null===(a=null===(o=t.example)||void 0===o?void 0:o.body_text)||void 0===a?void 0:a[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 o=Object.assign(Object.assign({},s.example),{body_text:[t]});return Object.assign(Object.assign({},s),{example:o})}return t}));o.components=a,null==G||G(o)}return a((()=>{S&&(null==j||j())}),[S]),a((()=>{!function(){var e,l,t,o,a;const n="mobile"===N?"template_html_mobile":"template_html_desktop",i=document.getElementById(n),u=(null!==(o=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!==o?o:"")+(null===(a=null==i?void 0:i.contentWindow)||void 0===a?void 0:a.document.head.innerHTML);z===c.EMAIL&&(null==q||q(u))}()}),[Z]),a((()=>{var e;const l=[];let t=[];if(z!==c.MESSAGE||J){"link"===(null==y?void 0:y.type)?(l.push({label:"",options:[f,_]}),W(f)):(l.push({label:"",options:[f,_]}),W(_));const e=null!=Y?Y:[];console.log("globalOptions",e),C([...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]}else{const e=null!=Y?Y:[];console.log("globalOptions",e),C([{label:"",options:[_,f]},...e]),t=[{label:"",options:[_,f]},...e]}if((z===c.WHATSAPP||z===c.EMAIL||z===c.MESSAGE)&&y.updatedValue)if(r.test(y.updatedValue)&&z===c.WHATSAPP||y.updatedValue.startsWith("{{")&&z!==c.WHATSAPP){const e=function(e,l,t){var o;let a={label:"",value:""};const n=t===c.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");V?a={label:e.updatedValue?e.updatedValue.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(o=e.updatedValue)&&void 0!==o?o:""}:l.map((e=>{e.options.map((e=>{var l;(null===(l=e.value)||void 0===l?void 0:l.replace("{{","").replace("}}","").trim())===n.trim()&&(a=e)}))}));return console.log("preSelectedOption",a),a}(y,t,z);e.value&&W(e)}else(null===(e=y.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(W(f),w(y.updatedValue.split("https://")[1])):(W(_),w(y.updatedValue))}),[]),a((()=>{N&&M&&P&&setTimeout((()=>{Q("custom_link"===(null==M?void 0:M.value)?`https://${P}`:P,M.value)}),100)}),[N]),a((()=>{!I&&M&&y.updatedValue&&setTimeout((()=>{Q("custom_link"===(null==M?void 0:M.value)?`https://${y.updatedValue}`:y.updatedValue,M.value),B(!0)}),100)}),[M]),e(x,Object.assign({channel:z,focused:S,onMouseEnter:()=>E(!0),onMouseLeave:()=>E(!1)},{children:[l("div",Object.assign({style:{marginBottom:8}},{children:l(m,Object.assign({style:{color:R&&!M?b.content.negative:b.content.primary}},{children:"link"===(null==y?void 0:y.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==M?void 0:M.label)?"space-between":"flex-end"}},{children:[l(p,{children:d(null!==(T=null==M?void 0:M.label)&&void 0!==T?T:"",20,!0)}),l(t,{onClick:()=>{H(!$)},width:24,height:24,color:b.content.primary})]})):l(u,{options:L,isSearchable:!1,onSelect:K,defaultOptions:M?[Object.assign(Object.assign({},M),{selected:!0})]:[]})})),("custom_text"===(null==M?void 0:M.value)||"custom_link"===(null==M?void 0:M.value))&&l(s,{labelText:"custom_text"===(null==M?void 0:M.value)?"Custom text value":"custom_link"===(null==M?void 0:M.value)?"Custom URL value":"",id:`variable-value-${null==M?void 0:M.value}-${k}`,value:P,errorMessage:R?P&&0!==P.trim().length?"custom_link"!==M.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"!==M.value&&P.length>30?"Length cannot be more than 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==M?void 0:M.value)?void 0:30,prefixText:"custom_link"===(null==M?void 0:M.value)?"https://":"",placeholder:"link"===y.type||"custom_link"===M.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{!function(e,l){var t;w(l);const o="custom_link"===(null==M?void 0:M.value)?`https://${l}`:l;Q(o,e),z===c.WHATSAPP&&(null==X||X(null!==(t=y.index)&&void 0!==t?t:0,o))}(M.value,e)}}),$&&l(i,{zIndex:2e3,data:null!=A?A:[],showVariable:$,setShowVariable:H,placeholder:"Add a variable",customTrigger:e=>{console.log("variable",e),null==O||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.defaultValue||e.displayName,selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{x as Container,j 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;const[S,E]=o(!1),[P,w]=o(""),[L,C]=o([]),[M,W]=o(),[$,H]=o(!1),[I,B]=o(!1),{device:z,channel:N,isError:R,originalVariableList:U,template:D,templateSelectionTriggered:Z,setTemplate:G,setDisplayContent:q,setOriginalVariableList:F,globalNormalizedPlaceholders:Y,enabledCustomText:J}=g();function K(e,l){var t,o,a;const n=e;w(""),W(n),N===c.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(Q(null!==(t=n.value)&&void 0!==t?t:"","string"),null==X||X(null!==(o=k.index)&&void 0!==o?o:0,`{{${n.value}}}`)):(null==X||X(null!==(a=k.index)&&void 0!==a?a: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"):(w(""),Q("",n.value))}function Q(e,l){var t,o;const a="custom_link"===l?"link":"custom_text"===l?"string":l;if(N!==c.WHATSAPP){const o=h(y+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===z?"template_html_mobile":"template_html_desktop"),i=N===c.EMAIL?null===(t=null==n?void 0:n.contentWindow)||void 0===t?void 0:t.document.getElementById(o):document.getElementById(o);i&&(i.textContent="custom_text"!==l&&"custom_link"!==l||e?e:k.variableName);const u=U.map(((l,t)=>t===y?Object.assign(Object.assign({},l),{type:a,updatedValue:e}):l));null==F||F(u)}if(N===c.WHATSAPP){const l=null===(o=U.body)||void 0===o?void 0:o.map(((l,t)=>t===y?Object.assign(Object.assign({},l),{type:a,updatedValue:e}):l));null==F||F((e=>Object.assign(Object.assign({},e),{body:l,buttons:U.buttons})))}}function X(e,l){var t;const o=Object.assign({},D),a=null===(t=null==o?void 0:o.components)||void 0===t?void 0:t.map((t=>{var o,a,n,i,u;const s=Object.assign({},t);if("BODY"===t.type&&(null===(a=null===(o=t.example)||void 0===o?void 0:o.body_text)||void 0===a?void 0:a[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 o=Object.assign(Object.assign({},s.example),{body_text:[t]});return Object.assign(Object.assign({},s),{example:o})}return t}));o.components=a,null==G||G(o)}return a((()=>{S&&(null==j||j())}),[S]),a((()=>{!function(){var e,l,t,o,a;const n="mobile"===z?"template_html_mobile":"template_html_desktop",i=document.getElementById(n),u=(null!==(o=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!==o?o:"")+(null===(a=null==i?void 0:i.contentWindow)||void 0===a?void 0:a.document.head.innerHTML);N===c.EMAIL&&(null==q||q(u))}()}),[Z]),a((()=>{var e;const l=[];let t=[];if(N!==c.MESSAGE||J){"link"===(null==k?void 0:k.type)?(l.push({label:"",options:[f,_]}),W(f)):(l.push({label:"",options:[f,_]}),W(_));const e=null!=Y?Y:[];console.log("globalOptions",e),C([...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]}else{const e=null!=Y?Y:[];console.log("globalOptions",e),C([{label:"",options:[_,f]},...e]),t=[{label:"",options:[_,f]},...e]}if((N===c.WHATSAPP||N===c.EMAIL||N===c.MESSAGE)&&k.updatedValue)if(r.test(k.updatedValue)&&N===c.WHATSAPP||k.updatedValue.startsWith("{{")&&N!==c.WHATSAPP){const e=function(e,l,t){var o;let a={label:"",value:""};const n=t===c.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");V?a={label:e.updatedValue?e.updatedValue.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(o=e.updatedValue)&&void 0!==o?o:""}:l.map((e=>{e.options.map((e=>{var l;(null===(l=e.value)||void 0===l?void 0:l.replace("{{","").replace("}}","").trim())===n.trim()&&(a=e)}))}));return console.log("preSelectedOption",a),a}(k,t,N);e.value&&W(e)}else(null===(e=k.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(W(f),w(k.updatedValue.split("https://")[1])):(W(_),w(k.updatedValue))}),[]),a((()=>{z&&M&&P&&setTimeout((()=>{Q("custom_link"===(null==M?void 0:M.value)?`https://${P}`:P,M.value)}),100)}),[z]),a((()=>{!I&&M&&k.updatedValue&&setTimeout((()=>{Q("custom_link"===(null==M?void 0:M.value)?`https://${k.updatedValue}`:k.updatedValue,M.value),B(!0)}),100)}),[M]),e(x,Object.assign({channel:N,focused:S,onMouseEnter:()=>E(!0),onMouseLeave:()=>E(!1)},{children:[l("div",Object.assign({style:{marginBottom:8}},{children:l(m,Object.assign({style:{color:R&&!M?b.content.negative:b.content.primary}},{children:"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==M?void 0:M.label)?"space-between":"flex-end"}},{children:[l(p,{children:d(null!==(T=null==M?void 0:M.label)&&void 0!==T?T:"",20,!0)}),l(t,{onClick:()=>{H(!$)},width:24,height:24,color:b.content.primary})]})):l(u,{options:L,isSearchable:!1,onSelect:K,defaultOptions:M?[Object.assign(Object.assign({},M),{selected:!0})]:[]})})),("custom_text"===(null==M?void 0:M.value)||"custom_link"===(null==M?void 0:M.value))&&l(s,{labelText:"custom_text"===(null==M?void 0:M.value)?"Custom text value":"custom_link"===(null==M?void 0:M.value)?"Custom URL value":"",id:`variable-value-${null==M?void 0:M.value}-${y}`,value:P,errorMessage:R?P&&0!==P.trim().length?"custom_link"!==M.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"!==M.value&&P.length>30?"Length cannot be more than 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==M?void 0:M.value)?void 0:30,prefixText:"custom_link"===(null==M?void 0:M.value)?"https://":"",placeholder:"link"===k.type||"custom_link"===M.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{!function(e,l){var t;w(l);const o="custom_link"===(null==M?void 0:M.value)?`https://${l}`:l;Q(o,e),N===c.WHATSAPP&&(null==X||X(null!==(t=k.index)&&void 0!==t?t:0,o))}(M.value,e)}}),$&&l(i,{zIndex:2e3,data:null!=A?A:[],showVariable:$,setShowVariable:H,placeholder:"Add a variable",customTrigger:e=>{console.log("variable",e),null==O||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,selected:!0,value:e.defaultValue||e.actualValue,bikPlaceholderType:"string"})}})]}))};export{x as Container,j as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.359-beta.4",
3
+ "version": "0.0.359-beta.6",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",