@bikdotai/bik-component-library 0.0.817-beta.12 → 0.0.817-beta.13
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.
- package/dist/cjs/components/template-preview/RCS/RCSChatPreview.js +1 -1
- package/dist/cjs/components/template-preview/RCS/RCSChatPreview.js.map +1 -1
- package/dist/cjs/components/template-preview/helpers/TemplateCreatorHelper.js +1 -1
- package/dist/cjs/components/template-preview/helpers/TemplateCreatorHelper.js.map +1 -1
- package/dist/cjs/components/template-preview/models/RCSTemplate.js.map +1 -1
- package/dist/cjs/editor/BikEditor.js +1 -1
- package/dist/cjs/editor/BikEditor.js.map +1 -1
- package/dist/cjs/editor/BikEditor.utils.js +2 -2
- package/dist/cjs/editor/BikEditor.utils.js.map +1 -1
- package/dist/esm/components/template-preview/RCS/RCSChatPreview.js +72 -68
- package/dist/esm/components/template-preview/RCS/RCSChatPreview.js.map +1 -1
- package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.d.ts +0 -8
- package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.js +61 -79
- package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.js.map +1 -1
- package/dist/esm/components/template-preview/models/RCSTemplate.d.ts +0 -7
- package/dist/esm/components/template-preview/models/RCSTemplate.js.map +1 -1
- package/dist/esm/editor/BikEditor.js +60 -54
- package/dist/esm/editor/BikEditor.js.map +1 -1
- package/dist/esm/editor/BikEditor.utils.d.ts +5 -2
- package/dist/esm/editor/BikEditor.utils.js +104 -96
- package/dist/esm/editor/BikEditor.utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),R=require("react"),I=require("../../template-context-mapper/context/templateModalContext.js"),H=require("../helpers/templateMiscHelper.js"),L=require("../helpers/VariableEditorHelper.js"),a=require("../models/TemplateMeta.js"),O=require("../WhatsApp/ChatBtn.js"),B=require("./RCSButtons.js"),T=require("./RCSMediaCard.js"),o=require("./RCSPreview.styled.js"),E=new L.VariableEditorHelper,Y=y=>{const{bodyText:p,titleText:c,headerMediaType:t,headerText:M,headerAssetLink:s,headerAssetName:C,imagePreviewStyles:x,size:h,bodyVariableList:j,headerVariableList:P,buttons:l,carouselCardIndex:r,isWhatsappCarousel:v,isPreview:A,titleVariableList:_,templateConfiguration:i}=y,b=E.format(p?.replace(/</g,"<").replace(/>/g,">"),j),w=E.format(M?.replace(/</g,"<").replace(/>/g,">"),P),D=E.format(c?.replace(/</g,"<").replace(/>/g,">"),_),{selectedCarouselIndex:d,isProductCarouselType:S,errorIndexes:q,isCarouselHovered:N}=I.useTemplateModalContext(),g=R.useMemo(()=>H.isRichAndCarouselCards(i?.templateType),[i?.templateType]),n=R.useMemo(()=>i?.orientation=="HORIZONTAL",[i]);return e.jsxs(o.RCSPreviewContainer,{isCarouselCard:r!=null&&r>-1,showBorder:r!=null&&r===d||S&&r!=null&&r>-1&&d!=null&&d>-1,hasError:q?.includes(r??-2),isWhatsappCarousel:v,isPreview:A,showDashedBorder:S&&N&&(d??-1)<0&&(r??-1)>-1,needBorder:g,isHorizontalOrientation:n,children:[!n&&e.jsx(e.Fragment,{children:t===a.HEADER_TYPES.TEXT?e.jsx(o.HeaderTextContainer,{dangerouslySetInnerHTML:{__html:w}}):t!==a.HEADER_TYPES.NONE&&s&&t!==a.HEADER_TYPES.DOCUMENT?e.jsx(T.RCSMediaCard,{headerAssetLink:s,headerAssetName:C,mediaType:t,imagePreviewStyles:t===a.HEADER_TYPES.IMAGE?x:{}}):null}),e.jsxs("div",{style:{width:n?"50%":""},children:[e.jsxs("div",{className:g?"":"text--template",children:[!!c&&e.jsx(e.Fragment,{children:e.jsx(o.TitleTextContainer,{dangerouslySetInnerHTML:{__html:D}})}),!!p&&e.jsx(e.Fragment,{children:e.jsx(o.RcsHtmlContainer,{dangerouslySetInnerHTML:{__html:b},style:{paddingTop:c?0:12}})}),t===a.HEADER_TYPES.DOCUMENT?e.jsx(T.PdfMediaCard,{headerAssetLink:s,headerAssetName:C}):e.jsx(e.Fragment,{})]}),l&&l.length>0?H.isRichAndCarouselCards(i?.templateType)?e.jsx(e.Fragment,{children:l.map((u,m)=>e.jsx(O.ChatBtn,{text:u.text,size:h},m))}):e.jsx(o.RCSChatBtnContainer,{children:l.map((u,m)=>e.jsx(B.RCSButtons,{text:u.text,size:h},m))}):null]}),n&&t!==a.HEADER_TYPES.NONE&&s&&t!==a.HEADER_TYPES.DOCUMENT&&e.jsx(T.RCSMediaCard,{headerAssetLink:s,headerAssetName:C,mediaType:t,imagePreviewStyles:t===a.HEADER_TYPES.IMAGE?x:{},isHorizontal:n})]})};exports.RCSChatPreview=Y;
|
|
2
2
|
//# sourceMappingURL=RCSChatPreview.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RCSChatPreview.js","sources":["../../../../../src/components/template-preview/RCS/RCSChatPreview.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { useTemplateModalContext } from '@src/components/template-context-mapper/context/templateModalContext';\nimport { isRichAndCarouselCards } from '../helpers/templateMiscHelper';\nimport { VariableEditorHelper } from '../helpers/VariableEditorHelper';\nimport { RCS_TEMPLATE_TYPE, RCSPreviewPropsV2 } from '../models/RCSTemplate';\nimport { HEADER_TYPES } from '../models/TemplateMeta';\nimport { ChatBtn } from '../WhatsApp/ChatBtn';\nimport { RCSButtons } from './RCSButtons';\nimport { PdfMediaCard, RCSMediaCard } from './RCSMediaCard';\nimport {\n\tHeaderTextContainer,\n\tRCSChatBtnContainer,\n\tRcsHtmlContainer,\n\tRCSPreviewContainer,\n\tTitleTextContainer,\n} from './RCSPreview.styled';\n\nconst variableEditorHelper = new VariableEditorHelper();\n\nexport const RCSChatPreview = (props: RCSPreviewPropsV2) => {\n\tconst {\n\t\tbodyText,\n\t\ttitleText,\n\t\theaderMediaType,\n\t\theaderText,\n\t\theaderAssetLink,\n\t\theaderAssetName,\n\t\timagePreviewStyles,\n\t\tsize,\n\t\tbodyVariableList,\n\t\theaderVariableList,\n\t\tbuttons,\n\t\tcarouselCardIndex,\n\t\tisWhatsappCarousel,\n\t\tisPreview,\n\t\ttitleVariableList,\n\t\ttemplateConfiguration,\n\t} = props;\n\n\tconst bodyHTML = variableEditorHelper.format(\n\t\tbodyText?.replace(/</g, '<').replace(/>/g, '>'),\n\t\tbodyVariableList,\n\t);\n\tconst headerHtml = variableEditorHelper.format(\n\t\theaderText?.replace(/</g, '<').replace(/>/g, '>'),\n\t\theaderVariableList,\n\t);\n\tconst titleHtml = variableEditorHelper.format(\n\t\ttitleText?.replace(/</g, '<').replace(/>/g, '>'),\n\t\ttitleVariableList,\n\t);\n\tconst {\n\t\tselectedCarouselIndex,\n\t\tisProductCarouselType,\n\t\terrorIndexes,\n\t\tisCarouselHovered,\n\t} = useTemplateModalContext();\n\n\tconst isRichCardTypeTemplate = useMemo(() => {\n\t\treturn isRichAndCarouselCards(\n\t\t\ttemplateConfiguration?.templateType as RCS_TEMPLATE_TYPE,\n\t\t);\n\t}, [templateConfiguration?.templateType]);\n\n\tconst isHorizontalOrientation = useMemo(() => {\n\t\treturn templateConfiguration?.orientation == 'HORIZONTAL';\n\t}, [templateConfiguration]);\n\n\
|
|
1
|
+
{"version":3,"file":"RCSChatPreview.js","sources":["../../../../../src/components/template-preview/RCS/RCSChatPreview.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { useTemplateModalContext } from '@src/components/template-context-mapper/context/templateModalContext';\nimport { isRichAndCarouselCards } from '../helpers/templateMiscHelper';\nimport { VariableEditorHelper } from '../helpers/VariableEditorHelper';\nimport { RCS_TEMPLATE_TYPE, RCSPreviewPropsV2 } from '../models/RCSTemplate';\nimport { HEADER_TYPES } from '../models/TemplateMeta';\nimport { ChatBtn } from '../WhatsApp/ChatBtn';\nimport { RCSButtons } from './RCSButtons';\nimport { PdfMediaCard, RCSMediaCard } from './RCSMediaCard';\nimport {\n\tHeaderTextContainer,\n\tRCSChatBtnContainer,\n\tRcsHtmlContainer,\n\tRCSPreviewContainer,\n\tTitleTextContainer,\n} from './RCSPreview.styled';\n\nconst variableEditorHelper = new VariableEditorHelper();\n\nexport const RCSChatPreview = (props: RCSPreviewPropsV2) => {\n\tconst {\n\t\tbodyText,\n\t\ttitleText,\n\t\theaderMediaType,\n\t\theaderText,\n\t\theaderAssetLink,\n\t\theaderAssetName,\n\t\timagePreviewStyles,\n\t\tsize,\n\t\tbodyVariableList,\n\t\theaderVariableList,\n\t\tbuttons,\n\t\tcarouselCardIndex,\n\t\tisWhatsappCarousel,\n\t\tisPreview,\n\t\ttitleVariableList,\n\t\ttemplateConfiguration,\n\t} = props;\n\n\tconst bodyHTML = variableEditorHelper.format(\n\t\tbodyText?.replace(/</g, '<').replace(/>/g, '>'),\n\t\tbodyVariableList,\n\t);\n\tconst headerHtml = variableEditorHelper.format(\n\t\theaderText?.replace(/</g, '<').replace(/>/g, '>'),\n\t\theaderVariableList,\n\t);\n\tconst titleHtml = variableEditorHelper.format(\n\t\ttitleText?.replace(/</g, '<').replace(/>/g, '>'),\n\t\ttitleVariableList,\n\t);\n\tconst {\n\t\tselectedCarouselIndex,\n\t\tisProductCarouselType,\n\t\terrorIndexes,\n\t\tisCarouselHovered,\n\t} = useTemplateModalContext();\n\n\tconst isRichCardTypeTemplate = useMemo(() => {\n\t\treturn isRichAndCarouselCards(\n\t\t\ttemplateConfiguration?.templateType as RCS_TEMPLATE_TYPE,\n\t\t);\n\t}, [templateConfiguration?.templateType]);\n\n\tconst isHorizontalOrientation = useMemo(() => {\n\t\treturn templateConfiguration?.orientation == 'HORIZONTAL';\n\t}, [templateConfiguration]);\n\n\treturn (\n\t\t<RCSPreviewContainer\n\t\t\tisCarouselCard={carouselCardIndex != undefined && carouselCardIndex > -1}\n\t\t\tshowBorder={\n\t\t\t\t(carouselCardIndex != undefined &&\n\t\t\t\t\tcarouselCardIndex === selectedCarouselIndex) ||\n\t\t\t\t(isProductCarouselType &&\n\t\t\t\t\tcarouselCardIndex != undefined &&\n\t\t\t\t\tcarouselCardIndex > -1 &&\n\t\t\t\t\tselectedCarouselIndex != undefined &&\n\t\t\t\t\tselectedCarouselIndex > -1)\n\t\t\t}\n\t\t\thasError={errorIndexes?.includes(carouselCardIndex ?? -2)}\n\t\t\tisWhatsappCarousel={isWhatsappCarousel}\n\t\t\tisPreview={isPreview}\n\t\t\tshowDashedBorder={\n\t\t\t\tisProductCarouselType &&\n\t\t\t\tisCarouselHovered &&\n\t\t\t\t(selectedCarouselIndex ?? -1) < 0 &&\n\t\t\t\t(carouselCardIndex ?? -1) > -1\n\t\t\t}\n\t\t\tneedBorder={isRichCardTypeTemplate}\n\t\t\tisHorizontalOrientation={isHorizontalOrientation}\n\t\t>\n\t\t\t{!isHorizontalOrientation && (\n\t\t\t\t<>\n\t\t\t\t\t{headerMediaType === HEADER_TYPES.TEXT ? (\n\t\t\t\t\t\t<HeaderTextContainer\n\t\t\t\t\t\t\tdangerouslySetInnerHTML={{ __html: headerHtml }}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) : headerMediaType !== HEADER_TYPES.NONE &&\n\t\t\t\t\t headerAssetLink &&\n\t\t\t\t\t headerMediaType !== HEADER_TYPES.DOCUMENT ? (\n\t\t\t\t\t\t<RCSMediaCard\n\t\t\t\t\t\t\theaderAssetLink={headerAssetLink}\n\t\t\t\t\t\t\theaderAssetName={headerAssetName}\n\t\t\t\t\t\t\tmediaType={headerMediaType}\n\t\t\t\t\t\t\timagePreviewStyles={\n\t\t\t\t\t\t\t\theaderMediaType === HEADER_TYPES.IMAGE ? imagePreviewStyles : {}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t) : null}\n\t\t\t\t</>\n\t\t\t)}\n\t\t\t<div style={{ width: isHorizontalOrientation ? '50%' : '' }}>\n\t\t\t\t<div className={isRichCardTypeTemplate ? '' : 'text--template'}>\n\t\t\t\t\t{!!titleText && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<TitleTextContainer\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t__html: titleHtml,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t)}\n\n\t\t\t\t\t{!!bodyText && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<RcsHtmlContainer\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t__html: bodyHTML,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\tstyle={{ paddingTop: titleText ? 0 : 12 }}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t)}\n\t\t\t\t\t{headerMediaType === HEADER_TYPES.DOCUMENT ? (\n\t\t\t\t\t\t<PdfMediaCard {...{ headerAssetLink, headerAssetName }} />\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<></>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\n\t\t\t\t{buttons && buttons.length > 0 ? (\n\t\t\t\t\tisRichAndCarouselCards(\n\t\t\t\t\t\ttemplateConfiguration?.templateType as RCS_TEMPLATE_TYPE,\n\t\t\t\t\t) ? (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{buttons.map((button, i) => (\n\t\t\t\t\t\t\t\t<ChatBtn key={i} text={button.text} size={size} />\n\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t</>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<RCSChatBtnContainer>\n\t\t\t\t\t\t\t{buttons.map((button, i) => (\n\t\t\t\t\t\t\t\t<RCSButtons key={i} text={button.text} size={size} />\n\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t</RCSChatBtnContainer>\n\t\t\t\t\t)\n\t\t\t\t) : null}\n\t\t\t</div>\n\t\t\t{isHorizontalOrientation &&\n\t\t\t\theaderMediaType !== HEADER_TYPES.NONE &&\n\t\t\t\theaderAssetLink &&\n\t\t\t\theaderMediaType !== HEADER_TYPES.DOCUMENT && (\n\t\t\t\t\t<RCSMediaCard\n\t\t\t\t\t\theaderAssetLink={headerAssetLink}\n\t\t\t\t\t\theaderAssetName={headerAssetName}\n\t\t\t\t\t\tmediaType={headerMediaType}\n\t\t\t\t\t\timagePreviewStyles={\n\t\t\t\t\t\t\theaderMediaType === HEADER_TYPES.IMAGE ? imagePreviewStyles : {}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisHorizontal={isHorizontalOrientation}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t</RCSPreviewContainer>\n\t);\n};\n"],"names":["variableEditorHelper","VariableEditorHelper","RCSChatPreview","props","bodyText","titleText","headerMediaType","headerText","headerAssetLink","headerAssetName","imagePreviewStyles","size","bodyVariableList","headerVariableList","buttons","carouselCardIndex","isWhatsappCarousel","isPreview","titleVariableList","templateConfiguration","bodyHTML","headerHtml","titleHtml","selectedCarouselIndex","isProductCarouselType","errorIndexes","isCarouselHovered","useTemplateModalContext","isRichCardTypeTemplate","useMemo","isRichAndCarouselCards","isHorizontalOrientation","jsxs","RCSPreviewContainer","jsx","Fragment","HEADER_TYPES","HeaderTextContainer","RCSMediaCard","TitleTextContainer","RcsHtmlContainer","PdfMediaCard","button","i","ChatBtn","RCSChatBtnContainer","RCSButtons"],"mappings":"4dAiBMA,EAAuB,IAAIC,EAAAA,qBAEpBC,EAAkBC,GAA6B,CAC3D,KAAM,CACL,SAAAC,EACA,UAAAC,EACA,gBAAAC,EACA,WAAAC,EACA,gBAAAC,EACA,gBAAAC,EACA,mBAAAC,EACA,KAAAC,EACA,iBAAAC,EACA,mBAAAC,EACA,QAAAC,EACA,kBAAAC,EACA,mBAAAC,EACA,UAAAC,EACA,kBAAAC,EACA,sBAAAC,CAAA,EACGhB,EAEEiB,EAAWpB,EAAq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UAAWH,EACX,mBACCA,IAAoB8B,EAAAA,aAAa,MAAQ1B,EAAqB,CAAA,EAE/D,aAAcqB,CAAA,CAAA,CACf,CAAA,CAAA,CAIL"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("date-fns"),b=require("../../../constants/Theme.js"),h=require("../constants/regexPatterns.js"),r=require("../constants/TemplateConstants.js"),d=require("../models/TemplateMeta.js"),u=require("../models/WhatsAppTemplate.js"),A=require("../utils/TemplateHelperUtils.js");class P{parseDataFromHeaderComponent(t,o,n){const e={headerType:d.HEADER_TYPES.NONE,headerVariables:[]},a=t?.components?.find(l=>l.type==="HEADER");if(a){e.headerType=a.format,e.headerText=a.text,e.headerAssetLink=a.example?.header_handle?.[0];const l=a.example?.header_text?.[0],c=t.mapping?.header?.[0],i=c;if(c){const s=c?.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),p=/\(\(/.test(c),E=n===u.POD.CHATBOT&&i&&i?.startsWith("((")&&i?.endsWith("))"),m={idx:0,variableVal:o||E?l:i,editable:p,editableDefaultValues:p?void 0:l,variableName:s};e.headerVariables=[m],a.example?.header_text?.length&&(e.headerText=e.headerText?.replace("{{1}}",`{{${s}}}`))}}return e}validateState(t){const o=new RegExp("\\p{Extended_Pictographic}","u");let n="valid";const e={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},a=new A.TemplateHelperUtils;let l=!1;const c=i=>{document.getElementById(i)?.scrollIntoView({behavior:"smooth",block:"nearest"})};if(t.meta?.name?t.meta.name?.trim().length>r.NAME_LEN_LIMIT?(e.meta.name=r.NAME_LEN_ERROR,n="invalid"):h.specialCharPattern.test(t.meta.name?.trim())&&(e.meta.name=r.NO_SPECIAL_CHAR,n="invalid"):(e.meta.name=r.REQUIRED_FIELD,n="invalid"),e.meta.name&&!l&&(c(r.CREATE_TEMPLATE_DOM_IDS.name),l=!0),t.headerType===d.HEADER_TYPES.TEXT){const i=t.headerText?.trim()??"";if(!i)e.header=r.REQUIRED_FIELD,n="invalid";else if(i.length>r.HEADER_TEXT_LEN_LIMIT)e.header=r.HEADER_LEN_ERROR,n="invalid";else{const s=a.getTemplateVariablesFromState(i);s&&s.length>1&&(e.header=r.ONE_VAR_ALLOWED,n="invalid")}}else t.headerType===d.HEADER_TYPES.DOCUMENT||t.headerType===d.HEADER_TYPES.IMAGE||(t.headerType,d.HEADER_TYPES.VIDEO);if((t.headerType===d.HEADER_TYPES.DOCUMENT||t.headerType===d.HEADER_TYPES.IMAGE||t.headerType===d.HEADER_TYPES.VIDEO)&&(t.headerAssetLink||(e.header=r.HEADER_ASSET_LINK_ERROR,n="invalid")),e.header&&!l&&(c(r.CREATE_TEMPLATE_DOM_IDS.header),l=!0),t.bodyText?t.bodyTextRaw&&t.bodyTextRaw?.trim().length>r.BODY_TEXT_LEN_LIMIT&&(e.body=r.BODY_LEN_ERROR,n="invalid"):(e.body=r.REQUIRED_FIELD,n="invalid"),e.body&&!l&&(c(r.CREATE_TEMPLATE_DOM_IDS.body),l=!0),t.footerText&&t.footerText.length>r.HEADER_TEXT_LEN_LIMIT&&(e.footer=r.HEADER_LEN_ERROR,n="invalid"),e?.footer&&!l&&(c(r.CREATE_TEMPLATE_DOM_IDS.footer),l=!0),t.actionsType===d.ACTIONS_TYPES.CTA_BTN){if(t.ctaBtn?.phoneNumber?.isChecked){const i=t.ctaBtn.phoneNumber.btnText?.trim(),s=t.ctaBtn.phoneNumber.phoneNumber;e.ctaBtn&&!i?(e.ctaBtn.phoneNumber.btnText=r.REQUIRED_FIELD,n="invalid"):e.ctaBtn&&i&&i.length>r.QUICK_REPLY_BTN_TEXT_LIMIT?(e.ctaBtn.phoneNumber.btnText=r.QUICK_REPLY_LEN_ERROR,n="invalid"):e.ctaBtn&&i&&o.test(i)&&(e.ctaBtn.phoneNumber.btnText=r.BUTTON_EMOJI_ERROR,n="invalid"),e.ctaBtn&&!s?(e.ctaBtn.phoneNumber.link=r.REQUIRED_FIELD,n="invalid"):e.ctaBtn&&s&&s.length<10&&(e.ctaBtn.phoneNumber.link=r.VALID_PHONE_NUMBER,n="invalid")}if(t.ctaBtn?.websiteLinkBtn?.isChecked){const i=t.ctaBtn.websiteLinkBtn.btnText?.trim(),s=t.ctaBtn.websiteLinkBtn.linkOpens?.trim(),p=t.ctaBtn.websiteLinkBtn.placeholder?.trim();e.ctaBtn&&!i?(e.ctaBtn.websiteLink.btnText=r.REQUIRED_FIELD,n="invalid"):e.ctaBtn&&i&&i.length>r.QUICK_REPLY_BTN_TEXT_LIMIT?(e.ctaBtn.websiteLink.btnText=r.QUICK_REPLY_LEN_ERROR,n="invalid"):e.ctaBtn&&i&&o.test(i)&&(e.ctaBtn.websiteLink.btnText=r.BUTTON_EMOJI_ERROR,n="invalid"),e.ctaBtn&&!s&&!p&&(e.ctaBtn.websiteLink.link=r.REQUIRED_FIELD,n="invalid")}}else if(t.actionsType===d.ACTIONS_TYPES.QUICK_REPLY){const i=["","",""];t.quickReply.forEach((s,p)=>{const E=s.text?.trim();if(!E)i[p]=r.REQUIRED_FIELD,n="invalid";else if(E.length>r.QUICK_REPLY_NAME_LEN_LIMIT)i[p]=r.QUICK_REPLY_LEN_ERROR,n="invalid";else if(o.test(E))i[p]=r.BUTTON_EMOJI_ERROR,n="invalid";else{const m=[...t.quickReply];m.splice(p,1),m.find(_=>_.text===E)&&(i[p]=r.QUICK_REPLY_NAME_ERROR,n="invalid")}}),e.quickReply=i}if(t.actionsType===d.ACTIONS_TYPES.CTA_BTN||t.actionsType===d.ACTIONS_TYPES.QUICK_REPLY){const i=e.quickReply?.reduce((s,p)=>s||!!p,!1);(e?.ctaBtn?.websiteLink?.link||e.ctaBtn?.websiteLink?.btnText||e.ctaBtn?.phoneNumber?.link||e.ctaBtn?.phoneNumber?.btnText||i)&&!l&&(c(r.CREATE_TEMPLATE_DOM_IDS.actionButtons),l=!0)}return{status:n,errors:e}}parseBodyComponent(t,o=!1,n,e){const a=[];let l="";const c=t.components?.find(i=>i.type==="BODY");return c&&(c.example?.body_text?.[0]?.forEach((i,s)=>{let p=t.mapping?.body?.[s];const E=p,m=p&&/\(\(/.test(p),T=p?.match(h.placeHolderNamePattern);T?.[2]&&(p=T?.[2]);const _=e===u.POD.CHATBOT&&E&&E?.startsWith("((")&&E?.endsWith("))");a.push({idx:s,variableVal:n||_?i:E,editable:!!m,editableDefaultValues:m?void 0:i,variableName:p??""})}),t.htmlContentUrl?l=t.htmlContentUrl:l=c.text?.split(/\{\{[0-9]+\}\}/).length?c.text?.split(/\{\{[0-9]+\}\}/).map((i,s)=>{if(a?.[s]){const p=a[s].variableName;return o?`${i}{{${p}}}`:`${i} <span> </span><span style="color: ${b.COLORS.content.brand}; text-decoration: underline;">{{${p}}}</span><span> </span>`}return i}).join(""):""),{bodyVariable:a,bodyText:l}}parseTitleComponent(t,o=!1,n){const e=[];let a="";const l=t.components?.find(c=>c.type==="TITLE");return l&&(l.example?.title_text?.[0]?.forEach((c,i)=>{let s=t.mapping?.body?.[i];const p=s,E=s&&/\(\(/.test(s),m=s?.match(h.placeHolderNamePattern);m?.[2]&&(s=m?.[2]),e.push({idx:i,variableVal:n?c:p,editable:!!E,editableDefaultValues:E?void 0:c,variableName:s??""})}),t.htmlContentUrl?a=t.htmlContentUrl:a=l.text?.split(/\{\{[0-9]+\}\}/).length?l.text?.split(/\{\{[0-9]+\}\}/).map((c,i)=>{if(e?.[i]){const s=e[i].variableName;return o?`${c}{{${s}}}`:`${c} <span> </span><span style="color: ${b.COLORS.content.brand}; text-decoration: underline;">{{${s}}}</span><span> </span>`}return c}).join(""):""),{titleText:a,titleVariables:e}}parseFooterComponent(t){return t.components?.find(n=>n.type==="FOOTER")?.text}parseButtonComponent(t){const o={actionsType:d.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},n=t.components?.find(e=>e.type==="BUTTONS");if(n&&n?.buttons?.length){const e=n?.buttons?.[0].type==="QUICK_REPLY"?d.ACTIONS_TYPES.QUICK_REPLY:d.ACTIONS_TYPES.CTA_BTN;if(o.actionsType=e,e===d.ACTIONS_TYPES.QUICK_REPLY){const a=n?.buttons?.map(l=>l)??[];o.quickReply=a}else e===d.ACTIONS_TYPES.CTA_BTN&&n?.buttons?.forEach(a=>{if(a.phone_number&&(o.ctaBtn.phoneNumber={isChecked:!0,btnText:a.text,phoneNumber:a.phone_number}),a.url){const l=t?.mapping?.buttons?.[0]??void 0;let c=!1;l&&h.editableVarPattern.test(l)&&(c=!0),o.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:a.text,linkOpens:c?a.example?.[0]:a.url,placeholder:c?void 0:l}}});o.allButtons=n.buttons?.map(a=>a.type==="COPY_CODE"?{...a,placeholder:Array.isArray(a.example)?a.example[0]:a?.example||""}:a)}return o}parseLimitedTimeOfferComponent(t,o){const n={text:"",dateTime:"",code:""};return t.components.forEach(e=>{if(e.type==="limited_time_offer"){n.text=e.limited_time_offer?.text??"";const a=e.example?.limited_time_offer;a&&a.startsWith("{{")&&a.endsWith("}}")?n.dateTime=a:n.dateTime=D.format(a?new Date(a):new Date,"MMM dd")}o.forEach(a=>{a.type==="COPY_CODE"&&(n.code=a.placeholder??"")})}),n}parseCallPermissionComponent(t){const o=t.components?.find(n=>n.type==="CALL_PERMISSION_REQUEST");return{showCallPermissionCard:!!o,callPermissionText:o?.text}}async parseUITemplateFromDBFormat(t){const{dbFormattedTemplate:o,isDuplicate:n,isV2:e=!1,showSampleValues:a,pod:l}=t,{headerType:c,headerAssetLink:i,headerAssetName:s,headerText:p,headerVariables:E}=await this.parseDataFromHeaderComponent(o,void 0,l),{bodyText:m,bodyVariable:T}=await this.parseBodyComponent(o,e,a,l),{titleText:_,titleVariables:C}=await this.parseTitleComponent(o,e,a),{actionsType:y,quickReply:N,ctaBtn:x,allButtons:R}=await this.parseButtonComponent(o),I=this.parseLimitedTimeOfferComponent(o,R),{showCallPermissionCard:L,callPermissionText:O}=this.parseCallPermissionComponent(o),f={quickReply:N,ctaBtn:x,allButtons:R,meta:{name:n?`${o.label} Copy`:o.label,category:o.category?.toUpperCase(),subCategory:o.templateCategory,language:o.language,templateId:o.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:y,footerText:this.parseFooterComponent(o),bodyVariables:T,bodyText:m,headerType:c,headerAssetLink:i,headerAssetName:s,headerText:p,headerVariables:E,alreadyAsADraft:o.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:I,titleText:_,titleVariables:C,showCallPermissionCard:L,callPermissionText:O},{errors:B}=this.validateState(f);return f.error=B,f}parseTemplateConfiguration(t){let o;const n=t?.content||{};if(typeof n=="string")try{o=JSON.parse(n)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),o={orientation:"VERTICAL"}}else o=n;return{...o,templateType:t?.templateType}}}exports.TemplateCreatorHelper=P;
|
|
2
2
|
//# sourceMappingURL=TemplateCreatorHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateCreatorHelper.js","sources":["../../../../../src/components/template-preview/helpers/TemplateCreatorHelper.ts"],"sourcesContent":["import { format } from 'date-fns';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\teditableVarPattern,\n\tplaceHolderNamePattern,\n\tspecialCharPattern,\n} from '../constants/regexPatterns';\nimport {\n\tBODY_LEN_ERROR,\n\tBODY_TEXT_LEN_LIMIT,\n\tBUTTON_EMOJI_ERROR,\n\tCREATE_TEMPLATE_DOM_IDS,\n\tHEADER_ASSET_LINK_ERROR,\n\tHEADER_LEN_ERROR,\n\tHEADER_TEXT_LEN_LIMIT,\n\tNAME_LEN_ERROR,\n\tNAME_LEN_LIMIT,\n\tNO_SPECIAL_CHAR,\n\tONE_VAR_ALLOWED,\n\tQUICK_REPLY_BTN_TEXT_LIMIT,\n\tQUICK_REPLY_LEN_ERROR,\n\tQUICK_REPLY_NAME_ERROR,\n\tQUICK_REPLY_NAME_LEN_LIMIT,\n\tREQUIRED_FIELD,\n\tVALID_PHONE_NUMBER,\n} from '../constants/TemplateConstants';\nimport {\n\tRCS_TEMPLATE_TYPE,\n\tRCSTemplateConfig,\n\tRCSTemplateType,\n} from '../models/RCSTemplate';\nimport {\n\tACTIONS_TYPES,\n\tHEADER_TYPES,\n\tQUICK_REPLY_BUTTON,\n} from '../models/TemplateMeta';\nimport {\n\tCreateTemplateType,\n\tPOD,\n\ttemplateVariable,\n\tWhatsappPreviewButtonType,\n\tWhatsAppTemplate,\n} from '../models/WhatsAppTemplate';\nimport { TemplateHelperUtils } from '../utils/TemplateHelperUtils';\n\nexport class TemplateCreatorHelper {\n\tprivate parseDataFromHeaderComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tshowSampleValues?: boolean,\n\t\tpod?: string,\n\t) {\n\t\tconst res: {\n\t\t\theaderType: HEADER_TYPES;\n\t\t\theaderAssetLink?: string;\n\t\t\theaderAssetName?: string;\n\t\t\theaderText?: string;\n\t\t\theaderVariables: templateVariable[];\n\t\t} = {\n\t\t\theaderType: HEADER_TYPES.NONE,\n\t\t\theaderVariables: [],\n\t\t};\n\n\t\tconst headerComponent = dbFormattedTemplate?.components?.find(\n\t\t\t(component) => component.type === 'HEADER',\n\t\t);\n\n\t\tif (headerComponent) {\n\t\t\tres.headerType = headerComponent.format as HEADER_TYPES;\n\t\t\tres.headerText = headerComponent.text;\n\n\t\t\tres.headerAssetLink = headerComponent.example?.header_handle?.[0];\n\n\t\t\tconst sampleValue = headerComponent.example?.header_text?.[0];\n\t\t\tconst headerVarPlaceholder = dbFormattedTemplate.mapping?.header?.[0];\n\t\t\tconst originalVariable = headerVarPlaceholder;\n\t\t\tif (headerVarPlaceholder) {\n\t\t\t\tconst normalizedName = headerVarPlaceholder\n\t\t\t\t\t?.replace('[[', '')\n\t\t\t\t\t.replace(']]', '')\n\t\t\t\t\t.replace('{{', '')\n\t\t\t\t\t.replace('}}', '')\n\t\t\t\t\t.replace('((', '')\n\t\t\t\t\t.replace('))', '');\n\t\t\t\tconst editable = /\\(\\(/.test(headerVarPlaceholder);\n\t\t\t\tconst isChatbotCustomText =\n\t\t\t\t\tpod === POD.CHATBOT &&\n\t\t\t\t\toriginalVariable &&\n\t\t\t\t\toriginalVariable?.startsWith('((') &&\n\t\t\t\t\toriginalVariable?.endsWith('))');\n\n\t\t\t\tconst reduxHeaderVar: templateVariable = {\n\t\t\t\t\tidx: 0,\n\t\t\t\t\tvariableVal:\n\t\t\t\t\t\tshowSampleValues || isChatbotCustomText\n\t\t\t\t\t\t\t? sampleValue\n\t\t\t\t\t\t\t: originalVariable,\n\t\t\t\t\teditable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: normalizedName,\n\t\t\t\t};\n\t\t\t\tres.headerVariables = [reduxHeaderVar];\n\t\t\t\tif (headerComponent.example?.header_text?.length) {\n\t\t\t\t\tres.headerText = res.headerText?.replace(\n\t\t\t\t\t\t/** since there will be only one variable in template so hard replace */\n\t\t\t\t\t\t'{{1}}',\n\t\t\t\t\t\t`{{${normalizedName}}}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\t/**\n\t * Check if current template state is ready for saving as a draft/submit-template or not\n\t * @param state\n\t */\n\tvalidateState(state: CreateTemplateType): {\n\t\tstatus: 'invalid' | 'valid';\n\t\terrors: CreateTemplateType['error'];\n\t} {\n\t\tconst emojiRegex = /\\p{Extended_Pictographic}/u;\n\t\tlet status: 'invalid' | 'valid' = 'valid';\n\t\tconst errors: CreateTemplateType['error'] = {\n\t\t\tmeta: {},\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber: { btnText: '', link: '' },\n\t\t\t\twebsiteLink: { btnText: '', link: '' },\n\t\t\t},\n\t\t\tquickReply: [null, null, null],\n\t\t};\n\t\tconst templateHelperUtils = new TemplateHelperUtils();\n\t\tlet isScrolled = false;\n\n\t\tconst scrollByElementId = (elementId: string) => {\n\t\t\tdocument.getElementById(elementId)?.scrollIntoView({\n\t\t\t\tbehavior: 'smooth',\n\t\t\t\tblock: 'nearest',\n\t\t\t});\n\t\t};\n\n\t\tif (!state.meta?.name) {\n\t\t\terrors.meta!.name = REQUIRED_FIELD;\n\t\t\tstatus = 'invalid';\n\t\t} else if (state.meta.name?.trim().length > NAME_LEN_LIMIT) {\n\t\t\terrors.meta!.name = NAME_LEN_ERROR;\n\t\t\tstatus = 'invalid';\n\t\t} else if (specialCharPattern.test(state.meta.name?.trim())) {\n\t\t\terrors.meta!.name = NO_SPECIAL_CHAR;\n\t\t\tstatus = 'invalid';\n\t\t}\n\n\t\tif (!!errors.meta!.name && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.name);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.headerType === HEADER_TYPES.TEXT) {\n\t\t\tconst text = state.headerText?.trim() ?? '';\n\t\t\tif (!text) {\n\t\t\t\terrors.header = REQUIRED_FIELD;\n\t\t\t\tstatus = 'invalid';\n\t\t\t} else if (text.length > HEADER_TEXT_LEN_LIMIT) {\n\t\t\t\terrors.header = HEADER_LEN_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t} else {\n\t\t\t\tconst variableList =\n\t\t\t\t\ttemplateHelperUtils.getTemplateVariablesFromState(text);\n\t\t\t\tif (variableList && variableList.length > 1) {\n\t\t\t\t\terrors.header = ONE_VAR_ALLOWED;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (state.headerType === HEADER_TYPES.DOCUMENT) {\n\t\t\t/** @todo add media header validations */\n\t\t} else if (state.headerType === HEADER_TYPES.IMAGE) {\n\t\t\t/** @todo add media header validations */\n\t\t} else if (state.headerType === HEADER_TYPES.VIDEO) {\n\t\t\t/** @todo add media header validations */\n\t\t}\n\n\t\tif (\n\t\t\tstate.headerType === HEADER_TYPES.DOCUMENT ||\n\t\t\tstate.headerType === HEADER_TYPES.IMAGE ||\n\t\t\tstate.headerType === HEADER_TYPES.VIDEO\n\t\t) {\n\t\t\tif (!state.headerAssetLink) {\n\t\t\t\terrors.header = HEADER_ASSET_LINK_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t}\n\t\t}\n\n\t\tif (!!errors.header && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.header);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (!state.bodyText) {\n\t\t\terrors.body = REQUIRED_FIELD;\n\t\t\tstatus = 'invalid';\n\t\t} else {\n\t\t\tif (\n\t\t\t\tstate.bodyTextRaw &&\n\t\t\t\tstate.bodyTextRaw?.trim().length > BODY_TEXT_LEN_LIMIT\n\t\t\t) {\n\t\t\t\terrors.body = BODY_LEN_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t}\n\t\t}\n\n\t\tif (!!errors.body && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.body);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.footerText && state.footerText.length > HEADER_TEXT_LEN_LIMIT) {\n\t\t\terrors.footer = HEADER_LEN_ERROR;\n\t\t\tstatus = 'invalid';\n\t\t}\n\n\t\tif (!!errors?.footer && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.footer);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.actionsType === ACTIONS_TYPES.CTA_BTN) {\n\t\t\tif (state.ctaBtn?.phoneNumber?.isChecked) {\n\t\t\t\tconst btnText = state.ctaBtn.phoneNumber.btnText?.trim();\n\t\t\t\tconst phoneNumber = state.ctaBtn.phoneNumber.phoneNumber;\n\n\t\t\t\tif (errors.ctaBtn && !btnText) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (\n\t\t\t\t\terrors.ctaBtn &&\n\t\t\t\t\tbtnText &&\n\t\t\t\t\tbtnText.length > QUICK_REPLY_BTN_TEXT_LIMIT\n\t\t\t\t) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && btnText && emojiRegex.test(btnText)) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\n\t\t\t\tif (errors.ctaBtn && !phoneNumber) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.link = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && phoneNumber && phoneNumber.length < 10) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.link = VALID_PHONE_NUMBER;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.ctaBtn?.websiteLinkBtn?.isChecked) {\n\t\t\t\tconst btnText = state.ctaBtn.websiteLinkBtn.btnText?.trim();\n\t\t\t\tconst customLink = state.ctaBtn.websiteLinkBtn.linkOpens?.trim();\n\t\t\t\tconst placeholder = state.ctaBtn.websiteLinkBtn.placeholder?.trim();\n\n\t\t\t\tif (errors.ctaBtn && !btnText) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (\n\t\t\t\t\terrors.ctaBtn &&\n\t\t\t\t\tbtnText &&\n\t\t\t\t\tbtnText.length > QUICK_REPLY_BTN_TEXT_LIMIT\n\t\t\t\t) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && btnText && emojiRegex.test(btnText)) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\n\t\t\t\tif (errors.ctaBtn && !customLink && !placeholder) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.link = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (state.actionsType === ACTIONS_TYPES.QUICK_REPLY) {\n\t\t\tconst quickReplyErrors = ['', '', ''];\n\t\t\tstate.quickReply.forEach((button, i) => {\n\t\t\t\tconst text = button.text?.trim();\n\t\t\t\tif (!text) {\n\t\t\t\t\tquickReplyErrors[i] = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (text.length > QUICK_REPLY_NAME_LEN_LIMIT) {\n\t\t\t\t\tquickReplyErrors[i] = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (emojiRegex.test(text)) {\n\t\t\t\t\tquickReplyErrors[i] = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else {\n\t\t\t\t\tconst buttons = [...state.quickReply];\n\t\t\t\t\tbuttons.splice(i, 1);\n\t\t\t\t\tconst exists = buttons.find(\n\t\t\t\t\t\t(el: QUICK_REPLY_BUTTON) => el.text === text,\n\t\t\t\t\t);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tquickReplyErrors[i] = QUICK_REPLY_NAME_ERROR;\n\t\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\terrors.quickReply = quickReplyErrors;\n\t\t}\n\n\t\tif (\n\t\t\tstate.actionsType === ACTIONS_TYPES.CTA_BTN ||\n\t\t\tstate.actionsType === ACTIONS_TYPES.QUICK_REPLY\n\t\t) {\n\t\t\tconst quickReplyErrors = errors.quickReply?.reduce(\n\t\t\t\t(qrbErrorAcc, currentError) => qrbErrorAcc || !!currentError,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tif (\n\t\t\t\t(!!errors?.ctaBtn?.websiteLink?.link ||\n\t\t\t\t\t!!errors.ctaBtn?.websiteLink?.btnText ||\n\t\t\t\t\t!!errors.ctaBtn?.phoneNumber?.link ||\n\t\t\t\t\t!!errors.ctaBtn?.phoneNumber?.btnText ||\n\t\t\t\t\t!!quickReplyErrors) &&\n\t\t\t\t!isScrolled\n\t\t\t) {\n\t\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.actionButtons);\n\t\t\t\tisScrolled = true;\n\t\t\t}\n\t\t}\n\n\t\treturn { status, errors };\n\t}\n\n\tprivate parseBodyComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tisV2 = false,\n\t\tshowSampleValues?: boolean,\n\t\tpod?: string,\n\t) {\n\t\tconst bodyVariable: templateVariable[] = [];\n\t\tlet bodyText = '';\n\n\t\tconst bodyComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'BODY',\n\t\t);\n\n\t\tif (bodyComponent) {\n\t\t\tbodyComponent.example?.body_text?.[0]?.forEach((sampleValue, i) => {\n\t\t\t\tlet bodyVarPlaceholder = dbFormattedTemplate.mapping?.body?.[i];\n\t\t\t\tconst originalVariable = bodyVarPlaceholder;\n\t\t\t\tconst editable = bodyVarPlaceholder && /\\(\\(/.test(bodyVarPlaceholder);\n\t\t\t\tconst matchedPlaceholderName = bodyVarPlaceholder?.match(\n\t\t\t\t\tplaceHolderNamePattern,\n\t\t\t\t);\n\n\t\t\t\tif (matchedPlaceholderName?.[2]) {\n\t\t\t\t\tbodyVarPlaceholder = matchedPlaceholderName?.[2];\n\t\t\t\t}\n\n\t\t\t\tconst isChatbotCustomText =\n\t\t\t\t\tpod === POD.CHATBOT &&\n\t\t\t\t\toriginalVariable &&\n\t\t\t\t\toriginalVariable?.startsWith('((') &&\n\t\t\t\t\toriginalVariable?.endsWith('))');\n\n\t\t\t\tbodyVariable.push({\n\t\t\t\t\tidx: i,\n\t\t\t\t\tvariableVal:\n\t\t\t\t\t\tshowSampleValues || isChatbotCustomText\n\t\t\t\t\t\t\t? sampleValue\n\t\t\t\t\t\t\t: originalVariable,\n\t\t\t\t\teditable: !!editable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: bodyVarPlaceholder ?? '',\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (dbFormattedTemplate.htmlContentUrl) {\n\t\t\t\tbodyText = dbFormattedTemplate.htmlContentUrl;\n\t\t\t} else {\n\t\t\t\tbodyText = bodyComponent.text?.split(/\\{\\{[0-9]+\\}\\}/).length\n\t\t\t\t\t? bodyComponent.text\n\t\t\t\t\t\t\t?.split(/\\{\\{[0-9]+\\}\\}/)\n\t\t\t\t\t\t\t.map((t, i) => {\n\t\t\t\t\t\t\t\tif (bodyVariable?.[i]) {\n\t\t\t\t\t\t\t\t\tconst normalizeName = bodyVariable[i].variableName;\n\t\t\t\t\t\t\t\t\tconst tmp = isV2\n\t\t\t\t\t\t\t\t\t\t? `${t}{{${normalizeName}}}`\n\t\t\t\t\t\t\t\t\t\t: `${t} <span> </span><span style=\"color: ${COLORS.content.brand}; text-decoration: underline;\">{{${normalizeName}}}</span><span> </span>`;\n\n\t\t\t\t\t\t\t\t\treturn tmp;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn t;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t: '';\n\t\t\t}\n\t\t}\n\n\t\treturn { bodyVariable, bodyText };\n\t}\n\n\tprivate parseTitleComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tisV2 = false,\n\t\tshowSampleValues?: boolean,\n\t) {\n\t\tconst titleVariable: templateVariable[] = [];\n\t\tlet titleText = '';\n\n\t\tconst bodyComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'TITLE',\n\t\t);\n\n\t\tif (bodyComponent) {\n\t\t\tbodyComponent.example?.title_text?.[0]?.forEach((sampleValue, i) => {\n\t\t\t\tlet bodyVarPlaceholder = dbFormattedTemplate.mapping?.body?.[i];\n\t\t\t\tconst originalVariable = bodyVarPlaceholder;\n\t\t\t\tconst editable = bodyVarPlaceholder && /\\(\\(/.test(bodyVarPlaceholder);\n\t\t\t\tconst matchedPlaceholderName = bodyVarPlaceholder?.match(\n\t\t\t\t\tplaceHolderNamePattern,\n\t\t\t\t);\n\n\t\t\t\tif (matchedPlaceholderName?.[2]) {\n\t\t\t\t\tbodyVarPlaceholder = matchedPlaceholderName?.[2];\n\t\t\t\t}\n\n\t\t\t\ttitleVariable.push({\n\t\t\t\t\tidx: i,\n\t\t\t\t\tvariableVal: showSampleValues ? sampleValue : originalVariable,\n\t\t\t\t\teditable: !!editable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: bodyVarPlaceholder ?? '',\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (dbFormattedTemplate.htmlContentUrl) {\n\t\t\t\ttitleText = dbFormattedTemplate.htmlContentUrl;\n\t\t\t} else {\n\t\t\t\ttitleText = bodyComponent.text?.split(/\\{\\{[0-9]+\\}\\}/).length\n\t\t\t\t\t? bodyComponent.text\n\t\t\t\t\t\t\t?.split(/\\{\\{[0-9]+\\}\\}/)\n\t\t\t\t\t\t\t.map((t, i) => {\n\t\t\t\t\t\t\t\tif (titleVariable?.[i]) {\n\t\t\t\t\t\t\t\t\tconst normalizeName = titleVariable[i].variableName;\n\t\t\t\t\t\t\t\t\tconst tmp = isV2\n\t\t\t\t\t\t\t\t\t\t? `${t}{{${normalizeName}}}`\n\t\t\t\t\t\t\t\t\t\t: `${t} <span> </span><span style=\"color: ${COLORS.content.brand}; text-decoration: underline;\">{{${normalizeName}}}</span><span> </span>`;\n\n\t\t\t\t\t\t\t\t\treturn tmp;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn t;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t: '';\n\t\t\t}\n\t\t}\n\n\t\treturn { titleText, titleVariables: titleVariable };\n\t}\n\n\tprivate parseFooterComponent(dbFormattedTemplate: WhatsAppTemplate) {\n\t\tconst footerComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'FOOTER',\n\t\t);\n\n\t\treturn footerComponent?.text;\n\t}\n\n\tprivate parseButtonComponent(dbFormattedTemplate: WhatsAppTemplate) {\n\t\tconst res: {\n\t\t\tactionsType: ACTIONS_TYPES;\n\t\t\tquickReply: Array<QUICK_REPLY_BUTTON>;\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber?: {\n\t\t\t\t\tisChecked?: boolean;\n\t\t\t\t\tbtnText?: string;\n\t\t\t\t\tphoneNumber?: string;\n\t\t\t\t};\n\t\t\t\twebsiteLinkBtn?: {\n\t\t\t\t\tisChecked?: boolean;\n\t\t\t\t\tbtnText?: string;\n\t\t\t\t\tlinkOpens?: string;\n\t\t\t\t\tplaceholder?: string;\n\t\t\t\t};\n\t\t\t};\n\t\t\tallButtons: WhatsappPreviewButtonType[];\n\t\t} = {\n\t\t\tactionsType: ACTIONS_TYPES.NONE,\n\t\t\tquickReply: [],\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber: undefined,\n\t\t\t\twebsiteLinkBtn: undefined,\n\t\t\t},\n\t\t\tallButtons: [],\n\t\t};\n\n\t\tconst buttonComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'BUTTONS',\n\t\t);\n\n\t\tif (buttonComponent && buttonComponent?.buttons?.length) {\n\t\t\tconst actionsType =\n\t\t\t\tbuttonComponent?.buttons?.[0].type === 'QUICK_REPLY'\n\t\t\t\t\t? ACTIONS_TYPES.QUICK_REPLY\n\t\t\t\t\t: ACTIONS_TYPES.CTA_BTN;\n\n\t\t\tres.actionsType = actionsType;\n\n\t\t\tif (actionsType === ACTIONS_TYPES.QUICK_REPLY) {\n\t\t\t\tconst btnTexts = (buttonComponent?.buttons?.map((btn) => btn) ??\n\t\t\t\t\t[]) as QUICK_REPLY_BUTTON[];\n\t\t\t\tres.quickReply = btnTexts;\n\t\t\t} else if (actionsType === ACTIONS_TYPES.CTA_BTN) {\n\t\t\t\tbuttonComponent?.buttons?.forEach((btn) => {\n\t\t\t\t\tif (btn.phone_number) {\n\t\t\t\t\t\tres.ctaBtn.phoneNumber = {\n\t\t\t\t\t\t\tisChecked: true,\n\t\t\t\t\t\t\tbtnText: btn.text,\n\t\t\t\t\t\t\tphoneNumber: btn.phone_number,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (btn.url) {\n\t\t\t\t\t\tconst btnPlaceholder =\n\t\t\t\t\t\t\tdbFormattedTemplate?.mapping?.buttons?.[0] ?? undefined;\n\t\t\t\t\t\tlet customUrl = false;\n\n\t\t\t\t\t\tif (btnPlaceholder && editableVarPattern.test(btnPlaceholder)) {\n\t\t\t\t\t\t\tcustomUrl = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tres.ctaBtn.websiteLinkBtn = {\n\t\t\t\t\t\t\tisChecked: true,\n\t\t\t\t\t\t\tbtnText: btn.text,\n\t\t\t\t\t\t\tlinkOpens: customUrl ? btn.example?.[0] : btn.url,\n\t\t\t\t\t\t\tplaceholder: customUrl ? undefined : btnPlaceholder,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Parses buttons from template to a format preview can understand.\n\t\t\t// Since copy code does not come with a variable by default, we are adding placeholder from example.\n\t\t\tres.allButtons = buttonComponent.buttons?.map((button) => {\n\t\t\t\tif (button.type === 'COPY_CODE') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...button,\n\t\t\t\t\t\tplaceholder: Array.isArray(button.example)\n\t\t\t\t\t\t\t? button.example[0]\n\t\t\t\t\t\t\t: button?.example || '',\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn button;\n\t\t\t}) as WhatsappPreviewButtonType[];\n\t\t}\n\n\t\treturn res;\n\t}\n\n\t/**\n\t * Parses LTO component to a format preview can understand.\n\t * Points to Note -\n\t * 1. Takes the Copy Code from previously parsed buttons.\n\t * 2. LTO component does not have a dateTime expiry by default. Hence, while sending template to ContextMapper, send with a date or current Date and Time is picked here.\n\t */\n\tprivate parseLimitedTimeOfferComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tallButtons: WhatsappPreviewButtonType[],\n\t) {\n\t\tconst limitedTimeOfferComponent: CreateTemplateType['limitedTimeOfferComponent'] =\n\t\t\t{\n\t\t\t\ttext: '',\n\t\t\t\tdateTime: '',\n\t\t\t\tcode: '',\n\t\t\t};\n\n\t\tdbFormattedTemplate.components.forEach((component) => {\n\t\t\tif (component.type === 'limited_time_offer') {\n\t\t\t\tlimitedTimeOfferComponent.text =\n\t\t\t\t\tcomponent.limited_time_offer?.text ?? '';\n\t\t\t\tconst dateTime = component.example?.limited_time_offer;\n\t\t\t\tif (dateTime && dateTime.startsWith('{{') && dateTime.endsWith('}}')) {\n\t\t\t\t\tlimitedTimeOfferComponent.dateTime = dateTime;\n\t\t\t\t} else {\n\t\t\t\t\tlimitedTimeOfferComponent.dateTime = format(\n\t\t\t\t\t\tdateTime ? new Date(dateTime) : new Date(),\n\t\t\t\t\t\t'MMM dd',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tallButtons.forEach((button) => {\n\t\t\t\tif (button.type === 'COPY_CODE') {\n\t\t\t\t\tlimitedTimeOfferComponent.code = button.placeholder ?? '';\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\treturn limitedTimeOfferComponent;\n\t}\n\n\tprivate parseCallPermissionComponent(dbFormattedTemplate: WhatsAppTemplate): {\n\t\tshowCallPermissionCard: boolean;\n\t\tcallPermissionText?: string;\n\t} {\n\t\tconst callPermissionComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => (component as any).type === 'CALL_PERMISSION_REQUEST',\n\t\t);\n\n\t\treturn {\n\t\t\tshowCallPermissionCard: Boolean(callPermissionComponent),\n\t\t\tcallPermissionText: (callPermissionComponent as any)?.text,\n\t\t};\n\t}\n\n\tasync parseUITemplateFromDBFormat(data: {\n\t\tdbFormattedTemplate: WhatsAppTemplate;\n\t\tisDuplicate?: boolean;\n\t\tshowSampleValues?: boolean;\n\t\tisV2?: boolean;\n\t\tpod?: string;\n\t}) {\n\t\tconst {\n\t\t\tdbFormattedTemplate,\n\t\t\tisDuplicate,\n\t\t\tisV2 = false,\n\t\t\tshowSampleValues,\n\t\t\tpod,\n\t\t} = data;\n\t\tconst {\n\t\t\theaderType,\n\t\t\theaderAssetLink,\n\t\t\theaderAssetName,\n\t\t\theaderText,\n\t\t\theaderVariables,\n\t\t} = await this.parseDataFromHeaderComponent(\n\t\t\tdbFormattedTemplate,\n\t\t\tundefined,\n\t\t\tpod,\n\t\t);\n\n\t\tconst { bodyText, bodyVariable: bodyVariables } =\n\t\t\tawait this.parseBodyComponent(\n\t\t\t\tdbFormattedTemplate,\n\t\t\t\tisV2,\n\t\t\t\tshowSampleValues,\n\t\t\t\tpod,\n\t\t\t);\n\t\tconst { titleText, titleVariables: titleVariables } =\n\t\t\tawait this.parseTitleComponent(\n\t\t\t\tdbFormattedTemplate,\n\t\t\t\tisV2,\n\t\t\t\tshowSampleValues,\n\t\t\t);\n\n\t\tconst { actionsType, quickReply, ctaBtn, allButtons } =\n\t\t\tawait this.parseButtonComponent(dbFormattedTemplate);\n\n\t\tconst limitedTimeOfferComponent = this.parseLimitedTimeOfferComponent(\n\t\t\tdbFormattedTemplate,\n\t\t\tallButtons,\n\t\t);\n\n\t\tconst { showCallPermissionCard, callPermissionText } =\n\t\t\tthis.parseCallPermissionComponent(dbFormattedTemplate);\n\n\t\tconst state: CreateTemplateType = {\n\t\t\tquickReply,\n\t\t\tctaBtn,\n\t\t\tallButtons,\n\t\t\tmeta: {\n\t\t\t\tname: isDuplicate\n\t\t\t\t\t? `${dbFormattedTemplate.label} Copy`\n\t\t\t\t\t: dbFormattedTemplate.label,\n\t\t\t\tcategory: dbFormattedTemplate.category?.toUpperCase(),\n\t\t\t\tsubCategory: dbFormattedTemplate.templateCategory,\n\t\t\t\tlanguage: dbFormattedTemplate.language,\n\t\t\t\ttemplateId: dbFormattedTemplate.templateId,\n\t\t\t},\n\t\t\terror: {\n\t\t\t\theader: undefined,\n\t\t\t\tbody: undefined,\n\t\t\t\tfooter: undefined,\n\t\t\t\tquickReply: undefined,\n\t\t\t\tmeta: undefined,\n\t\t\t\tctaBtn: undefined,\n\t\t\t},\n\n\t\t\tactionsType,\n\t\t\tfooterText: this.parseFooterComponent(dbFormattedTemplate),\n\t\t\t/** BODY TEXT */\n\t\t\tbodyVariables,\n\t\t\tbodyText,\n\n\t\t\t/** HEADER */\n\t\t\theaderType,\n\t\t\theaderAssetLink,\n\t\t\theaderAssetName,\n\t\t\theaderText,\n\t\t\theaderVariables,\n\t\t\talreadyAsADraft: dbFormattedTemplate.isDraft,\n\t\t\tmode: 'edit',\n\t\t\tinitialLoading: false,\n\t\t\t/* LIMITED TIME OFFER */\n\t\t\tlimitedTimeOfferComponent,\n\t\t\t/* Title for RCS */\n\t\t\ttitleText,\n\t\t\ttitleVariables,\n\t\t\t/* Call Permission */\n\t\t\tshowCallPermissionCard,\n\t\t\tcallPermissionText,\n\t\t};\n\n\t\tconst { errors } = this.validateState(state);\n\n\t\tstate.error = errors;\n\n\t\treturn state;\n\t}\n\n\tparseTemplateConfiguration(template: RCSTemplateType): RCSTemplateConfig {\n\t\tlet config: RCSTemplateConfig;\n\t\tconst templateConfig = template?.content || ({} as RCSTemplateConfig);\n\t\tif (typeof templateConfig === 'string') {\n\t\t\ttry {\n\t\t\t\tconfig = JSON.parse(templateConfig) as RCSTemplateConfig;\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error parsing rcsTemplate component JSON:', error);\n\t\t\t\tconfig = { orientation: 'VERTICAL' } as RCSTemplateConfig;\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = templateConfig;\n\t\t}\n\t\treturn {\n\t\t\t...config,\n\t\t\ttemplateType: template?.templateType as RCS_TEMPLATE_TYPE,\n\t\t\tisMediaAfterBody: this.isRcsMediaAfterBody(template),\n\t\t};\n\t}\n\n\t/**\n\t * Determines, from the original `components[]` order, whether a non-TEXT\n\t * media header appears AFTER the body component. The library preview\n\t * otherwise always renders the media first; honouring this keeps\n\t * body-then-media templates (the third-party ordering for some\n\t * `text_message_with_media` templates) correct in the preview.\n\t */\n\tisRcsMediaAfterBody(template: RCSTemplateType): boolean {\n\t\tconst components = template?.components;\n\t\tif (!Array.isArray(components)) return false;\n\n\t\tconst mediaHeaderIndex = components.findIndex(\n\t\t\t(component) =>\n\t\t\t\tcomponent.type === 'HEADER' &&\n\t\t\t\t!!component.format &&\n\t\t\t\tcomponent.format !== HEADER_TYPES.TEXT,\n\t\t);\n\t\tconst bodyIndex = components.findIndex(\n\t\t\t(component) => component.type === 'BODY',\n\t\t);\n\n\t\treturn (\n\t\t\tmediaHeaderIndex > -1 && bodyIndex > -1 && mediaHeaderIndex > bodyIndex\n\t\t);\n\t}\n}\n"],"names":["TemplateCreatorHelper","dbFormattedTemplate","showSampleValues","pod","res","HEADER_TYPES","headerComponent","component","sampleValue","headerVarPlaceholder","originalVariable","normalizedName","editable","isChatbotCustomText","POD","reduxHeaderVar","state","emojiRegex","status","errors","templateHelperUtils","TemplateHelperUtils","isScrolled","scrollByElementId","elementId","NAME_LEN_LIMIT","NAME_LEN_ERROR","specialCharPattern","NO_SPECIAL_CHAR","REQUIRED_FIELD","CREATE_TEMPLATE_DOM_IDS","text","HEADER_TEXT_LEN_LIMIT","HEADER_LEN_ERROR","variableList","ONE_VAR_ALLOWED","HEADER_ASSET_LINK_ERROR","BODY_TEXT_LEN_LIMIT","BODY_LEN_ERROR","ACTIONS_TYPES","btnText","phoneNumber","QUICK_REPLY_BTN_TEXT_LIMIT","QUICK_REPLY_LEN_ERROR","BUTTON_EMOJI_ERROR","VALID_PHONE_NUMBER","customLink","placeholder","quickReplyErrors","button","i","QUICK_REPLY_NAME_LEN_LIMIT","buttons","el","QUICK_REPLY_NAME_ERROR","qrbErrorAcc","currentError","isV2","bodyVariable","bodyText","bodyComponent","bodyVarPlaceholder","matchedPlaceholderName","placeHolderNamePattern","t","normalizeName","COLORS","titleVariable","titleText","buttonComponent","actionsType","btnTexts","btn","btnPlaceholder","customUrl","editableVarPattern","allButtons","limitedTimeOfferComponent","dateTime","format","callPermissionComponent","data","isDuplicate","headerType","headerAssetLink","headerAssetName","headerText","headerVariables","bodyVariables","titleVariables","quickReply","ctaBtn","showCallPermissionCard","callPermissionText","template","config","templateConfig","error","components","mediaHeaderIndex","bodyIndex"],"mappings":"8WA6CO,MAAMA,CAAsB,CAC1B,6BACPC,EACAC,EACAC,EACC,CACD,MAAMC,EAMF,CACH,WAAYC,EAAAA,aAAa,KACzB,gBAAiB,CAAA,CAAC,EAGbC,EAAkBL,GAAqB,YAAY,KACvDM,GAAcA,EAAU,OAAS,QAAA,EAGnC,GAAID,EAAiB,CACpBF,EAAI,WAAaE,EAAgB,OACjCF,EAAI,WAAaE,EAAgB,KAEjCF,EAAI,gBAAkBE,EAAgB,SAAS,gBAAgB,CAAC,EAEhE,MAAME,EAAcF,EAAgB,SAAS,cAAc,CAAC,EACtDG,EAAuBR,EAAoB,SAAS,SAAS,CAAC,EAC9DS,EAAmBD,EACzB,GAAIA,EAAsB,CACzB,MAAME,EAAiBF,GACpB,QAAQ,KAAM,EAAE,EACjB,QAAQ,KAAM,EAAE,EAChB,QAAQ,KAAM,EAAE,EAChB,QAAQ,KAAM,EAAE,EAChB,QAAQ,KAAM,EAAE,EAChB,QAAQ,KAAM,EAAE,EACZG,EAAW,OAAO,KAAKH,CAAoB,EAC3CI,EACL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uBAAAG,EACA,mBAAAC,CAAA,EAGK,CAAE,OAAA1E,CAAA,EAAW,KAAK,cAAcH,CAAK,EAE3C,OAAAA,EAAM,MAAQG,EAEPH,CACR,CAEA,2BAA2B8E,EAA8C,CACxE,IAAIC,EACJ,MAAMC,EAAiBF,GAAU,SAAY,CAAA,EAC7C,GAAI,OAAOE,GAAmB,SAC7B,GAAI,CACHD,EAAS,KAAK,MAAMC,CAAc,CACnC,OAASC,EAAO,CACf,QAAQ,MAAM,4CAA6CA,CAAK,EAChEF,EAAS,CAAE,YAAa,UAAA,CACzB,MAEAA,EAASC,EAEV,MAAO,CACN,GAAGD,EACH,aAAcD,GAAU,aACxB,iBAAkB,KAAK,oBAAoBA,CAAQ,CAAA,CAErD,CASA,oBAAoBA,EAAoC,CACvD,MAAMI,EAAaJ,GAAU,WAC7B,GAAI,CAAC,MAAM,QAAQI,CAAU,EAAG,MAAO,GAEvC,MAAMC,EAAmBD,EAAW,UAClC3F,GACAA,EAAU,OAAS,UACnB,CAAC,CAACA,EAAU,QACZA,EAAU,SAAWF,eAAa,IAAA,EAE9B+F,EAAYF,EAAW,UAC3B3F,GAAcA,EAAU,OAAS,MAAA,EAGnC,OACC4F,EAAmB,IAAMC,EAAY,IAAMD,EAAmBC,CAEhE,CACD"}
|
|
1
|
+
{"version":3,"file":"TemplateCreatorHelper.js","sources":["../../../../../src/components/template-preview/helpers/TemplateCreatorHelper.ts"],"sourcesContent":["import { format } from 'date-fns';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\teditableVarPattern,\n\tplaceHolderNamePattern,\n\tspecialCharPattern,\n} from '../constants/regexPatterns';\nimport {\n\tBODY_LEN_ERROR,\n\tBODY_TEXT_LEN_LIMIT,\n\tBUTTON_EMOJI_ERROR,\n\tCREATE_TEMPLATE_DOM_IDS,\n\tHEADER_ASSET_LINK_ERROR,\n\tHEADER_LEN_ERROR,\n\tHEADER_TEXT_LEN_LIMIT,\n\tNAME_LEN_ERROR,\n\tNAME_LEN_LIMIT,\n\tNO_SPECIAL_CHAR,\n\tONE_VAR_ALLOWED,\n\tQUICK_REPLY_BTN_TEXT_LIMIT,\n\tQUICK_REPLY_LEN_ERROR,\n\tQUICK_REPLY_NAME_ERROR,\n\tQUICK_REPLY_NAME_LEN_LIMIT,\n\tREQUIRED_FIELD,\n\tVALID_PHONE_NUMBER,\n} from '../constants/TemplateConstants';\nimport {\n\tRCS_TEMPLATE_TYPE,\n\tRCSTemplateConfig,\n\tRCSTemplateType,\n} from '../models/RCSTemplate';\nimport {\n\tACTIONS_TYPES,\n\tHEADER_TYPES,\n\tQUICK_REPLY_BUTTON,\n} from '../models/TemplateMeta';\nimport {\n\tCreateTemplateType,\n\tPOD,\n\ttemplateVariable,\n\tWhatsappPreviewButtonType,\n\tWhatsAppTemplate,\n} from '../models/WhatsAppTemplate';\nimport { TemplateHelperUtils } from '../utils/TemplateHelperUtils';\n\nexport class TemplateCreatorHelper {\n\tprivate parseDataFromHeaderComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tshowSampleValues?: boolean,\n\t\tpod?: string,\n\t) {\n\t\tconst res: {\n\t\t\theaderType: HEADER_TYPES;\n\t\t\theaderAssetLink?: string;\n\t\t\theaderAssetName?: string;\n\t\t\theaderText?: string;\n\t\t\theaderVariables: templateVariable[];\n\t\t} = {\n\t\t\theaderType: HEADER_TYPES.NONE,\n\t\t\theaderVariables: [],\n\t\t};\n\n\t\tconst headerComponent = dbFormattedTemplate?.components?.find(\n\t\t\t(component) => component.type === 'HEADER',\n\t\t);\n\n\t\tif (headerComponent) {\n\t\t\tres.headerType = headerComponent.format as HEADER_TYPES;\n\t\t\tres.headerText = headerComponent.text;\n\n\t\t\tres.headerAssetLink = headerComponent.example?.header_handle?.[0];\n\n\t\t\tconst sampleValue = headerComponent.example?.header_text?.[0];\n\t\t\tconst headerVarPlaceholder = dbFormattedTemplate.mapping?.header?.[0];\n\t\t\tconst originalVariable = headerVarPlaceholder;\n\t\t\tif (headerVarPlaceholder) {\n\t\t\t\tconst normalizedName = headerVarPlaceholder\n\t\t\t\t\t?.replace('[[', '')\n\t\t\t\t\t.replace(']]', '')\n\t\t\t\t\t.replace('{{', '')\n\t\t\t\t\t.replace('}}', '')\n\t\t\t\t\t.replace('((', '')\n\t\t\t\t\t.replace('))', '');\n\t\t\t\tconst editable = /\\(\\(/.test(headerVarPlaceholder);\n\t\t\t\tconst isChatbotCustomText =\n\t\t\t\t\tpod === POD.CHATBOT &&\n\t\t\t\t\toriginalVariable &&\n\t\t\t\t\toriginalVariable?.startsWith('((') &&\n\t\t\t\t\toriginalVariable?.endsWith('))');\n\n\t\t\t\tconst reduxHeaderVar: templateVariable = {\n\t\t\t\t\tidx: 0,\n\t\t\t\t\tvariableVal:\n\t\t\t\t\t\tshowSampleValues || isChatbotCustomText\n\t\t\t\t\t\t\t? sampleValue\n\t\t\t\t\t\t\t: originalVariable,\n\t\t\t\t\teditable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: normalizedName,\n\t\t\t\t};\n\t\t\t\tres.headerVariables = [reduxHeaderVar];\n\t\t\t\tif (headerComponent.example?.header_text?.length) {\n\t\t\t\t\tres.headerText = res.headerText?.replace(\n\t\t\t\t\t\t/** since there will be only one variable in template so hard replace */\n\t\t\t\t\t\t'{{1}}',\n\t\t\t\t\t\t`{{${normalizedName}}}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\t/**\n\t * Check if current template state is ready for saving as a draft/submit-template or not\n\t * @param state\n\t */\n\tvalidateState(state: CreateTemplateType): {\n\t\tstatus: 'invalid' | 'valid';\n\t\terrors: CreateTemplateType['error'];\n\t} {\n\t\tconst emojiRegex = /\\p{Extended_Pictographic}/u;\n\t\tlet status: 'invalid' | 'valid' = 'valid';\n\t\tconst errors: CreateTemplateType['error'] = {\n\t\t\tmeta: {},\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber: { btnText: '', link: '' },\n\t\t\t\twebsiteLink: { btnText: '', link: '' },\n\t\t\t},\n\t\t\tquickReply: [null, null, null],\n\t\t};\n\t\tconst templateHelperUtils = new TemplateHelperUtils();\n\t\tlet isScrolled = false;\n\n\t\tconst scrollByElementId = (elementId: string) => {\n\t\t\tdocument.getElementById(elementId)?.scrollIntoView({\n\t\t\t\tbehavior: 'smooth',\n\t\t\t\tblock: 'nearest',\n\t\t\t});\n\t\t};\n\n\t\tif (!state.meta?.name) {\n\t\t\terrors.meta!.name = REQUIRED_FIELD;\n\t\t\tstatus = 'invalid';\n\t\t} else if (state.meta.name?.trim().length > NAME_LEN_LIMIT) {\n\t\t\terrors.meta!.name = NAME_LEN_ERROR;\n\t\t\tstatus = 'invalid';\n\t\t} else if (specialCharPattern.test(state.meta.name?.trim())) {\n\t\t\terrors.meta!.name = NO_SPECIAL_CHAR;\n\t\t\tstatus = 'invalid';\n\t\t}\n\n\t\tif (!!errors.meta!.name && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.name);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.headerType === HEADER_TYPES.TEXT) {\n\t\t\tconst text = state.headerText?.trim() ?? '';\n\t\t\tif (!text) {\n\t\t\t\terrors.header = REQUIRED_FIELD;\n\t\t\t\tstatus = 'invalid';\n\t\t\t} else if (text.length > HEADER_TEXT_LEN_LIMIT) {\n\t\t\t\terrors.header = HEADER_LEN_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t} else {\n\t\t\t\tconst variableList =\n\t\t\t\t\ttemplateHelperUtils.getTemplateVariablesFromState(text);\n\t\t\t\tif (variableList && variableList.length > 1) {\n\t\t\t\t\terrors.header = ONE_VAR_ALLOWED;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (state.headerType === HEADER_TYPES.DOCUMENT) {\n\t\t\t/** @todo add media header validations */\n\t\t} else if (state.headerType === HEADER_TYPES.IMAGE) {\n\t\t\t/** @todo add media header validations */\n\t\t} else if (state.headerType === HEADER_TYPES.VIDEO) {\n\t\t\t/** @todo add media header validations */\n\t\t}\n\n\t\tif (\n\t\t\tstate.headerType === HEADER_TYPES.DOCUMENT ||\n\t\t\tstate.headerType === HEADER_TYPES.IMAGE ||\n\t\t\tstate.headerType === HEADER_TYPES.VIDEO\n\t\t) {\n\t\t\tif (!state.headerAssetLink) {\n\t\t\t\terrors.header = HEADER_ASSET_LINK_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t}\n\t\t}\n\n\t\tif (!!errors.header && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.header);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (!state.bodyText) {\n\t\t\terrors.body = REQUIRED_FIELD;\n\t\t\tstatus = 'invalid';\n\t\t} else {\n\t\t\tif (\n\t\t\t\tstate.bodyTextRaw &&\n\t\t\t\tstate.bodyTextRaw?.trim().length > BODY_TEXT_LEN_LIMIT\n\t\t\t) {\n\t\t\t\terrors.body = BODY_LEN_ERROR;\n\t\t\t\tstatus = 'invalid';\n\t\t\t}\n\t\t}\n\n\t\tif (!!errors.body && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.body);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.footerText && state.footerText.length > HEADER_TEXT_LEN_LIMIT) {\n\t\t\terrors.footer = HEADER_LEN_ERROR;\n\t\t\tstatus = 'invalid';\n\t\t}\n\n\t\tif (!!errors?.footer && !isScrolled) {\n\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.footer);\n\t\t\tisScrolled = true;\n\t\t}\n\n\t\tif (state.actionsType === ACTIONS_TYPES.CTA_BTN) {\n\t\t\tif (state.ctaBtn?.phoneNumber?.isChecked) {\n\t\t\t\tconst btnText = state.ctaBtn.phoneNumber.btnText?.trim();\n\t\t\t\tconst phoneNumber = state.ctaBtn.phoneNumber.phoneNumber;\n\n\t\t\t\tif (errors.ctaBtn && !btnText) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (\n\t\t\t\t\terrors.ctaBtn &&\n\t\t\t\t\tbtnText &&\n\t\t\t\t\tbtnText.length > QUICK_REPLY_BTN_TEXT_LIMIT\n\t\t\t\t) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && btnText && emojiRegex.test(btnText)) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.btnText = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\n\t\t\t\tif (errors.ctaBtn && !phoneNumber) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.link = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && phoneNumber && phoneNumber.length < 10) {\n\t\t\t\t\terrors.ctaBtn.phoneNumber.link = VALID_PHONE_NUMBER;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.ctaBtn?.websiteLinkBtn?.isChecked) {\n\t\t\t\tconst btnText = state.ctaBtn.websiteLinkBtn.btnText?.trim();\n\t\t\t\tconst customLink = state.ctaBtn.websiteLinkBtn.linkOpens?.trim();\n\t\t\t\tconst placeholder = state.ctaBtn.websiteLinkBtn.placeholder?.trim();\n\n\t\t\t\tif (errors.ctaBtn && !btnText) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (\n\t\t\t\t\terrors.ctaBtn &&\n\t\t\t\t\tbtnText &&\n\t\t\t\t\tbtnText.length > QUICK_REPLY_BTN_TEXT_LIMIT\n\t\t\t\t) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (errors.ctaBtn && btnText && emojiRegex.test(btnText)) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.btnText = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\n\t\t\t\tif (errors.ctaBtn && !customLink && !placeholder) {\n\t\t\t\t\terrors.ctaBtn.websiteLink.link = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (state.actionsType === ACTIONS_TYPES.QUICK_REPLY) {\n\t\t\tconst quickReplyErrors = ['', '', ''];\n\t\t\tstate.quickReply.forEach((button, i) => {\n\t\t\t\tconst text = button.text?.trim();\n\t\t\t\tif (!text) {\n\t\t\t\t\tquickReplyErrors[i] = REQUIRED_FIELD;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (text.length > QUICK_REPLY_NAME_LEN_LIMIT) {\n\t\t\t\t\tquickReplyErrors[i] = QUICK_REPLY_LEN_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else if (emojiRegex.test(text)) {\n\t\t\t\t\tquickReplyErrors[i] = BUTTON_EMOJI_ERROR;\n\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t} else {\n\t\t\t\t\tconst buttons = [...state.quickReply];\n\t\t\t\t\tbuttons.splice(i, 1);\n\t\t\t\t\tconst exists = buttons.find(\n\t\t\t\t\t\t(el: QUICK_REPLY_BUTTON) => el.text === text,\n\t\t\t\t\t);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tquickReplyErrors[i] = QUICK_REPLY_NAME_ERROR;\n\t\t\t\t\t\tstatus = 'invalid';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\terrors.quickReply = quickReplyErrors;\n\t\t}\n\n\t\tif (\n\t\t\tstate.actionsType === ACTIONS_TYPES.CTA_BTN ||\n\t\t\tstate.actionsType === ACTIONS_TYPES.QUICK_REPLY\n\t\t) {\n\t\t\tconst quickReplyErrors = errors.quickReply?.reduce(\n\t\t\t\t(qrbErrorAcc, currentError) => qrbErrorAcc || !!currentError,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tif (\n\t\t\t\t(!!errors?.ctaBtn?.websiteLink?.link ||\n\t\t\t\t\t!!errors.ctaBtn?.websiteLink?.btnText ||\n\t\t\t\t\t!!errors.ctaBtn?.phoneNumber?.link ||\n\t\t\t\t\t!!errors.ctaBtn?.phoneNumber?.btnText ||\n\t\t\t\t\t!!quickReplyErrors) &&\n\t\t\t\t!isScrolled\n\t\t\t) {\n\t\t\t\tscrollByElementId(CREATE_TEMPLATE_DOM_IDS.actionButtons);\n\t\t\t\tisScrolled = true;\n\t\t\t}\n\t\t}\n\n\t\treturn { status, errors };\n\t}\n\n\tprivate parseBodyComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tisV2 = false,\n\t\tshowSampleValues?: boolean,\n\t\tpod?: string,\n\t) {\n\t\tconst bodyVariable: templateVariable[] = [];\n\t\tlet bodyText = '';\n\n\t\tconst bodyComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'BODY',\n\t\t);\n\n\t\tif (bodyComponent) {\n\t\t\tbodyComponent.example?.body_text?.[0]?.forEach((sampleValue, i) => {\n\t\t\t\tlet bodyVarPlaceholder = dbFormattedTemplate.mapping?.body?.[i];\n\t\t\t\tconst originalVariable = bodyVarPlaceholder;\n\t\t\t\tconst editable = bodyVarPlaceholder && /\\(\\(/.test(bodyVarPlaceholder);\n\t\t\t\tconst matchedPlaceholderName = bodyVarPlaceholder?.match(\n\t\t\t\t\tplaceHolderNamePattern,\n\t\t\t\t);\n\n\t\t\t\tif (matchedPlaceholderName?.[2]) {\n\t\t\t\t\tbodyVarPlaceholder = matchedPlaceholderName?.[2];\n\t\t\t\t}\n\n\t\t\t\tconst isChatbotCustomText =\n\t\t\t\t\tpod === POD.CHATBOT &&\n\t\t\t\t\toriginalVariable &&\n\t\t\t\t\toriginalVariable?.startsWith('((') &&\n\t\t\t\t\toriginalVariable?.endsWith('))');\n\n\t\t\t\tbodyVariable.push({\n\t\t\t\t\tidx: i,\n\t\t\t\t\tvariableVal:\n\t\t\t\t\t\tshowSampleValues || isChatbotCustomText\n\t\t\t\t\t\t\t? sampleValue\n\t\t\t\t\t\t\t: originalVariable,\n\t\t\t\t\teditable: !!editable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: bodyVarPlaceholder ?? '',\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (dbFormattedTemplate.htmlContentUrl) {\n\t\t\t\tbodyText = dbFormattedTemplate.htmlContentUrl;\n\t\t\t} else {\n\t\t\t\tbodyText = bodyComponent.text?.split(/\\{\\{[0-9]+\\}\\}/).length\n\t\t\t\t\t? bodyComponent.text\n\t\t\t\t\t\t\t?.split(/\\{\\{[0-9]+\\}\\}/)\n\t\t\t\t\t\t\t.map((t, i) => {\n\t\t\t\t\t\t\t\tif (bodyVariable?.[i]) {\n\t\t\t\t\t\t\t\t\tconst normalizeName = bodyVariable[i].variableName;\n\t\t\t\t\t\t\t\t\tconst tmp = isV2\n\t\t\t\t\t\t\t\t\t\t? `${t}{{${normalizeName}}}`\n\t\t\t\t\t\t\t\t\t\t: `${t} <span> </span><span style=\"color: ${COLORS.content.brand}; text-decoration: underline;\">{{${normalizeName}}}</span><span> </span>`;\n\n\t\t\t\t\t\t\t\t\treturn tmp;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn t;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t: '';\n\t\t\t}\n\t\t}\n\n\t\treturn { bodyVariable, bodyText };\n\t}\n\n\tprivate parseTitleComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tisV2 = false,\n\t\tshowSampleValues?: boolean,\n\t) {\n\t\tconst titleVariable: templateVariable[] = [];\n\t\tlet titleText = '';\n\n\t\tconst bodyComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'TITLE',\n\t\t);\n\n\t\tif (bodyComponent) {\n\t\t\tbodyComponent.example?.title_text?.[0]?.forEach((sampleValue, i) => {\n\t\t\t\tlet bodyVarPlaceholder = dbFormattedTemplate.mapping?.body?.[i];\n\t\t\t\tconst originalVariable = bodyVarPlaceholder;\n\t\t\t\tconst editable = bodyVarPlaceholder && /\\(\\(/.test(bodyVarPlaceholder);\n\t\t\t\tconst matchedPlaceholderName = bodyVarPlaceholder?.match(\n\t\t\t\t\tplaceHolderNamePattern,\n\t\t\t\t);\n\n\t\t\t\tif (matchedPlaceholderName?.[2]) {\n\t\t\t\t\tbodyVarPlaceholder = matchedPlaceholderName?.[2];\n\t\t\t\t}\n\n\t\t\t\ttitleVariable.push({\n\t\t\t\t\tidx: i,\n\t\t\t\t\tvariableVal: showSampleValues ? sampleValue : originalVariable,\n\t\t\t\t\teditable: !!editable,\n\t\t\t\t\teditableDefaultValues: editable ? undefined : sampleValue,\n\t\t\t\t\tvariableName: bodyVarPlaceholder ?? '',\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tif (dbFormattedTemplate.htmlContentUrl) {\n\t\t\t\ttitleText = dbFormattedTemplate.htmlContentUrl;\n\t\t\t} else {\n\t\t\t\ttitleText = bodyComponent.text?.split(/\\{\\{[0-9]+\\}\\}/).length\n\t\t\t\t\t? bodyComponent.text\n\t\t\t\t\t\t\t?.split(/\\{\\{[0-9]+\\}\\}/)\n\t\t\t\t\t\t\t.map((t, i) => {\n\t\t\t\t\t\t\t\tif (titleVariable?.[i]) {\n\t\t\t\t\t\t\t\t\tconst normalizeName = titleVariable[i].variableName;\n\t\t\t\t\t\t\t\t\tconst tmp = isV2\n\t\t\t\t\t\t\t\t\t\t? `${t}{{${normalizeName}}}`\n\t\t\t\t\t\t\t\t\t\t: `${t} <span> </span><span style=\"color: ${COLORS.content.brand}; text-decoration: underline;\">{{${normalizeName}}}</span><span> </span>`;\n\n\t\t\t\t\t\t\t\t\treturn tmp;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn t;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t: '';\n\t\t\t}\n\t\t}\n\n\t\treturn { titleText, titleVariables: titleVariable };\n\t}\n\n\tprivate parseFooterComponent(dbFormattedTemplate: WhatsAppTemplate) {\n\t\tconst footerComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'FOOTER',\n\t\t);\n\n\t\treturn footerComponent?.text;\n\t}\n\n\tprivate parseButtonComponent(dbFormattedTemplate: WhatsAppTemplate) {\n\t\tconst res: {\n\t\t\tactionsType: ACTIONS_TYPES;\n\t\t\tquickReply: Array<QUICK_REPLY_BUTTON>;\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber?: {\n\t\t\t\t\tisChecked?: boolean;\n\t\t\t\t\tbtnText?: string;\n\t\t\t\t\tphoneNumber?: string;\n\t\t\t\t};\n\t\t\t\twebsiteLinkBtn?: {\n\t\t\t\t\tisChecked?: boolean;\n\t\t\t\t\tbtnText?: string;\n\t\t\t\t\tlinkOpens?: string;\n\t\t\t\t\tplaceholder?: string;\n\t\t\t\t};\n\t\t\t};\n\t\t\tallButtons: WhatsappPreviewButtonType[];\n\t\t} = {\n\t\t\tactionsType: ACTIONS_TYPES.NONE,\n\t\t\tquickReply: [],\n\t\t\tctaBtn: {\n\t\t\t\tphoneNumber: undefined,\n\t\t\t\twebsiteLinkBtn: undefined,\n\t\t\t},\n\t\t\tallButtons: [],\n\t\t};\n\n\t\tconst buttonComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => component.type === 'BUTTONS',\n\t\t);\n\n\t\tif (buttonComponent && buttonComponent?.buttons?.length) {\n\t\t\tconst actionsType =\n\t\t\t\tbuttonComponent?.buttons?.[0].type === 'QUICK_REPLY'\n\t\t\t\t\t? ACTIONS_TYPES.QUICK_REPLY\n\t\t\t\t\t: ACTIONS_TYPES.CTA_BTN;\n\n\t\t\tres.actionsType = actionsType;\n\n\t\t\tif (actionsType === ACTIONS_TYPES.QUICK_REPLY) {\n\t\t\t\tconst btnTexts = (buttonComponent?.buttons?.map((btn) => btn) ??\n\t\t\t\t\t[]) as QUICK_REPLY_BUTTON[];\n\t\t\t\tres.quickReply = btnTexts;\n\t\t\t} else if (actionsType === ACTIONS_TYPES.CTA_BTN) {\n\t\t\t\tbuttonComponent?.buttons?.forEach((btn) => {\n\t\t\t\t\tif (btn.phone_number) {\n\t\t\t\t\t\tres.ctaBtn.phoneNumber = {\n\t\t\t\t\t\t\tisChecked: true,\n\t\t\t\t\t\t\tbtnText: btn.text,\n\t\t\t\t\t\t\tphoneNumber: btn.phone_number,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (btn.url) {\n\t\t\t\t\t\tconst btnPlaceholder =\n\t\t\t\t\t\t\tdbFormattedTemplate?.mapping?.buttons?.[0] ?? undefined;\n\t\t\t\t\t\tlet customUrl = false;\n\n\t\t\t\t\t\tif (btnPlaceholder && editableVarPattern.test(btnPlaceholder)) {\n\t\t\t\t\t\t\tcustomUrl = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tres.ctaBtn.websiteLinkBtn = {\n\t\t\t\t\t\t\tisChecked: true,\n\t\t\t\t\t\t\tbtnText: btn.text,\n\t\t\t\t\t\t\tlinkOpens: customUrl ? btn.example?.[0] : btn.url,\n\t\t\t\t\t\t\tplaceholder: customUrl ? undefined : btnPlaceholder,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Parses buttons from template to a format preview can understand.\n\t\t\t// Since copy code does not come with a variable by default, we are adding placeholder from example.\n\t\t\tres.allButtons = buttonComponent.buttons?.map((button) => {\n\t\t\t\tif (button.type === 'COPY_CODE') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...button,\n\t\t\t\t\t\tplaceholder: Array.isArray(button.example)\n\t\t\t\t\t\t\t? button.example[0]\n\t\t\t\t\t\t\t: button?.example || '',\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn button;\n\t\t\t}) as WhatsappPreviewButtonType[];\n\t\t}\n\n\t\treturn res;\n\t}\n\n\t/**\n\t * Parses LTO component to a format preview can understand.\n\t * Points to Note -\n\t * 1. Takes the Copy Code from previously parsed buttons.\n\t * 2. LTO component does not have a dateTime expiry by default. Hence, while sending template to ContextMapper, send with a date or current Date and Time is picked here.\n\t */\n\tprivate parseLimitedTimeOfferComponent(\n\t\tdbFormattedTemplate: WhatsAppTemplate,\n\t\tallButtons: WhatsappPreviewButtonType[],\n\t) {\n\t\tconst limitedTimeOfferComponent: CreateTemplateType['limitedTimeOfferComponent'] =\n\t\t\t{\n\t\t\t\ttext: '',\n\t\t\t\tdateTime: '',\n\t\t\t\tcode: '',\n\t\t\t};\n\n\t\tdbFormattedTemplate.components.forEach((component) => {\n\t\t\tif (component.type === 'limited_time_offer') {\n\t\t\t\tlimitedTimeOfferComponent.text =\n\t\t\t\t\tcomponent.limited_time_offer?.text ?? '';\n\t\t\t\tconst dateTime = component.example?.limited_time_offer;\n\t\t\t\tif (dateTime && dateTime.startsWith('{{') && dateTime.endsWith('}}')) {\n\t\t\t\t\tlimitedTimeOfferComponent.dateTime = dateTime;\n\t\t\t\t} else {\n\t\t\t\t\tlimitedTimeOfferComponent.dateTime = format(\n\t\t\t\t\t\tdateTime ? new Date(dateTime) : new Date(),\n\t\t\t\t\t\t'MMM dd',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tallButtons.forEach((button) => {\n\t\t\t\tif (button.type === 'COPY_CODE') {\n\t\t\t\t\tlimitedTimeOfferComponent.code = button.placeholder ?? '';\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\treturn limitedTimeOfferComponent;\n\t}\n\n\tprivate parseCallPermissionComponent(dbFormattedTemplate: WhatsAppTemplate): {\n\t\tshowCallPermissionCard: boolean;\n\t\tcallPermissionText?: string;\n\t} {\n\t\tconst callPermissionComponent = dbFormattedTemplate.components?.find(\n\t\t\t(component) => (component as any).type === 'CALL_PERMISSION_REQUEST',\n\t\t);\n\n\t\treturn {\n\t\t\tshowCallPermissionCard: Boolean(callPermissionComponent),\n\t\t\tcallPermissionText: (callPermissionComponent as any)?.text,\n\t\t};\n\t}\n\n\tasync parseUITemplateFromDBFormat(data: {\n\t\tdbFormattedTemplate: WhatsAppTemplate;\n\t\tisDuplicate?: boolean;\n\t\tshowSampleValues?: boolean;\n\t\tisV2?: boolean;\n\t\tpod?: string;\n\t}) {\n\t\tconst {\n\t\t\tdbFormattedTemplate,\n\t\t\tisDuplicate,\n\t\t\tisV2 = false,\n\t\t\tshowSampleValues,\n\t\t\tpod,\n\t\t} = data;\n\t\tconst {\n\t\t\theaderType,\n\t\t\theaderAssetLink,\n\t\t\theaderAssetName,\n\t\t\theaderText,\n\t\t\theaderVariables,\n\t\t} = await this.parseDataFromHeaderComponent(\n\t\t\tdbFormattedTemplate,\n\t\t\tundefined,\n\t\t\tpod,\n\t\t);\n\n\t\tconst { bodyText, bodyVariable: bodyVariables } =\n\t\t\tawait this.parseBodyComponent(\n\t\t\t\tdbFormattedTemplate,\n\t\t\t\tisV2,\n\t\t\t\tshowSampleValues,\n\t\t\t\tpod,\n\t\t\t);\n\t\tconst { titleText, titleVariables: titleVariables } =\n\t\t\tawait this.parseTitleComponent(\n\t\t\t\tdbFormattedTemplate,\n\t\t\t\tisV2,\n\t\t\t\tshowSampleValues,\n\t\t\t);\n\n\t\tconst { actionsType, quickReply, ctaBtn, allButtons } =\n\t\t\tawait this.parseButtonComponent(dbFormattedTemplate);\n\n\t\tconst limitedTimeOfferComponent = this.parseLimitedTimeOfferComponent(\n\t\t\tdbFormattedTemplate,\n\t\t\tallButtons,\n\t\t);\n\n\t\tconst { showCallPermissionCard, callPermissionText } =\n\t\t\tthis.parseCallPermissionComponent(dbFormattedTemplate);\n\n\t\tconst state: CreateTemplateType = {\n\t\t\tquickReply,\n\t\t\tctaBtn,\n\t\t\tallButtons,\n\t\t\tmeta: {\n\t\t\t\tname: isDuplicate\n\t\t\t\t\t? `${dbFormattedTemplate.label} Copy`\n\t\t\t\t\t: dbFormattedTemplate.label,\n\t\t\t\tcategory: dbFormattedTemplate.category?.toUpperCase(),\n\t\t\t\tsubCategory: dbFormattedTemplate.templateCategory,\n\t\t\t\tlanguage: dbFormattedTemplate.language,\n\t\t\t\ttemplateId: dbFormattedTemplate.templateId,\n\t\t\t},\n\t\t\terror: {\n\t\t\t\theader: undefined,\n\t\t\t\tbody: undefined,\n\t\t\t\tfooter: undefined,\n\t\t\t\tquickReply: undefined,\n\t\t\t\tmeta: undefined,\n\t\t\t\tctaBtn: undefined,\n\t\t\t},\n\n\t\t\tactionsType,\n\t\t\tfooterText: this.parseFooterComponent(dbFormattedTemplate),\n\t\t\t/** BODY TEXT */\n\t\t\tbodyVariables,\n\t\t\tbodyText,\n\n\t\t\t/** HEADER */\n\t\t\theaderType,\n\t\t\theaderAssetLink,\n\t\t\theaderAssetName,\n\t\t\theaderText,\n\t\t\theaderVariables,\n\t\t\talreadyAsADraft: dbFormattedTemplate.isDraft,\n\t\t\tmode: 'edit',\n\t\t\tinitialLoading: false,\n\t\t\t/* LIMITED TIME OFFER */\n\t\t\tlimitedTimeOfferComponent,\n\t\t\t/* Title for RCS */\n\t\t\ttitleText,\n\t\t\ttitleVariables,\n\t\t\t/* Call Permission */\n\t\t\tshowCallPermissionCard,\n\t\t\tcallPermissionText,\n\t\t};\n\n\t\tconst { errors } = this.validateState(state);\n\n\t\tstate.error = errors;\n\n\t\treturn state;\n\t}\n\n\tparseTemplateConfiguration(template: RCSTemplateType): RCSTemplateConfig {\n\t\tlet config: RCSTemplateConfig;\n\t\tconst templateConfig = template?.content || ({} as RCSTemplateConfig);\n\t\tif (typeof templateConfig === 'string') {\n\t\t\ttry {\n\t\t\t\tconfig = JSON.parse(templateConfig) as RCSTemplateConfig;\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error parsing rcsTemplate component JSON:', error);\n\t\t\t\tconfig = { orientation: 'VERTICAL' } as RCSTemplateConfig;\n\t\t\t}\n\t\t} else {\n\t\t\tconfig = templateConfig;\n\t\t}\n\t\treturn {\n\t\t\t...config,\n\t\t\ttemplateType: template?.templateType as RCS_TEMPLATE_TYPE,\n\t\t};\n\t}\n}\n"],"names":["TemplateCreatorHelper","dbFormattedTemplate","showSampleValues","pod","res","HEADER_TYPES","headerComponent","component","sampleValue","headerVarPlaceholder","originalVariable","normalizedName","editable","isChatbotCustomText","POD","reduxHeaderVar","state","emojiRegex","status","errors","templateHelperUtils","TemplateHelperUtils","isScrolled","scrollByElementId","elementId","NAME_LEN_LIMIT","NAME_LEN_ERROR","specialCharPattern","NO_SPECIAL_CHAR","REQUIRED_FIELD","CREATE_TEMPLATE_DOM_IDS","text","HEADER_TEXT_LEN_LIMIT","HEADER_LEN_ERROR","variableList","ONE_VAR_ALLOWED","HEADER_ASSET_LINK_ERROR","BODY_TEXT_LEN_LIMIT","BODY_LEN_ERROR","ACTIONS_TYPES","btnText","phoneNumber","QUICK_REPLY_BTN_TEXT_LIMIT","QUICK_REPLY_LEN_ERROR","BUTTON_EMOJI_ERROR","VALID_PHONE_NUMBER","customLink","placeholder","quickReplyErrors","button","i","QUICK_REPLY_NAME_LEN_LIMIT","buttons","el","QUICK_REPLY_NAME_ERROR","qrbErrorAcc","currentError","isV2","bodyVariable","bodyText","bodyComponent","bodyVarPlaceholder","matchedPlaceholderName","placeHolderNamePattern","t","normalizeName","COLORS","titleVariable","titleText","buttonComponent","actionsType","btnTexts","btn","btnPlaceholder","customUrl","editableVarPattern","allButtons","limitedTimeOfferComponent","dateTime","format","callPermissionComponent","data","isDuplicate","headerType","headerAssetLink","headerAssetName","headerText","headerVariables","bodyVariables","titleVariables","quickReply","ctaBtn","showCallPermissionCard","callPermiss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,CAAmB,EAE9C4E,EAA4B,KAAK,+BACtC5E,EACA2E,CAAA,EAGK,CAAE,uBAAAgB,EAAwB,mBAAAC,CAAA,EAC/B,KAAK,6BAA6B5F,CAAmB,EAEhDe,EAA4B,CACjC,WAAA0E,EACA,OAAAC,EACA,WAAAf,EACA,KAAM,CACL,KAAMM,EACH,GAAGjF,EAAoB,KAAK,QAC5BA,EAAoB,MACvB,SAAUA,EAAoB,UAAU,YAAA,EACxC,YAAaA,EAAoB,iBACjC,SAAUA,EAAoB,SAC9B,WAAYA,EAAoB,UAAA,EAEjC,MAAO,CACN,OAAQ,OACR,KAAM,OACN,OAAQ,OACR,WAAY,OACZ,KAAM,OACN,OAAQ,MAAA,EAGT,YAAAqE,EACA,WAAY,KAAK,qBAAqBrE,CAAmB,EAEzD,cAAAuF,EACA,SAAA7B,EAGA,WAAAwB,EACA,gBAAAC,EACA,gBAAAC,EACA,WAAAC,EACA,gBAAAC,EACA,gBAAiBtF,EAAoB,QACrC,KAAM,OACN,eAAgB,GAEhB,0BAAA4E,EAEA,UAAAT,EACA,eAAAqB,EAEA,uBAAAG,EACA,mBAAAC,CAAA,EAGK,CAAE,OAAA1E,CAAA,EAAW,KAAK,cAAcH,CAAK,EAE3C,OAAAA,EAAM,MAAQG,EAEPH,CACR,CAEA,2BAA2B8E,EAA8C,CACxE,IAAIC,EACJ,MAAMC,EAAiBF,GAAU,SAAY,CAAA,EAC7C,GAAI,OAAOE,GAAmB,SAC7B,GAAI,CACHD,EAAS,KAAK,MAAMC,CAAc,CACnC,OAASC,EAAO,CACf,QAAQ,MAAM,4CAA6CA,CAAK,EAChEF,EAAS,CAAE,YAAa,UAAA,CACzB,MAEAA,EAASC,EAEV,MAAO,CACN,GAAGD,EACH,aAAcD,GAAU,YAAA,CAE1B,CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RCSTemplate.js","sources":["../../../../../src/components/template-preview/models/RCSTemplate.ts"],"sourcesContent":["import { Timestamp } from 'firebase-admin/firestore';\nimport { CHANNEL_TYPE } from './Channels';\nimport { TEMPLATE_STATUS } from './TemplateMeta';\nimport { WhatsappLikePreviewTypes, WhatsAppTemplate } from './WhatsAppTemplate';\n\nexport interface RCSPreviewProps extends WhatsappLikePreviewTypes {\n\tisCarousal?: boolean;\n}\nexport interface RCSTemplateType extends WhatsAppTemplate {\n\tid: string;\n\tstatus: TEMPLATE_STATUS;\n\tname: string;\n\tcontent?: string;\n\tmapping: { [key: string]: string[] | object[] };\n\tmediaTemplateActionButtonTypes: { [key: string]: string[] | object[] };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tcreatedAt: number;\n\tupdatedAt: number;\n\ttemplateType?: RCS_TEMPLATE_TYPE;\n\trcsBroadcastConfig?: {\n\t\tmapping: { [key: string]: string | object };\n\t};\n\thtmlContentUrl?: string;\n\ttemplateId?: string;\n\tchannel: CHANNEL_TYPE;\n\theaders?: string[];\n}\n\nexport interface RCSPreviewPropsV2 extends WhatsappLikePreviewTypes {\n\ttemplateConfiguration: RCSTemplateConfig;\n}\n\nexport interface RcsTemplate {\n\tcontent?: string;\n\tcomponents: string;\n\tmapping: { [key: string]: string | object };\n\tmediaTemplateActionButtonTypes: { [key: string]: string | object };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tstatus: TEMPLATE_STATUS;\n\texternalStatus: RCS_TEMPLATE_STATUS;\n\ttemplateType: string;\n\tcreatedAt: Timestamp;\n\tupdatedAt: Timestamp;\n}\n\nexport interface CreateRcsTemplatePayload {\n\tname: string;\n\tlabel: string;\n\tstoreId: string;\n\tcategory: string;\n\tchannelTemplateId: string;\n\tchannel: string;\n\tcontent: string;\n\tcomponents: string;\n\tmapping: { [key: string]: string | object };\n\tmediaTemplateActionButtonTypes: { [key: string]: string | object };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tbotId: string;\n\texternalStatus: RCS_TEMPLATE_STATUS;\n\ttemplateType: string;\n\tstatus: TEMPLATE_STATUS;\n\tcreatedAt: Timestamp;\n\tcreatedBy: string;\n\ttemplateCategory?: string;\n\tupdatedAt: Timestamp;\n\ttemplateId?: string;\n}\n\nexport enum RCS_TEMPLATE_STATUS {\n\tACTIVE = 'active',\n\tAPPROVED = 'approved',\n\tPENDING = 'pending',\n\tREJECTED = 'rejected',\n\tFAILED = 'Failed',\n}\n\nexport enum RCS_TEMPLATE_TYPE {\n\tTEXT_MESSAGE = 'text_message', //body and button(name and url)--> custom variable\n\tTEXT_MESSAGE_WITH_PDF = 'text_message_with_pdf', //body, and button(name and url)custom\n\tCAROUSEL = 'carousel', //body, and button(name and url)custom ,title\n\tRICH_CARD = 'rich_card', //body, and button(name and url)custom ,title\n\tUNKNOWN = 'unknown',\n}\n\nexport enum RCS_BUTTON_TYPE {\n\tREPLY = 'reply',\n\tURL_ACTION = 'url_action', // url --->\n\tDIALER_ACTION = 'dialer_action',\n\tVIEW_LOCATION_LATLONG = 'view_location_latlong',\n\tVIEW_LOCATION_QUERY = 'view_location_query',\n\tSHARE_LOCATION = 'share_location',\n\tCALENDAR_EVENT = 'calendar_event',\n}\n\nexport enum MEDIA_FORMAT {\n\tIMAGE = 'image',\n\tVIDEO = 'video',\n\tDOCUMENT = 'document',\n\tOTHER = 'other',\n}\n\nexport enum IMAGE_EXTENSIONS {\n\tJPG = 'jpg',\n\tJPEG = 'jpeg',\n\tPNG = 'png',\n\tGIF = 'gif',\n\tBMP = 'bmp',\n\tWEBP = 'webp',\n}\n\nexport enum VIDEO_EXTENSIONS {\n\tMP4 = 'mp4',\n\tMOV = 'mov',\n\tAVI = 'avi',\n\tMKV = 'mkv',\n\tWEBM = 'webm',\n}\n\nexport enum DOCUMENT_EXTENSIONS {\n\tPDF = 'pdf',\n\tDOC = 'doc',\n\tDOCX = 'docx',\n\tXLS = 'xls',\n\tXLSX = 'xlsx',\n\tPPT = 'ppt',\n\tPPTX = 'pptx',\n\tTXT = 'txt',\n}\n\nexport interface RCSTemplateConfig {\n\ttemplateType: RCS_TEMPLATE_TYPE | string;\n\theight: string;\n\torientation: string;\n
|
|
1
|
+
{"version":3,"file":"RCSTemplate.js","sources":["../../../../../src/components/template-preview/models/RCSTemplate.ts"],"sourcesContent":["import { Timestamp } from 'firebase-admin/firestore';\nimport { CHANNEL_TYPE } from './Channels';\nimport { TEMPLATE_STATUS } from './TemplateMeta';\nimport { WhatsappLikePreviewTypes, WhatsAppTemplate } from './WhatsAppTemplate';\n\nexport interface RCSPreviewProps extends WhatsappLikePreviewTypes {\n\tisCarousal?: boolean;\n}\nexport interface RCSTemplateType extends WhatsAppTemplate {\n\tid: string;\n\tstatus: TEMPLATE_STATUS;\n\tname: string;\n\tcontent?: string;\n\tmapping: { [key: string]: string[] | object[] };\n\tmediaTemplateActionButtonTypes: { [key: string]: string[] | object[] };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tcreatedAt: number;\n\tupdatedAt: number;\n\ttemplateType?: RCS_TEMPLATE_TYPE;\n\trcsBroadcastConfig?: {\n\t\tmapping: { [key: string]: string | object };\n\t};\n\thtmlContentUrl?: string;\n\ttemplateId?: string;\n\tchannel: CHANNEL_TYPE;\n\theaders?: string[];\n}\n\nexport interface RCSPreviewPropsV2 extends WhatsappLikePreviewTypes {\n\ttemplateConfiguration: RCSTemplateConfig;\n}\n\nexport interface RcsTemplate {\n\tcontent?: string;\n\tcomponents: string;\n\tmapping: { [key: string]: string | object };\n\tmediaTemplateActionButtonTypes: { [key: string]: string | object };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tstatus: TEMPLATE_STATUS;\n\texternalStatus: RCS_TEMPLATE_STATUS;\n\ttemplateType: string;\n\tcreatedAt: Timestamp;\n\tupdatedAt: Timestamp;\n}\n\nexport interface CreateRcsTemplatePayload {\n\tname: string;\n\tlabel: string;\n\tstoreId: string;\n\tcategory: string;\n\tchannelTemplateId: string;\n\tchannel: string;\n\tcontent: string;\n\tcomponents: string;\n\tmapping: { [key: string]: string | object };\n\tmediaTemplateActionButtonTypes: { [key: string]: string | object };\n\tcustomParams?: Record<string, string>;\n\tdestinationUrl?: Record<string, string>;\n\tbotId: string;\n\texternalStatus: RCS_TEMPLATE_STATUS;\n\ttemplateType: string;\n\tstatus: TEMPLATE_STATUS;\n\tcreatedAt: Timestamp;\n\tcreatedBy: string;\n\ttemplateCategory?: string;\n\tupdatedAt: Timestamp;\n\ttemplateId?: string;\n}\n\nexport enum RCS_TEMPLATE_STATUS {\n\tACTIVE = 'active',\n\tAPPROVED = 'approved',\n\tPENDING = 'pending',\n\tREJECTED = 'rejected',\n\tFAILED = 'Failed',\n}\n\nexport enum RCS_TEMPLATE_TYPE {\n\tTEXT_MESSAGE = 'text_message', //body and button(name and url)--> custom variable\n\tTEXT_MESSAGE_WITH_PDF = 'text_message_with_pdf', //body, and button(name and url)custom\n\tCAROUSEL = 'carousel', //body, and button(name and url)custom ,title\n\tRICH_CARD = 'rich_card', //body, and button(name and url)custom ,title\n\tUNKNOWN = 'unknown',\n}\n\nexport enum RCS_BUTTON_TYPE {\n\tREPLY = 'reply',\n\tURL_ACTION = 'url_action', // url --->\n\tDIALER_ACTION = 'dialer_action',\n\tVIEW_LOCATION_LATLONG = 'view_location_latlong',\n\tVIEW_LOCATION_QUERY = 'view_location_query',\n\tSHARE_LOCATION = 'share_location',\n\tCALENDAR_EVENT = 'calendar_event',\n}\n\nexport enum MEDIA_FORMAT {\n\tIMAGE = 'image',\n\tVIDEO = 'video',\n\tDOCUMENT = 'document',\n\tOTHER = 'other',\n}\n\nexport enum IMAGE_EXTENSIONS {\n\tJPG = 'jpg',\n\tJPEG = 'jpeg',\n\tPNG = 'png',\n\tGIF = 'gif',\n\tBMP = 'bmp',\n\tWEBP = 'webp',\n}\n\nexport enum VIDEO_EXTENSIONS {\n\tMP4 = 'mp4',\n\tMOV = 'mov',\n\tAVI = 'avi',\n\tMKV = 'mkv',\n\tWEBM = 'webm',\n}\n\nexport enum DOCUMENT_EXTENSIONS {\n\tPDF = 'pdf',\n\tDOC = 'doc',\n\tDOCX = 'docx',\n\tXLS = 'xls',\n\tXLSX = 'xlsx',\n\tPPT = 'ppt',\n\tPPTX = 'pptx',\n\tTXT = 'txt',\n}\n\nexport interface RCSTemplateConfig {\n\ttemplateType: RCS_TEMPLATE_TYPE | string;\n\theight: string;\n\torientation: string;\n}\n"],"names":["RCS_TEMPLATE_TYPE"],"mappings":"gFA+EO,IAAKA,GAAAA,IACXA,EAAA,aAAe,eACfA,EAAA,sBAAwB,wBACxBA,EAAA,SAAW,WACXA,EAAA,UAAY,YACZA,EAAA,QAAU,UALCA,IAAAA,GAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react/jsx-runtime"),te=require("../node_modules/@tiptap/core/dist/index.js"),D=require("@tiptap/react"),c=require("react"),ne=require("./BikEditor.styles.js"),U=require("./BikEditor.types.js"),s=require("./BikEditor.utils.js"),oe=require("./extensions/buildExtensions.js"),re=require("./floating/LinkBubbleMenu.js");function se(g){return Object.entries(g).map(([h,f])=>`${h.replace(/([A-Z])/g,m=>`-${m.toLowerCase()}`)}:${f}`).join(";")}const ie=(g,h)=>{const{initialContent:f,sections:m,features:k,disabled:N,maxCharacters:y,shortcuts:W,sendShortcut:$,mentions:l,slashCommands:d,link:J,onPaste:Q,onReady:R,onChange:x,onSend:p,onFocus:B,onBlur:b,onSelectionChange:A,minHeight:V,maxHeight:Z,style:G,className:K,editorClassName:E,editorStyle:z}=g,X=m?.length?s.buildSectionedContent(s.normalizeHtml(f??""),m.map(e=>({...e,content:s.normalizeHtml(e.content)}))):s.normalizeHtml(f??""),C=c.useRef([]),H=c.useRef(!1),I=c.useRef(R);I.current=R;const T=c.useRef(x);T.current=x;const L=c.useRef(A);L.current=A;const v=c.useRef(U.DEFAULT_FORMAT_STATE),F=c.useRef(B);F.current=B;const M=c.useRef(b);M.current=b;const q=c.useRef(p);q.current=p;const O=c.useRef(l?.agents??[]);O.current=l?.agents??[];const P=c.useRef(l?.teams??[]);P.current=l?.teams??[];const w=c.useRef(d?.items??[]);w.current=d?.items??[];const o=D.useEditor({extensions:oe.buildExtensions({features:k,placeholder:g.placeholder,maxCharacters:y,hasSections:(m?.length??0)>0,mentions:{agents:l?O:void 0,teams:l?P:void 0},slashCommands:d?w:void 0,onPaste:Q,onSend:p?e=>q.current?.(e):void 0,sendShortcut:$,shortcuts:W,onMentionSelected:l?.onSelect,onSlashCommandSelected:d?.onSelect,renderMentionItem:l?.renderItem,renderMentionDropdown:l?.renderDropdown,renderSlashCommandItem:d?.renderItem,renderSlashCommandDropdown:d?.renderDropdown}),content:X,editable:!N,immediatelyRender:!1,editorProps:{attributes:{...E?{class:E}:{},...z?{style:se(z)}:{}}},onUpdate:({editor:e})=>{T.current?.(s.extractContent(e))},onTransaction:({editor:e})=>{const t=s.extractActiveFormats(e),n=v.current;(n.bold!==t.bold||n.italic!==t.italic||n.underline!==t.underline||n.strike!==t.strike||n.bulletList!==t.bulletList||n.orderedList!==t.orderedList||n.blockquote!==t.blockquote||n.codeBlock!==t.codeBlock||n.superscript!==t.superscript||n.subscript!==t.subscript||n.textAlign!==t.textAlign||n.fontFamily!==t.fontFamily||n.fontSize!==t.fontSize||n.color!==t.color||n.highlight!==t.highlight||n.link?.href!==t.link?.href)&&(v.current=t,L.current?.(t))},onFocus:()=>F.current?.(),onBlur:()=>M.current?.()});function i(e){o?e(o):C.current.push(e)}return c.useEffect(()=>{o&&(C.current.length>0&&C.current.splice(0).forEach(t=>t(o)),H.current||(H.current=!0,I.current?.()))},[o]),c.useImperativeHandle(h,()=>({focus:e=>i(t=>t.commands.focus(e)),blur:()=>i(e=>e.commands.blur()),clearContent:()=>i(e=>e.commands.clearContent(!0)),setContent:e=>{const t=s.normalizeHtml(e);i(n=>n.commands.setContent(t,{emitUpdate:!0}))},insertContent:e=>{const t=s.normalizeHtml(e);i(n=>n.commands.insertContent(t))},insertInlineContent:e=>{i(t=>s.insertInlineHtml(t,e))},insertAtStart:e=>{const t=s.normalizeHtml(e);i(n=>n.commands.insertContentAt(1,t))},insertBlock:e=>{const t=s.normalizeHtml(e);i(n=>n.commands.insertContentAt(n.state.doc.content.size,t))},appendInline:e=>{const t=s.normalizeHtml(e);i(n=>n.commands.insertContentAt(n.state.doc.content.size-1,t))},insertAtEnd(e){this.insertBlock(e)},appendContent(e){this.appendInline(e)},getContent:()=>o?s.extractContent(o):{html:"",text:"",isEmpty:!0,characterCount:0},getJSON:()=>o?.getJSON()??null,getMentions:()=>{const e=new Set,t=new Set;return o?(o.state.doc.descendants(n=>{n.type.name==="mentionAgent"&&n.attrs.id!=null?e.add(String(n.attrs.id)):n.type.name==="mentionTeam"&&n.attrs.id!=null&&t.add(String(n.attrs.id))}),{agentIds:Array.from(e),teamIds:Array.from(t)}):{agentIds:[],teamIds:[]}},getCursorPosition:()=>{if(!o)return{from:0,to:0};const{from:e,to:t}=o.state.selection;return{from:e,to:t}},insertAtPosition:(e,t)=>{const n=s.normalizeHtml(t);i(r=>r.commands.insertContentAt(e,n))},getSelectedText:()=>{if(!o)return"";const{state:e}=o,{from:t,to:n,empty:r}=e.selection;if(!r)return e.doc.textBetween(t,n," ");const a=e.schema.marks.link;if(a){const u=te.getMarkRange(e.doc.resolve(t),a);if(u)return e.doc.textBetween(u.from,u.to," ")}return""},getCharacterCount:()=>({count:o?.storage.characterCount?.characters?.()??o?.getText().length??0,limit:y??null}),getSectionContent:e=>o?s.extractSectionContent(o,e):{html:"",text:"",isEmpty:!0,characterCount:0},setSectionContent:(e,t)=>{const n=s.normalizeHtml(t);i(r=>s.setSectionContentInEditor(r,e,n))},focusSection:e=>{i(t=>{if(e==="body"){let r=t.state.doc.content.size-1;t.state.doc.descendants((a,u)=>(a.type.name==="sectionDivider"&&r===t.state.doc.content.size-1&&(r=u-1),r===t.state.doc.content.size-1)),r<1&&(r=1),t.chain().focus().setTextSelection(r).run();return}let n=-1;t.state.doc.descendants((r,a)=>{if(n!==-1)return!1;r.type.name==="sectionDivider"&&r.attrs.sectionId===e&&(n=a+r.nodeSize+1)}),n!==-1&&t.chain().focus().setTextSelection(n).run()})},clearSection:e=>{i(t=>s.setSectionContentInEditor(t,e,"<p></p>"))},getBodyContent:()=>o?s.extractBodyContent(o):{html:"",text:"",isEmpty:!0,characterCount:0},setBodyContent:e=>{const t=s.normalizeHtml(e);i(n=>s.setSectionContentInEditor(n,"body",t))},setBodyAndSections:(e,t)=>{const n=s.buildSectionedContent(s.normalizeHtml(e),t.map(r=>({id:r.id,content:s.normalizeHtml(r.content)})));i(r=>r.commands.setContent(n,{emitUpdate:!0}))},appendBodyContent:e=>{const t=s.normalizeHtml(e);i(n=>{const r=s.findSectionEndPos(n,"body");n.commands.insertContentAt(r-1,t,{parseOptions:{preserveWhitespace:!0}})})},insertAtSectionStart:(e,t)=>{const n=s.normalizeHtml(t);i(r=>{const a=s.findSectionStartPos(r,e);a!==-1&&r.commands.insertContentAt(a,n,{parseOptions:{preserveWhitespace:!0}})})},insertAtSectionEnd:(e,t)=>{const n=s.normalizeHtml(t);i(r=>{const a=s.findSectionEndPos(r,e);r.commands.insertContentAt(a,n,{parseOptions:{preserveWhitespace:!0}})})},getActiveFormats:()=>o?s.extractActiveFormats(o):U.DEFAULT_FORMAT_STATE,actions:{toggleBold:()=>o?.chain().focus().toggleBold().run(),toggleItalic:()=>o?.chain().focus().toggleItalic().run(),toggleUnderline:()=>o?.chain().focus().toggleUnderline().run(),toggleStrike:()=>o?.chain().focus().toggleStrike().run(),toggleBulletList:()=>o?.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>o?.chain().focus().toggleOrderedList().run(),toggleBlockquote:()=>o?.chain().focus().toggleBlockquote().run(),toggleCodeBlock:()=>o?.chain().focus().toggleCodeBlock().run(),setTextAlign:e=>o?.chain().focus().setTextAlign(e).run(),setFontFamily:e=>o?.chain().focus().setFontFamily(e).run(),setFontSize:e=>o?.chain().focus().setFontSize(e).run(),setColor:e=>o?.chain().focus().setColor(e).run(),setHighlight:e=>o?.chain().focus().toggleHighlight({color:e}).run(),unsetColor:()=>o?.chain().focus().unsetColor().run(),unsetHighlight:()=>o?.chain().focus().unsetHighlight().run(),setLink:(e,t)=>{o&&(t!==void 0?o.chain().focus().extendMarkRange("link").command(({tr:n,state:r})=>{const{from:a,to:u}=n.selection,j=r.schema.marks.link;if(!j)return!1;const Y=r.schema.text(t,[j.create({href:e})]),ee=r.schema.text(" ");return n.replaceWith(a,u,[Y,ee]),!0}).run():o.chain().focus().extendMarkRange("link").setLink({href:e}).insertContent(" ").run())},updateLink:e=>o?.chain().focus().extendMarkRange("link").setLink({href:e}).run(),removeLink:()=>o?.chain().focus().extendMarkRange("link").unsetLink().run(),insertEmoji:e=>o?.chain().focus().insertContent(e).run(),insertVariable:e=>o?.chain().focus().insertContent(`{{${e}}}`).run(),insertHtml:e=>o?.commands.insertContent(s.normalizeHtml(e)),undo:()=>o?.chain().focus().undo().run(),redo:()=>o?.chain().focus().redo().run(),canUndo:()=>o?.can().undo()??!1,canRedo:()=>o?.can().redo()??!1,toggleSuperscript:()=>o?.chain().focus().toggleSuperscript().run(),toggleSubscript:()=>o?.chain().focus().toggleSubscript().run(),insertImage:e=>o?.chain().focus().setImage({src:e}).run()}}),[o]),o?S.jsxs(ne.BikEditorShell,{minHeight:V,maxHeight:Z,tightParagraphs:!k?.richPaste,style:G,className:K,children:[S.jsx(D.EditorContent,{editor:o}),S.jsx(re.LinkBubbleMenu,{editor:o,renderLinkTooltip:J?.renderTooltip})]}):null},_=c.forwardRef(ie);_.displayName="BikEditor";exports.BikEditor=_;
|
|
2
2
|
//# sourceMappingURL=BikEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BikEditor.js","sources":["../../../src/editor/BikEditor.tsx"],"sourcesContent":["'use client';\n\n/**\n * IMPLEMENTATION LAYER — TipTap-specific.\n * If the underlying editor is swapped, this file changes; BikEditor.types.ts and\n * src/editor/index.ts (the consumer contract) do NOT change.\n */\nimport { Editor, getMarkRange } from '@tiptap/core';\nimport { EditorContent, useEditor } from '@tiptap/react';\nimport React, {\n\tforwardRef,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n} from 'react';\nimport { BikEditorShell } from './BikEditor.styles';\nimport {\n\tBikEditorProps,\n\tBikEditorRef,\n\tDEFAULT_FORMAT_STATE,\n\tFormatState,\n} from './BikEditor.types';\nimport {\n\tbuildSectionedContent,\n\textractActiveFormats,\n\textractBodyContent,\n\textractContent,\n\textractSectionContent,\n\tfindSectionEndPos,\n\tfindSectionStartPos,\n\tinsertInlineHtml,\n\tnormalizeHtml,\n\tsetSectionContentInEditor,\n} from './BikEditor.utils';\nimport { buildExtensions } from './extensions/buildExtensions';\nimport { LinkBubbleMenu } from './floating/LinkBubbleMenu';\n\n/** Convert React.CSSProperties to an inline CSS string for editorProps.attributes. */\nfunction cssToString(style: React.CSSProperties): string {\n\treturn Object.entries(style)\n\t\t.map(\n\t\t\t([k, v]) => `${k.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`)}:${v}`,\n\t\t)\n\t\t.join(';');\n}\n\nconst BikEditorInner = (\n\tprops: BikEditorProps,\n\tref: React.Ref<BikEditorRef>,\n) => {\n\tconst {\n\t\tinitialContent,\n\t\tsections,\n\t\tfeatures,\n\t\tdisabled,\n\t\tmaxCharacters,\n\t\tshortcuts,\n\t\tsendShortcut,\n\t\tmentions,\n\t\tslashCommands,\n\t\tlink,\n\t\tonPaste,\n\t\tonReady,\n\t\tonChange,\n\t\tonSend,\n\t\tonFocus,\n\t\tonBlur,\n\t\tonSelectionChange,\n\t\tminHeight,\n\t\tmaxHeight,\n\t\tstyle,\n\t\tclassName,\n\t\teditorClassName,\n\t\teditorStyle,\n\t} = props;\n\n\tconst initialEditorContent = sections?.length\n\t\t? buildSectionedContent(\n\t\t\t\tnormalizeHtml(initialContent ?? ''),\n\t\t\t\tsections.map((s) => ({ ...s, content: normalizeHtml(s.content) })),\n\t\t )\n\t\t: normalizeHtml(initialContent ?? '');\n\n\t// ── Command queue ─────────────────────────────────────────────────────────\n\t// TipTap's useEditor initializes asynchronously; the editor instance is null\n\t// until the first commit. Any imperative method called before the editor is\n\t// ready is enqueued here and flushed automatically once it becomes non-null.\n\t// Consumers never need setTimeout or readiness guards.\n\tconst pendingQueue = useRef<Array<(e: Editor) => void>>([]);\n\tconst hasCalledOnReady = useRef(false);\n\t// Keep stable refs to all callbacks so useEditor receives the same function\n\t// identity on every render — prevents TipTap from re-registering event\n\t// handlers every time the parent re-renders with new inline function props.\n\tconst onReadyRef = useRef(onReady);\n\tonReadyRef.current = onReady;\n\tconst onChangeRef = useRef(onChange);\n\tonChangeRef.current = onChange;\n\tconst onSelectionChangeRef = useRef(onSelectionChange);\n\tonSelectionChangeRef.current = onSelectionChange;\n\tconst prevFormatsRef = useRef<FormatState>(DEFAULT_FORMAT_STATE);\n\tconst onFocusRef = useRef(onFocus);\n\tonFocusRef.current = onFocus;\n\tconst onBlurRef = useRef(onBlur);\n\tonBlurRef.current = onBlur;\n\tconst onSendRef = useRef(onSend);\n\tonSendRef.current = onSend;\n\tconst agentMentionsRef = useRef(mentions?.agents ?? []);\n\tagentMentionsRef.current = mentions?.agents ?? [];\n\tconst teamMentionsRef = useRef(mentions?.teams ?? []);\n\tteamMentionsRef.current = mentions?.teams ?? [];\n\tconst slashCommandsRef = useRef(slashCommands?.items ?? []);\n\tslashCommandsRef.current = slashCommands?.items ?? [];\n\n\tconst editor = useEditor({\n\t\textensions: buildExtensions({\n\t\t\tfeatures,\n\t\t\tplaceholder: props.placeholder,\n\t\t\tmaxCharacters,\n\t\t\thasSections: (sections?.length ?? 0) > 0,\n\t\t\tmentions: {\n\t\t\t\tagents: mentions ? agentMentionsRef : undefined,\n\t\t\t\tteams: mentions ? teamMentionsRef : undefined,\n\t\t\t},\n\t\t\tslashCommands: slashCommands ? slashCommandsRef : undefined,\n\t\t\tonPaste,\n\t\t\tonSend: onSend ? (snapshot) => onSendRef.current?.(snapshot) : undefined,\n\t\t\tsendShortcut,\n\t\t\tshortcuts,\n\t\t\tonMentionSelected: mentions?.onSelect,\n\t\t\tonSlashCommandSelected: slashCommands?.onSelect,\n\t\t\trenderMentionItem: mentions?.renderItem,\n\t\t\trenderMentionDropdown: mentions?.renderDropdown,\n\t\t\trenderSlashCommandItem: slashCommands?.renderItem,\n\t\t\trenderSlashCommandDropdown: slashCommands?.renderDropdown,\n\t\t}),\n\t\tcontent: initialEditorContent,\n\t\teditable: !disabled,\n\t\timmediatelyRender: false, // SSR-safe — NEVER remove this\n\t\teditorProps: {\n\t\t\tattributes: {\n\t\t\t\t...(editorClassName ? { class: editorClassName } : {}),\n\t\t\t\t...(editorStyle ? { style: cssToString(editorStyle) } : {}),\n\t\t\t},\n\t\t},\n\t\tonUpdate: ({ editor: e }) => {\n\t\t\tonChangeRef.current?.(extractContent(e));\n\t\t},\n\t\tonTransaction: ({ editor: e }) => {\n\t\t\tconst next = extractActiveFormats(e);\n\t\t\tconst prev = prevFormatsRef.current;\n\t\t\tconst changed =\n\t\t\t\tprev.bold !== next.bold ||\n\t\t\t\tprev.italic !== next.italic ||\n\t\t\t\tprev.underline !== next.underline ||\n\t\t\t\tprev.strike !== next.strike ||\n\t\t\t\tprev.bulletList !== next.bulletList ||\n\t\t\t\tprev.orderedList !== next.orderedList ||\n\t\t\t\tprev.blockquote !== next.blockquote ||\n\t\t\t\tprev.codeBlock !== next.codeBlock ||\n\t\t\t\tprev.superscript !== next.superscript ||\n\t\t\t\tprev.subscript !== next.subscript ||\n\t\t\t\tprev.textAlign !== next.textAlign ||\n\t\t\t\tprev.fontFamily !== next.fontFamily ||\n\t\t\t\tprev.fontSize !== next.fontSize ||\n\t\t\t\tprev.color !== next.color ||\n\t\t\t\tprev.highlight !== next.highlight ||\n\t\t\t\tprev.link?.href !== next.link?.href;\n\t\t\tif (changed) {\n\t\t\t\tprevFormatsRef.current = next;\n\t\t\t\tonSelectionChangeRef.current?.(next);\n\t\t\t}\n\t\t},\n\t\tonFocus: () => onFocusRef.current?.(),\n\t\tonBlur: () => onBlurRef.current?.(),\n\t});\n\n\t// ── enqueue ───────────────────────────────────────────────────────────────\n\t// Run immediately if the editor is ready; otherwise defer to the queue.\n\t// Closures passed to enqueue MUST capture all parameters explicitly —\n\t// they must NOT close over `editor` (which would be null at enqueue time).\n\tfunction enqueue(op: (e: Editor) => void): void {\n\t\tif (editor) {\n\t\t\top(editor);\n\t\t} else {\n\t\t\tpendingQueue.current.push(op);\n\t\t}\n\t}\n\n\t// Flush the pending queue and fire onReady when editor transitions null → ready.\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\t\tif (pendingQueue.current.length > 0) {\n\t\t\tconst queue = pendingQueue.current.splice(0);\n\t\t\tqueue.forEach((op) => op(editor));\n\t\t}\n\t\tif (!hasCalledOnReady.current) {\n\t\t\thasCalledOnReady.current = true;\n\t\t\tonReadyRef.current?.();\n\t\t}\n\t}, [editor]);\n\n\tuseImperativeHandle(\n\t\tref,\n\t\t() => ({\n\t\t\t// ── Focus ────────────────────────────────────────────────────────\n\t\t\tfocus: (position) => enqueue((e) => e.commands.focus(position)),\n\t\t\tblur: () => enqueue((e) => e.commands.blur()),\n\n\t\t\t// ── Content ──────────────────────────────────────────────────────\n\t\t\tclearContent: () => enqueue((e) => e.commands.clearContent(true)),\n\t\t\tsetContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.setContent(normalised, { emitUpdate: true }));\n\t\t\t},\n\t\t\tinsertContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContent(normalised));\n\t\t\t},\n\t\t\tinsertInlineContent: (html) => {\n\t\t\t\tenqueue((e) => insertInlineHtml(e, html));\n\t\t\t},\n\t\t\tinsertAtStart: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(1, normalised));\n\t\t\t},\n\t\t\tinsertBlock: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\tappendInline: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// doc.content.size is after the last </p> (block boundary).\n\t\t\t\t// Subtract 1 to land inside the last paragraph so text appends\n\t\t\t\t// inline rather than being wrapped in a new paragraph each call.\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size - 1, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Backwards-compatible aliases\n\t\t\tinsertAtEnd(html) {\n\t\t\t\tthis.insertBlock(html);\n\t\t\t},\n\t\t\tappendContent(html) {\n\t\t\t\tthis.appendInline(html);\n\t\t\t},\n\t\t\tgetContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tgetJSON: () => editor?.getJSON() ?? null,\n\t\t\tgetMentions: () => {\n\t\t\t\tconst agentIds = new Set<string>();\n\t\t\t\tconst teamIds = new Set<string>();\n\t\t\t\tif (!editor) return { agentIds: [], teamIds: [] };\n\t\t\t\teditor.state.doc.descendants((node) => {\n\t\t\t\t\tif (node.type.name === 'mentionAgent' && node.attrs['id'] != null) {\n\t\t\t\t\t\tagentIds.add(String(node.attrs['id']));\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tnode.type.name === 'mentionTeam' &&\n\t\t\t\t\t\tnode.attrs['id'] != null\n\t\t\t\t\t) {\n\t\t\t\t\t\tteamIds.add(String(node.attrs['id']));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn { agentIds: Array.from(agentIds), teamIds: Array.from(teamIds) };\n\t\t\t},\n\n\t\t\t// ── Selection ────────────────────────────────────────────────────\n\t\t\tgetCursorPosition: () => {\n\t\t\t\tif (!editor) return { from: 0, to: 0 };\n\t\t\t\tconst { from, to } = editor.state.selection;\n\t\t\t\treturn { from, to };\n\t\t\t},\n\t\t\tinsertAtPosition: (pos, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(pos, normalised));\n\t\t\t},\n\t\t\tgetSelectedText: () => {\n\t\t\t\tif (!editor) return '';\n\t\t\t\tconst { state } = editor;\n\t\t\t\tconst { from, to, empty } = state.selection;\n\t\t\t\tif (!empty) {\n\t\t\t\t\treturn state.doc.textBetween(from, to, ' ');\n\t\t\t\t}\n\t\t\t\t// When the cursor is inside a link with nothing selected, return the\n\t\t\t\t// full link text — useful for pre-filling a link modal's text field.\n\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\tif (linkMarkType) {\n\t\t\t\t\tconst range = getMarkRange(state.doc.resolve(from), linkMarkType);\n\t\t\t\t\tif (range) {\n\t\t\t\t\t\treturn state.doc.textBetween(range.from, range.to, ' ');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t},\n\n\t\t\t// ── Character count ───────────────────────────────────────────────\n\t\t\tgetCharacterCount: () => ({\n\t\t\t\tcount:\n\t\t\t\t\teditor?.storage.characterCount?.characters?.() ??\n\t\t\t\t\teditor?.getText().length ??\n\t\t\t\t\t0,\n\t\t\t\tlimit: maxCharacters ?? null,\n\t\t\t}),\n\n\t\t\t// ── Sections ─────────────────────────────────────────────────────\n\t\t\tgetSectionContent: (sectionId) =>\n\t\t\t\teditor\n\t\t\t\t\t? extractSectionContent(editor, sectionId)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\n\t\t\tsetSectionContent: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, normalised));\n\t\t\t},\n\n\t\t\tfocusSection: (sectionId) => {\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tif (sectionId === 'body') {\n\t\t\t\t\t\tlet endOfBody = e.state.doc.content.size - 1;\n\t\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\t\tendOfBody === e.state.doc.content.size - 1\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tendOfBody = pos - 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn endOfBody === e.state.doc.content.size - 1;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (endOfBody < 1) endOfBody = 1;\n\t\t\t\t\t\te.chain().focus().setTextSelection(endOfBody).run();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet targetPos = -1;\n\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\tif (targetPos !== -1) return false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// pos + nodeSize lands right after the divider;\n\t\t\t\t\t\t\t// +1 more puts us inside the first paragraph of that section.\n\t\t\t\t\t\t\ttargetPos = pos + node.nodeSize + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (targetPos !== -1) {\n\t\t\t\t\t\te.chain().focus().setTextSelection(targetPos).run();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\n\t\t\tclearSection: (sectionId) => {\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, '<p></p>'));\n\t\t\t},\n\n\t\t\t// ── Convenience body shorthands ───────────────────────────────────\n\t\t\tgetBodyContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractBodyContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tsetBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, 'body', normalised));\n\t\t\t},\n\t\t\tsetBodyAndSections: (body, sections) => {\n\t\t\t\tconst html = buildSectionedContent(\n\t\t\t\t\tnormalizeHtml(body),\n\t\t\t\t\tsections.map((s) => ({\n\t\t\t\t\t\tid: s.id,\n\t\t\t\t\t\tcontent: normalizeHtml(s.content),\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t\tenqueue((e) => e.commands.setContent(html, { emitUpdate: true }));\n\t\t\t},\n\t\t\tappendBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// findSectionEndPos returns the position of the first divider (or\n\t\t\t\t// doc.content.size), which is the block boundary after the last </p>.\n\t\t\t\t// Subtract 1 to stay inside the last paragraph so successive calls\n\t\t\t\t// append inline text rather than creating a new paragraph each time.\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst boundaryPos = findSectionEndPos(e, 'body');\n\t\t\t\t\te.commands.insertContentAt(boundaryPos - 1, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionStart: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionStartPos(e, sectionId);\n\t\t\t\t\tif (pos !== -1) e.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionEnd: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionEndPos(e, sectionId);\n\t\t\t\t\te.commands.insertContentAt(pos, normalised);\n\t\t\t\t});\n\t\t\t},\n\t\t\t// ── Formats & actions ─────────────────────────────────────────────\n\t\t\tgetActiveFormats: () =>\n\t\t\t\teditor ? extractActiveFormats(editor) : DEFAULT_FORMAT_STATE,\n\t\t\tactions: {\n\t\t\t\ttoggleBold: () => editor?.chain().focus().toggleBold().run(),\n\t\t\t\ttoggleItalic: () => editor?.chain().focus().toggleItalic().run(),\n\t\t\t\ttoggleUnderline: () => editor?.chain().focus().toggleUnderline().run(),\n\t\t\t\ttoggleStrike: () => editor?.chain().focus().toggleStrike().run(),\n\t\t\t\ttoggleBulletList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBulletList().run(),\n\t\t\t\ttoggleOrderedList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleOrderedList().run(),\n\t\t\t\ttoggleBlockquote: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBlockquote().run(),\n\t\t\t\ttoggleCodeBlock: () => editor?.chain().focus().toggleCodeBlock().run(),\n\t\t\t\tsetTextAlign: (align) =>\n\t\t\t\t\teditor?.chain().focus().setTextAlign(align).run(),\n\t\t\t\tsetFontFamily: (font) =>\n\t\t\t\t\teditor?.chain().focus().setFontFamily(font).run(),\n\t\t\t\tsetFontSize: (size) => editor?.chain().focus().setFontSize(size).run(),\n\t\t\t\tsetColor: (color) => editor?.chain().focus().setColor(color).run(),\n\t\t\t\tsetHighlight: (color) =>\n\t\t\t\t\teditor?.chain().focus().toggleHighlight({ color }).run(),\n\t\t\t\tunsetColor: () => editor?.chain().focus().unsetColor().run(),\n\t\t\t\tunsetHighlight: () => editor?.chain().focus().unsetHighlight().run(),\n\t\t\t\tsetLink: (href, text) => {\n\t\t\t\t\tif (!editor) return;\n\t\t\t\t\tif (text !== undefined) {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.command(({ tr, state }) => {\n\t\t\t\t\t\t\t\tconst { from, to } = tr.selection;\n\t\t\t\t\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\t\t\t\t\tif (!linkMarkType) return false;\n\t\t\t\t\t\t\t\tconst linkNode = state.schema.text(text, [\n\t\t\t\t\t\t\t\t\tlinkMarkType.create({ href }),\n\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\tconst space = state.schema.text(' ');\n\t\t\t\t\t\t\t\ttr.replaceWith(from, to, [linkNode, space]);\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t} else {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t\t.insertContent(' ')\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tupdateLink: (href) =>\n\t\t\t\t\teditor\n\t\t\t\t\t\t?.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t.run(),\n\t\t\t\tremoveLink: () =>\n\t\t\t\t\teditor?.chain().focus().extendMarkRange('link').unsetLink().run(),\n\t\t\t\tinsertEmoji: (emoji) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(emoji).run(),\n\t\t\t\tinsertVariable: (variableName) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(`{{${variableName}}}`).run(),\n\t\t\t\tinsertHtml: (html) =>\n\t\t\t\t\teditor?.commands.insertContent(normalizeHtml(html)),\n\t\t\t\tundo: () => editor?.chain().focus().undo().run(),\n\t\t\t\tredo: () => editor?.chain().focus().redo().run(),\n\t\t\t\tcanUndo: () => editor?.can().undo() ?? false,\n\t\t\t\tcanRedo: () => editor?.can().redo() ?? false,\n\t\t\t\ttoggleSuperscript: () =>\n\t\t\t\t\teditor?.chain().focus().toggleSuperscript().run(),\n\t\t\t\ttoggleSubscript: () => editor?.chain().focus().toggleSubscript().run(),\n\t\t\t\tinsertImage: (src) => editor?.chain().focus().setImage({ src }).run(),\n\t\t\t},\n\t\t}),\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[editor],\n\t);\n\n\tif (!editor) return null;\n\n\treturn (\n\t\t<BikEditorShell\n\t\t\tminHeight={minHeight}\n\t\t\tmaxHeight={maxHeight}\n\t\t\ttightParagraphs={!features?.richPaste}\n\t\t\tstyle={style}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t<EditorContent editor={editor} />\n\t\t\t<LinkBubbleMenu editor={editor} renderLinkTooltip={link?.renderTooltip} />\n\t\t</BikEditorShell>\n\t);\n};\n\nexport const BikEditor = forwardRef<BikEditorRef, BikEditorProps>(\n\tBikEditorInner,\n);\nBikEditor.displayName = 'BikEditor';\n"],"names":["cssToString","style","k","v","c","BikEditorInner","props","ref","initialContent","sections","features","disabled","maxCharacters","shortcuts","sendShortcut","mentions","slashCommands","link","onPaste","onReady","onChange","onSend","onFocus","onBlur","onSelectionChange","minHeight","maxHeight","className","editorClassName","editorStyle","initialEditorContent","buildSectionedContent","normalizeHtml","s","pendingQueue","useRef","hasCalledOnReady","onReadyRef","onChangeRef","onSelectionChangeRef","prevFormatsRef","DEFAULT_FORMAT_STATE","onFocusRef","onBlurRef","onSendRef","agentMentionsRef","teamMentionsRef","slashCommandsRef","editor","useEditor","buildExtensions","snapshot","e","extractContent","next","extractActiveFormats","prev","enqueue","op","useEffect","useImperativeHandle","position","html","normalised","insertInlineHtml","agentIds","teamIds","node","from","to","pos","state","empty","linkMarkType","range","getMarkRange","sectionId","extractSectionContent","setSectionContentInEditor","endOfBody","targetPos","extractBodyContent","body","boundaryPos","findSectionEndPos","findSectionStartPos","align","font","size","color","href","text","tr","linkNode","space","emoji","variableName","src","jsxs","BikEditorShell","jsx","EditorContent","LinkBubbleMenu","BikEditor","forwardRef"],"mappings":"6ZAsCA,SAASA,GAAYC,EAAoC,CACxD,OAAO,OAAO,QAAQA,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,eAAc,OAAArD,EAAgB,EAC/BoD,EAAAA,IAACE,GAAAA,eAAA,CAAe,OAAAtD,EAAgB,kBAAmB/B,GAAM,aAAA,CAAe,CAAA,CAAA,CAAA,EAXtD,IAcrB,EAEasF,EAAYC,EAAAA,WACxBnG,EACD,EACAkG,EAAU,YAAc"}
|
|
1
|
+
{"version":3,"file":"BikEditor.js","sources":["../../../src/editor/BikEditor.tsx"],"sourcesContent":["'use client';\n\n/**\n * IMPLEMENTATION LAYER — TipTap-specific.\n * If the underlying editor is swapped, this file changes; BikEditor.types.ts and\n * src/editor/index.ts (the consumer contract) do NOT change.\n */\nimport { Editor, getMarkRange } from '@tiptap/core';\nimport { EditorContent, useEditor } from '@tiptap/react';\nimport React, {\n\tforwardRef,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n} from 'react';\nimport { BikEditorShell } from './BikEditor.styles';\nimport {\n\tBikEditorProps,\n\tBikEditorRef,\n\tDEFAULT_FORMAT_STATE,\n\tFormatState,\n} from './BikEditor.types';\nimport {\n\tbuildSectionedContent,\n\textractActiveFormats,\n\textractBodyContent,\n\textractContent,\n\textractSectionContent,\n\tfindSectionEndPos,\n\tfindSectionStartPos,\n\tinsertInlineHtml,\n\tnormalizeHtml,\n\tsetSectionContentInEditor,\n} from './BikEditor.utils';\nimport { buildExtensions } from './extensions/buildExtensions';\nimport { LinkBubbleMenu } from './floating/LinkBubbleMenu';\n\n/** Convert React.CSSProperties to an inline CSS string for editorProps.attributes. */\nfunction cssToString(style: React.CSSProperties): string {\n\treturn Object.entries(style)\n\t\t.map(\n\t\t\t([k, v]) => `${k.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`)}:${v}`,\n\t\t)\n\t\t.join(';');\n}\n\nconst BikEditorInner = (\n\tprops: BikEditorProps,\n\tref: React.Ref<BikEditorRef>,\n) => {\n\tconst {\n\t\tinitialContent,\n\t\tsections,\n\t\tfeatures,\n\t\tdisabled,\n\t\tmaxCharacters,\n\t\tshortcuts,\n\t\tsendShortcut,\n\t\tmentions,\n\t\tslashCommands,\n\t\tlink,\n\t\tonPaste,\n\t\tonReady,\n\t\tonChange,\n\t\tonSend,\n\t\tonFocus,\n\t\tonBlur,\n\t\tonSelectionChange,\n\t\tminHeight,\n\t\tmaxHeight,\n\t\tstyle,\n\t\tclassName,\n\t\teditorClassName,\n\t\teditorStyle,\n\t} = props;\n\n\tconst initialEditorContent = sections?.length\n\t\t? buildSectionedContent(\n\t\t\t\tnormalizeHtml(initialContent ?? ''),\n\t\t\t\tsections.map((s) => ({ ...s, content: normalizeHtml(s.content) })),\n\t\t )\n\t\t: normalizeHtml(initialContent ?? '');\n\n\t// ── Command queue ─────────────────────────────────────────────────────────\n\t// TipTap's useEditor initializes asynchronously; the editor instance is null\n\t// until the first commit. Any imperative method called before the editor is\n\t// ready is enqueued here and flushed automatically once it becomes non-null.\n\t// Consumers never need setTimeout or readiness guards.\n\tconst pendingQueue = useRef<Array<(e: Editor) => void>>([]);\n\tconst hasCalledOnReady = useRef(false);\n\t// Keep stable refs to all callbacks so useEditor receives the same function\n\t// identity on every render — prevents TipTap from re-registering event\n\t// handlers every time the parent re-renders with new inline function props.\n\tconst onReadyRef = useRef(onReady);\n\tonReadyRef.current = onReady;\n\tconst onChangeRef = useRef(onChange);\n\tonChangeRef.current = onChange;\n\tconst onSelectionChangeRef = useRef(onSelectionChange);\n\tonSelectionChangeRef.current = onSelectionChange;\n\tconst prevFormatsRef = useRef<FormatState>(DEFAULT_FORMAT_STATE);\n\tconst onFocusRef = useRef(onFocus);\n\tonFocusRef.current = onFocus;\n\tconst onBlurRef = useRef(onBlur);\n\tonBlurRef.current = onBlur;\n\tconst onSendRef = useRef(onSend);\n\tonSendRef.current = onSend;\n\tconst agentMentionsRef = useRef(mentions?.agents ?? []);\n\tagentMentionsRef.current = mentions?.agents ?? [];\n\tconst teamMentionsRef = useRef(mentions?.teams ?? []);\n\tteamMentionsRef.current = mentions?.teams ?? [];\n\tconst slashCommandsRef = useRef(slashCommands?.items ?? []);\n\tslashCommandsRef.current = slashCommands?.items ?? [];\n\n\tconst editor = useEditor({\n\t\textensions: buildExtensions({\n\t\t\tfeatures,\n\t\t\tplaceholder: props.placeholder,\n\t\t\tmaxCharacters,\n\t\t\thasSections: (sections?.length ?? 0) > 0,\n\t\t\tmentions: {\n\t\t\t\tagents: mentions ? agentMentionsRef : undefined,\n\t\t\t\tteams: mentions ? teamMentionsRef : undefined,\n\t\t\t},\n\t\t\tslashCommands: slashCommands ? slashCommandsRef : undefined,\n\t\t\tonPaste,\n\t\t\tonSend: onSend ? (snapshot) => onSendRef.current?.(snapshot) : undefined,\n\t\t\tsendShortcut,\n\t\t\tshortcuts,\n\t\t\tonMentionSelected: mentions?.onSelect,\n\t\t\tonSlashCommandSelected: slashCommands?.onSelect,\n\t\t\trenderMentionItem: mentions?.renderItem,\n\t\t\trenderMentionDropdown: mentions?.renderDropdown,\n\t\t\trenderSlashCommandItem: slashCommands?.renderItem,\n\t\t\trenderSlashCommandDropdown: slashCommands?.renderDropdown,\n\t\t}),\n\t\tcontent: initialEditorContent,\n\t\teditable: !disabled,\n\t\timmediatelyRender: false, // SSR-safe — NEVER remove this\n\t\teditorProps: {\n\t\t\tattributes: {\n\t\t\t\t...(editorClassName ? { class: editorClassName } : {}),\n\t\t\t\t...(editorStyle ? { style: cssToString(editorStyle) } : {}),\n\t\t\t},\n\t\t},\n\t\tonUpdate: ({ editor: e }) => {\n\t\t\tonChangeRef.current?.(extractContent(e));\n\t\t},\n\t\tonTransaction: ({ editor: e }) => {\n\t\t\tconst next = extractActiveFormats(e);\n\t\t\tconst prev = prevFormatsRef.current;\n\t\t\tconst changed =\n\t\t\t\tprev.bold !== next.bold ||\n\t\t\t\tprev.italic !== next.italic ||\n\t\t\t\tprev.underline !== next.underline ||\n\t\t\t\tprev.strike !== next.strike ||\n\t\t\t\tprev.bulletList !== next.bulletList ||\n\t\t\t\tprev.orderedList !== next.orderedList ||\n\t\t\t\tprev.blockquote !== next.blockquote ||\n\t\t\t\tprev.codeBlock !== next.codeBlock ||\n\t\t\t\tprev.superscript !== next.superscript ||\n\t\t\t\tprev.subscript !== next.subscript ||\n\t\t\t\tprev.textAlign !== next.textAlign ||\n\t\t\t\tprev.fontFamily !== next.fontFamily ||\n\t\t\t\tprev.fontSize !== next.fontSize ||\n\t\t\t\tprev.color !== next.color ||\n\t\t\t\tprev.highlight !== next.highlight ||\n\t\t\t\tprev.link?.href !== next.link?.href;\n\t\t\tif (changed) {\n\t\t\t\tprevFormatsRef.current = next;\n\t\t\t\tonSelectionChangeRef.current?.(next);\n\t\t\t}\n\t\t},\n\t\tonFocus: () => onFocusRef.current?.(),\n\t\tonBlur: () => onBlurRef.current?.(),\n\t});\n\n\t// ── enqueue ───────────────────────────────────────────────────────────────\n\t// Run immediately if the editor is ready; otherwise defer to the queue.\n\t// Closures passed to enqueue MUST capture all parameters explicitly —\n\t// they must NOT close over `editor` (which would be null at enqueue time).\n\tfunction enqueue(op: (e: Editor) => void): void {\n\t\tif (editor) {\n\t\t\top(editor);\n\t\t} else {\n\t\t\tpendingQueue.current.push(op);\n\t\t}\n\t}\n\n\t// Flush the pending queue and fire onReady when editor transitions null → ready.\n\tuseEffect(() => {\n\t\tif (!editor) return;\n\t\tif (pendingQueue.current.length > 0) {\n\t\t\tconst queue = pendingQueue.current.splice(0);\n\t\t\tqueue.forEach((op) => op(editor));\n\t\t}\n\t\tif (!hasCalledOnReady.current) {\n\t\t\thasCalledOnReady.current = true;\n\t\t\tonReadyRef.current?.();\n\t\t}\n\t}, [editor]);\n\n\tuseImperativeHandle(\n\t\tref,\n\t\t() => ({\n\t\t\t// ── Focus ────────────────────────────────────────────────────────\n\t\t\tfocus: (position) => enqueue((e) => e.commands.focus(position)),\n\t\t\tblur: () => enqueue((e) => e.commands.blur()),\n\n\t\t\t// ── Content ──────────────────────────────────────────────────────\n\t\t\tclearContent: () => enqueue((e) => e.commands.clearContent(true)),\n\t\t\tsetContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.setContent(normalised, { emitUpdate: true }));\n\t\t\t},\n\t\t\tinsertContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContent(normalised));\n\t\t\t},\n\t\t\tinsertInlineContent: (html) => {\n\t\t\t\tenqueue((e) => insertInlineHtml(e, html));\n\t\t\t},\n\t\t\tinsertAtStart: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(1, normalised));\n\t\t\t},\n\t\t\tinsertBlock: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\tappendInline: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// doc.content.size is after the last </p> (block boundary).\n\t\t\t\t// Subtract 1 to land inside the last paragraph so text appends\n\t\t\t\t// inline rather than being wrapped in a new paragraph each call.\n\t\t\t\tenqueue((e) =>\n\t\t\t\t\te.commands.insertContentAt(e.state.doc.content.size - 1, normalised),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Backwards-compatible aliases\n\t\t\tinsertAtEnd(html) {\n\t\t\t\tthis.insertBlock(html);\n\t\t\t},\n\t\t\tappendContent(html) {\n\t\t\t\tthis.appendInline(html);\n\t\t\t},\n\t\t\tgetContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tgetJSON: () => editor?.getJSON() ?? null,\n\t\t\tgetMentions: () => {\n\t\t\t\tconst agentIds = new Set<string>();\n\t\t\t\tconst teamIds = new Set<string>();\n\t\t\t\tif (!editor) return { agentIds: [], teamIds: [] };\n\t\t\t\teditor.state.doc.descendants((node) => {\n\t\t\t\t\tif (node.type.name === 'mentionAgent' && node.attrs['id'] != null) {\n\t\t\t\t\t\tagentIds.add(String(node.attrs['id']));\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tnode.type.name === 'mentionTeam' &&\n\t\t\t\t\t\tnode.attrs['id'] != null\n\t\t\t\t\t) {\n\t\t\t\t\t\tteamIds.add(String(node.attrs['id']));\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn { agentIds: Array.from(agentIds), teamIds: Array.from(teamIds) };\n\t\t\t},\n\n\t\t\t// ── Selection ────────────────────────────────────────────────────\n\t\t\tgetCursorPosition: () => {\n\t\t\t\tif (!editor) return { from: 0, to: 0 };\n\t\t\t\tconst { from, to } = editor.state.selection;\n\t\t\t\treturn { from, to };\n\t\t\t},\n\t\t\tinsertAtPosition: (pos, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => e.commands.insertContentAt(pos, normalised));\n\t\t\t},\n\t\t\tgetSelectedText: () => {\n\t\t\t\tif (!editor) return '';\n\t\t\t\tconst { state } = editor;\n\t\t\t\tconst { from, to, empty } = state.selection;\n\t\t\t\tif (!empty) {\n\t\t\t\t\treturn state.doc.textBetween(from, to, ' ');\n\t\t\t\t}\n\t\t\t\t// When the cursor is inside a link with nothing selected, return the\n\t\t\t\t// full link text — useful for pre-filling a link modal's text field.\n\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\tif (linkMarkType) {\n\t\t\t\t\tconst range = getMarkRange(state.doc.resolve(from), linkMarkType);\n\t\t\t\t\tif (range) {\n\t\t\t\t\t\treturn state.doc.textBetween(range.from, range.to, ' ');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn '';\n\t\t\t},\n\n\t\t\t// ── Character count ───────────────────────────────────────────────\n\t\t\tgetCharacterCount: () => ({\n\t\t\t\tcount:\n\t\t\t\t\teditor?.storage.characterCount?.characters?.() ??\n\t\t\t\t\teditor?.getText().length ??\n\t\t\t\t\t0,\n\t\t\t\tlimit: maxCharacters ?? null,\n\t\t\t}),\n\n\t\t\t// ── Sections ─────────────────────────────────────────────────────\n\t\t\tgetSectionContent: (sectionId) =>\n\t\t\t\teditor\n\t\t\t\t\t? extractSectionContent(editor, sectionId)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\n\t\t\tsetSectionContent: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, normalised));\n\t\t\t},\n\n\t\t\tfocusSection: (sectionId) => {\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tif (sectionId === 'body') {\n\t\t\t\t\t\tlet endOfBody = e.state.doc.content.size - 1;\n\t\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\t\tendOfBody === e.state.doc.content.size - 1\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tendOfBody = pos - 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn endOfBody === e.state.doc.content.size - 1;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (endOfBody < 1) endOfBody = 1;\n\t\t\t\t\t\te.chain().focus().setTextSelection(endOfBody).run();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet targetPos = -1;\n\t\t\t\t\te.state.doc.descendants((node, pos) => {\n\t\t\t\t\t\tif (targetPos !== -1) return false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnode.type.name === 'sectionDivider' &&\n\t\t\t\t\t\t\tnode.attrs['sectionId'] === sectionId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// pos + nodeSize lands right after the divider;\n\t\t\t\t\t\t\t// +1 more puts us inside the first paragraph of that section.\n\t\t\t\t\t\t\ttargetPos = pos + node.nodeSize + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (targetPos !== -1) {\n\t\t\t\t\t\te.chain().focus().setTextSelection(targetPos).run();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\n\t\t\tclearSection: (sectionId) => {\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, sectionId, '<p></p>'));\n\t\t\t},\n\n\t\t\t// ── Convenience body shorthands ───────────────────────────────────\n\t\t\tgetBodyContent: () =>\n\t\t\t\teditor\n\t\t\t\t\t? extractBodyContent(editor)\n\t\t\t\t\t: { html: '', text: '', isEmpty: true, characterCount: 0 },\n\t\t\tsetBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => setSectionContentInEditor(e, 'body', normalised));\n\t\t\t},\n\t\t\tsetBodyAndSections: (body, sections) => {\n\t\t\t\tconst html = buildSectionedContent(\n\t\t\t\t\tnormalizeHtml(body),\n\t\t\t\t\tsections.map((s) => ({\n\t\t\t\t\t\tid: s.id,\n\t\t\t\t\t\tcontent: normalizeHtml(s.content),\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t\tenqueue((e) => e.commands.setContent(html, { emitUpdate: true }));\n\t\t\t},\n\t\t\tappendBodyContent: (html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\t// findSectionEndPos returns the position of the first divider (or\n\t\t\t\t// doc.content.size), which is the block boundary after the last </p>.\n\t\t\t\t// Subtract 1 to stay inside the last paragraph so successive calls\n\t\t\t\t// append inline text rather than creating a new paragraph each time.\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst boundaryPos = findSectionEndPos(e, 'body');\n\t\t\t\t\te.commands.insertContentAt(boundaryPos - 1, normalised, {\n\t\t\t\t\t\tparseOptions: { preserveWhitespace: true },\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionStart: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionStartPos(e, sectionId);\n\t\t\t\t\tif (pos !== -1)\n\t\t\t\t\t\te.commands.insertContentAt(pos, normalised, {\n\t\t\t\t\t\t\tparseOptions: { preserveWhitespace: true },\n\t\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tinsertAtSectionEnd: (sectionId, html) => {\n\t\t\t\tconst normalised = normalizeHtml(html);\n\t\t\t\tenqueue((e) => {\n\t\t\t\t\tconst pos = findSectionEndPos(e, sectionId);\n\t\t\t\t\te.commands.insertContentAt(pos, normalised, {\n\t\t\t\t\t\tparseOptions: { preserveWhitespace: true },\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\t// ── Formats & actions ─────────────────────────────────────────────\n\t\t\tgetActiveFormats: () =>\n\t\t\t\teditor ? extractActiveFormats(editor) : DEFAULT_FORMAT_STATE,\n\t\t\tactions: {\n\t\t\t\ttoggleBold: () => editor?.chain().focus().toggleBold().run(),\n\t\t\t\ttoggleItalic: () => editor?.chain().focus().toggleItalic().run(),\n\t\t\t\ttoggleUnderline: () => editor?.chain().focus().toggleUnderline().run(),\n\t\t\t\ttoggleStrike: () => editor?.chain().focus().toggleStrike().run(),\n\t\t\t\ttoggleBulletList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBulletList().run(),\n\t\t\t\ttoggleOrderedList: () =>\n\t\t\t\t\teditor?.chain().focus().toggleOrderedList().run(),\n\t\t\t\ttoggleBlockquote: () =>\n\t\t\t\t\teditor?.chain().focus().toggleBlockquote().run(),\n\t\t\t\ttoggleCodeBlock: () => editor?.chain().focus().toggleCodeBlock().run(),\n\t\t\t\tsetTextAlign: (align) =>\n\t\t\t\t\teditor?.chain().focus().setTextAlign(align).run(),\n\t\t\t\tsetFontFamily: (font) =>\n\t\t\t\t\teditor?.chain().focus().setFontFamily(font).run(),\n\t\t\t\tsetFontSize: (size) => editor?.chain().focus().setFontSize(size).run(),\n\t\t\t\tsetColor: (color) => editor?.chain().focus().setColor(color).run(),\n\t\t\t\tsetHighlight: (color) =>\n\t\t\t\t\teditor?.chain().focus().toggleHighlight({ color }).run(),\n\t\t\t\tunsetColor: () => editor?.chain().focus().unsetColor().run(),\n\t\t\t\tunsetHighlight: () => editor?.chain().focus().unsetHighlight().run(),\n\t\t\t\tsetLink: (href, text) => {\n\t\t\t\t\tif (!editor) return;\n\t\t\t\t\tif (text !== undefined) {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.command(({ tr, state }) => {\n\t\t\t\t\t\t\t\tconst { from, to } = tr.selection;\n\t\t\t\t\t\t\t\tconst linkMarkType = state.schema.marks['link'];\n\t\t\t\t\t\t\t\tif (!linkMarkType) return false;\n\t\t\t\t\t\t\t\tconst linkNode = state.schema.text(text, [\n\t\t\t\t\t\t\t\t\tlinkMarkType.create({ href }),\n\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\tconst space = state.schema.text(' ');\n\t\t\t\t\t\t\t\ttr.replaceWith(from, to, [linkNode, space]);\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t} else {\n\t\t\t\t\t\teditor\n\t\t\t\t\t\t\t.chain()\n\t\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t\t.insertContent(' ')\n\t\t\t\t\t\t\t.run();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tupdateLink: (href) =>\n\t\t\t\t\teditor\n\t\t\t\t\t\t?.chain()\n\t\t\t\t\t\t.focus()\n\t\t\t\t\t\t.extendMarkRange('link')\n\t\t\t\t\t\t.setLink({ href })\n\t\t\t\t\t\t.run(),\n\t\t\t\tremoveLink: () =>\n\t\t\t\t\teditor?.chain().focus().extendMarkRange('link').unsetLink().run(),\n\t\t\t\tinsertEmoji: (emoji) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(emoji).run(),\n\t\t\t\tinsertVariable: (variableName) =>\n\t\t\t\t\teditor?.chain().focus().insertContent(`{{${variableName}}}`).run(),\n\t\t\t\tinsertHtml: (html) =>\n\t\t\t\t\teditor?.commands.insertContent(normalizeHtml(html)),\n\t\t\t\tundo: () => editor?.chain().focus().undo().run(),\n\t\t\t\tredo: () => editor?.chain().focus().redo().run(),\n\t\t\t\tcanUndo: () => editor?.can().undo() ?? false,\n\t\t\t\tcanRedo: () => editor?.can().redo() ?? false,\n\t\t\t\ttoggleSuperscript: () =>\n\t\t\t\t\teditor?.chain().focus().toggleSuperscript().run(),\n\t\t\t\ttoggleSubscript: () => editor?.chain().focus().toggleSubscript().run(),\n\t\t\t\tinsertImage: (src) => editor?.chain().focus().setImage({ src }).run(),\n\t\t\t},\n\t\t}),\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t[editor],\n\t);\n\n\tif (!editor) return null;\n\n\treturn (\n\t\t<BikEditorShell\n\t\t\tminHeight={minHeight}\n\t\t\tmaxHeight={maxHeight}\n\t\t\ttightParagraphs={!features?.richPaste}\n\t\t\tstyle={style}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t<EditorContent editor={editor} />\n\t\t\t<LinkBubbleMenu editor={editor} renderLinkTooltip={link?.renderTooltip} />\n\t\t</BikEditorShell>\n\t);\n};\n\nexport const BikEditor = forwardRef<BikEditorRef, BikEditorProps>(\n\tBikEditorInner,\n);\nBikEditor.displayName = 'BikEditor';\n"],"names":["cssToString","style","k","v","c","BikEditorInner","props","ref","initialContent","sections","features","disabled","maxCharacters","shortcuts","sendShortcut","mentions","slashCommands","link","onPaste","onReady","onChange","onSend","onFocus","onBlur","onSelectionChange","minHeight","maxHeight","className","editorClassName","editorStyle","initialEditorContent","buildSectionedContent","normalizeHtml","s","pendingQueue","useRef","hasCalledOnReady","onReadyRef","onChangeRef","onSelectionChangeRef","prevFormatsRef","DEFAULT_FORMAT_STATE","onFocusRef","onBlurRef","onSendRef","agentMentionsRef","teamMentionsRef","slashCommandsRef","editor","useEditor","buildExtensions","snapshot","extractContent","next","extractActiveFormats","prev","enqueue","op","useEffect","useImperativeHandle","position","e","html","normalised","insertInlineHtml","agentIds","teamIds","node","from","to","pos","state","empty","linkMarkType","range","getMarkRange","sectionId","extractSectionContent","setSectionContentInEditor","endOfBody","targetPos","extractBodyContent","body","boundaryPos","findSectionEndPos","findSectionStartPos","align","font","size","color","href","text","tr","linkNode","space","emoji","variableName","src","jsxs","BikEditorShell","jsx","EditorContent","LinkBubbleMenu","BikEditor","forwardRef"],"mappings":"6ZAsCA,SAASA,GAAYC,EAAoC,CACxD,OAAO,OAAO,QAAQA,CAAK,EACzB,IACA,CAAC,CAACC,EAAGC,CAAC,IAAM,GAAGD,EAAE,QAAQ,WAAaE,GAAM,IAAIA,EAAE,YAAA,CAAa,EAAE,CAAC,IAAID,CAAC,EAAA,EAEvE,KAAK,GAAG,CACX,CAEA,MAAME,GAAiB,CACtBC,EACAC,IACI,CACJ,KAAM,CACL,eAAAC,EACA,SAAAC,EACA,SAAAC,EACA,SAAAC,EACA,cAAAC,EACA,UAAAC,EACA,aAAAC,EACA,SAAAC,EACA,cAAAC,EACA,KAAAC,EACA,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,OAAAC,EACA,QAAAC,EACA,OAAAC,EACA,kBAAAC,EACA,UAAAC,EACA,UAAAC,EACA,MAAAzB,EACA,UAAA0B,EACA,gBAAAC,EACA,YAAAC,CAAA,EACGvB,EAEEwB,EAAuBrB,GAAU,OACpCsB,EAAAA,sBACAC,EAAAA,cAAcxB,GAAkB,EAAE,EAClCC,EAAS,IAAKwB,IAAO,CAAE,GAAGA,EAAG,QAASD,gBAAcC,EAAE,OAAO,GAAI,CAAA,EAEjED,EAAAA,cAAcxB,GAAkB,EAAE,EAO/B0B,EAAeC,EAAAA,OAAmC,EAAE,EACpDC,EAAmBD,EAAAA,OAAO,EAAK,EAI/BE,EAA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