@bikdotai/bik-component-library 0.0.359-beta.13 → 0.0.359-beta.15
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"),o=require("../../add-variableV2/AddVariableV2SideModal.js"),n=require("../../dropdown/Dropdown.js"),i=require("../../input/Input.js"),
|
|
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"),o=require("../../add-variableV2/AddVariableV2SideModal.js"),n=require("../../dropdown/Dropdown.js"),i=require("../../input/Input.js"),s=require("../../product-picker-v2/collectionScreen.js"),u=require("../../template-preview/constants/regexPatterns.js"),d=require("../../template-preview/models/Channels.js"),r=require("../../TypographyStyle.js"),c=require("../../../utils/StringUtils.js"),p=require("../../../constants/Theme.js"),v=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
4
|
background: ${e=>e.focused&&e.channel===d.CHANNEL_TYPE.EMAIL?p.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:y,setShowDiscountCheckBox:A}=a;var f,O;const[T,N]=t.useState(!1),[P,C]=t.useState(""),[L,k]=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:R,templateSelectionTriggered:$,setTemplate:z,setDisplayContent:D,setOriginalVariableList:U,globalNormalizedPlaceholders:Z,enabledCustomText:F}=v.useTemplateModalContext();function G(e,l){var t,a,o;const n=e;C(""),V(n),console.log("singleOption",n),console.log("variable",E),W===d.CHANNEL_TYPE.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(J(null!==(t=n.value)&&void 0!==t?t:"","string"),null==K||K(null!==(a=E.index)&&void 0!==a?a:0,n.value)):(null==K||K(null!==(o=E.index)&&void 0!==o?o:0,E.variableName),J("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?J(n.value,"url"===n.bikPlaceholderType?"link":"string"):(C(""),J("",n.value))}function J(e,l){var t,a;const o="custom_link"===l?"link":"custom_text"===l?"string":l;if(W!==d.CHANNEL_TYPE.WHATSAPP){const a=m.getVariableNameForEmailByIndex(_+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===Y?"template_html_mobile":"template_html_desktop"),i=W===d.CHANNEL_TYPE.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:E.variableName);const
|
|
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:y,setShowDiscountCheckBox:A}=a;var f,O;const[T,N]=t.useState(!1),[P,C]=t.useState(""),[L,k]=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:R,templateSelectionTriggered:$,setTemplate:z,setDisplayContent:D,setOriginalVariableList:U,globalNormalizedPlaceholders:Z,enabledCustomText:F}=v.useTemplateModalContext();function G(e,l){var t,a,o;const n=e;C(""),V(n),console.log("singleOption",n),console.log("variable",E),W===d.CHANNEL_TYPE.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(J(null!==(t=n.value)&&void 0!==t?t:"","string"),null==K||K(null!==(a=E.index)&&void 0!==a?a:0,n.value)):(null==K||K(null!==(o=E.index)&&void 0!==o?o:0,E.variableName),J("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?J(n.value,"url"===n.bikPlaceholderType?"link":"string"):(C(""),J("",n.value))}function J(e,l){var t,a;const o="custom_link"===l?"link":"custom_text"===l?"string":l;if(W!==d.CHANNEL_TYPE.WHATSAPP){const a=m.getVariableNameForEmailByIndex(_+1),n=null===document||void 0===document?void 0:document.getElementById("mobile"===Y?"template_html_mobile":"template_html_desktop"),i=W===d.CHANNEL_TYPE.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:E.variableName);const s=B.map(((l,t)=>t===_?Object.assign(Object.assign({},l),{type:o,updatedValue:e}):l));null==U||U(s)}if(console.log("originalVariableList",B),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:o,updatedValue:e}):l));console.log("lib-updatedVariables",l),null==U||U((e=>Object.assign(Object.assign({},e),{body:l,buttons:B.buttons})))}}function K(e,l,t){var a,o,n;const i=Object.assign({},R),s=null===(a=null==i?void 0:i.components)||void 0===a?void 0:a.map((t=>{var a,o,n,i,s;const u=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!==(s=null===(i=null===(n=u.example)||void 0===n?void 0:n.body_text)||void 0===i?void 0:i[0])&&void 0!==s?s:[]];t[e]=l.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},u.example),{body_text:[t]});return Object.assign(Object.assign({},u),{example:a})}return console.log("updateComponent",u),t}));if(i.components=s,(null===(o=null==i?void 0:i.mapping)||void 0===o?void 0:o.body)&&Array.isArray(null===(n=null==i?void 0:i.mapping)||void 0===n?void 0:n.body))try{i.mapping=Object.assign(Object.assign({},i.mapping),{body:i.mapping.body.map(((t,a)=>e===a?l:t))})}catch(e){console.log("error",e)}null==z||z(Object.assign({},i))}return t.useEffect((()=>{T&&(null==b||b())}),[T]),t.useEffect((()=>{!function(){var e,l,t,a,o;const n="mobile"===Y?"template_html_mobile":"template_html_desktop",i=document.getElementById(n),s=(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);W===d.CHANNEL_TYPE.EMAIL&&(null==D||D(s))}()}),[$]),t.useEffect((()=>{var e;const l=[];let t=[];if(W!==d.CHANNEL_TYPE.MESSAGE||F){"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:[];console.log("globalOptions",e),k([...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],console.log("allOptions",t)}else{const e=null!=Z?Z:[];console.log("globalOptions",e),k([{label:"",options:[h,x]},...e]),t=[{label:"",options:[h,x]},...e]}if((W===d.CHANNEL_TYPE.WHATSAPP||W===d.CHANNEL_TYPE.EMAIL||W===d.CHANNEL_TYPE.MESSAGE)&&E.updatedValue)if(u.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 o={label:"",value:""};const n=t===d.CHANNEL_TYPE.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");j?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 console.log("preSelectedOption",o),o}(E,t,W);e.value&&V(e)}else(null===(e=E.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(V(x),C(E.updatedValue.split("https://")[1])):(V(h),C(E.updatedValue))}),[]),t.useEffect((()=>{Y&&S&&P&&setTimeout((()=>{J("custom_link"===(null==S?void 0:S.value)?`https://${P}`:P,S.value)}),100)}),[Y]),t.useEffect((()=>{!M&&S&&E.updatedValue&&setTimeout((()=>{J("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?p.COLORS.content.negative:p.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:s.truncate(null!==(O=null==S?void 0:S.label)&&void 0!==O?O:"",20,!0)}),e.jsx(l.default,{onClick:()=>{w(!H)},width:24,height:24,color:p.COLORS.content.primary})]})):e.jsx(n.Dropdown,{options:L,isSearchable:!1,onSelect:G,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(i.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:P,errorMessage:I?P&&0!==P.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://${P.trim()}`)&&0!==P.trim().length?"custom_link"!==S.value&&P.length>30?"Length cannot be more than 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=>{!function(e,l){var t;C(l);const a="custom_link"===(null==S?void 0:S.value)?`https://${l}`:l;J(a,e),W===d.CHANNEL_TYPE.WHATSAPP&&(null==K||K(null!==(t=E.index)&&void 0!==t?t:0,a))}(S.value,e)}}),H&&e.jsx(o.AddVariableV2SideModal,{zIndex:2e3,data:null!=y?y:[],showVariable:H,setShowVariable:w,placeholder:"Add a variable",customTrigger:e=>{console.log("variable",e),null==A||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.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};
|
|
@@ -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
|
-
`,y={value:"custom_link",label:"Custom URL"},f={value:"custom_text",label:"Custom text"},
|
|
7
|
+
`,y={value:"custom_link",label:"Custom URL"},f={value:"custom_text",label:"Custom text"},j=n=>{let{onFocus:j,variable:_,index:k,showVariableModal:O,variableList:A,setShowDiscountCheckBox:V}=n;var T,S;const[E,P]=o(!1),[w,L]=o(""),[C,M]=o([]),[W,H]=o(),[I,$]=o(!1),[B,N]=o(!1),{device:z,channel:R,isError:U,originalVariableList:D,template:Z,templateSelectionTriggered:G,setTemplate:q,setDisplayContent:F,setOriginalVariableList:Y,globalNormalizedPlaceholders:J,enabledCustomText:K}=g();function Q(e,l){var t,o,a;const n=e;L(""),H(n),console.log("singleOption",n),console.log("variable",_),R===c.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(X(null!==(t=n.value)&&void 0!==t?t:"","string"),null==ee||ee(null!==(o=_.index)&&void 0!==o?o:0,n.value)):(null==ee||ee(null!==(a=_.index)&&void 0!==a?a:0,_.variableName),X("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?X(n.value,"url"===n.bikPlaceholderType?"link":"string"):(L(""),X("",n.value))}function X(e,l){var t,o;const a="custom_link"===l?"link":"custom_text"===l?"string":l;if(R!==c.WHATSAPP){const o=h(k+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(o):document.getElementById(o);i&&(i.textContent="custom_text"!==l&&"custom_link"!==l||e?e:_.variableName);const s=D.map(((l,t)=>t===k?Object.assign(Object.assign({},l),{type:a,updatedValue:e}):l));null==Y||Y(s)}if(console.log("originalVariableList",D),R===c.WHATSAPP){const l=null===(o=D.body)||void 0===o?void 0:o.map(((l,t)=>t===k?Object.assign(Object.assign({},l),{type:a,updatedValue:e}):l));console.log("lib-updatedVariables",l),null==Y||Y((e=>Object.assign(Object.assign({},e),{body:l,buttons:D.buttons})))}}function ee(e,l,t){var o,a,n;const i=Object.assign({},Z),s=null===(o=null==i?void 0:i.components)||void 0===o?void 0:o.map((t=>{var o,a,n,i,s;const u=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!==(s=null===(i=null===(n=u.example)||void 0===n?void 0:n.body_text)||void 0===i?void 0:i[0])&&void 0!==s?s:[]];t[e]=l.replace("{{","").replace("}}","").replace("((","").replace("))","");const o=Object.assign(Object.assign({},u.example),{body_text:[t]});return Object.assign(Object.assign({},u),{example:o})}return console.log("updateComponent",u),t}));if(i.components=s,(null===(a=null==i?void 0:i.mapping)||void 0===a?void 0:a.body)&&Array.isArray(null===(n=null==i?void 0:i.mapping)||void 0===n?void 0:n.body))try{i.mapping=Object.assign(Object.assign({},i.mapping),{body:i.mapping.body.map(((t,o)=>e===o?l:t))})}catch(e){console.log("error",e)}null==q||q(Object.assign({},i))}return a((()=>{E&&(null==j||j())}),[E]),a((()=>{!function(){var e,l,t,o,a;const n="mobile"===z?"template_html_mobile":"template_html_desktop",i=document.getElementById(n),s=(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);R===c.EMAIL&&(null==F||F(s))}()}),[G]),a((()=>{var e;const l=[];let t=[];if(R!==c.MESSAGE||K){"link"===(null==_?void 0:_.type)?(l.push({label:"",options:[y,f]}),H(y)):(l.push({label:"",options:[y,f]}),H(f));const e=null!=J?J:[];console.log("globalOptions",e),M([...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],console.log("allOptions",t)}else{const e=null!=J?J:[];console.log("globalOptions",e),M([{label:"",options:[f,y]},...e]),t=[{label:"",options:[f,y]},...e]}if((R===c.WHATSAPP||R===c.EMAIL||R===c.MESSAGE)&&_.updatedValue)if(r.test(_.updatedValue)&&R===c.WHATSAPP||_.updatedValue.startsWith("{{")&&R!==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("}}","");O?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}(_,t,R);e.value&&H(e)}else(null===(e=_.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(H(y),L(_.updatedValue.split("https://")[1])):(H(f),L(_.updatedValue))}),[]),a((()=>{z&&W&&w&&setTimeout((()=>{X("custom_link"===(null==W?void 0:W.value)?`https://${w}`:w,W.value)}),100)}),[z]),a((()=>{!B&&W&&_.updatedValue&&setTimeout((()=>{X("custom_link"===(null==W?void 0:W.value)?`https://${_.updatedValue}`:_.updatedValue,W.value),N(!0)}),100)}),[W]),e(x,Object.assign({channel:R,focused:E,onMouseEnter:()=>P(!0),onMouseLeave:()=>P(!1)},{children:[l("div",Object.assign({style:{marginBottom:8}},{children:e(p,Object.assign({style:{color:U&&!W?b.content.negative:b.content.primary}},{children:[null===(T=_.variableName)||void 0===T?void 0:T.replace("{{","").replace("}}","")," ","link"===(null==_?void 0:_.type)?"link":"variable"]}))})),l("div",Object.assign({style:{marginBottom:12}},{children:O?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(m,{children:d(null!==(S=null==W?void 0:W.label)&&void 0!==S?S:"",20,!0)}),l(t,{onClick:()=>{$(!I)},width:24,height:24,color:b.content.primary})]})):l(s,{options:C,isSearchable:!1,onSelect:Q,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(u,{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}-${k}`,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 than 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"===_.type||"custom_link"===W.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{!function(e,l){var t;L(l);const o="custom_link"===(null==W?void 0:W.value)?`https://${l}`:l;X(o,e),R===c.WHATSAPP&&(null==ee||ee(null!==(t=_.index)&&void 0!==t?t:0,o))}(W.value,e)}}),I&&l(i,{zIndex:2e3,data:null!=A?A:[],showVariable:I,setShowVariable:$,placeholder:"Add a variable",customTrigger:e=>{console.log("variable",e),null==V||V(!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.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{x as Container,j as default};
|