{"version":3,"file":"preview_controller-Bhfjqknz.js","sources":["../../../app/javascript/controllers/campaign/preview_controller.js"],"sourcesContent":["import ApplicationController from '../application_controller'\nimport { useURLValidations } from \"../mixins/useURLValidations\"\nimport {Piece} from \"@/controllers/compose/models/piece\";\n\nexport default class extends ApplicationController {\n static values = {\n content: String,\n smsCount: Number,\n url: String,\n }\n\n static targets = ['paragraphs']\n connect() {\n useURLValidations(this)\n super.connect()\n }\n\n updatePreview({ detail }) {\n this.paragraphsTarget.innerHTML = ''\n\n if(!detail.string) {\n this.paragraphsTarget.innerHTML = this.translations.campaign.broadcasts.new.fields.body.placeholder\n return\n }\n\n const tempDiv = document.createElement('div')\n tempDiv.innerHTML = detail.html\n\n tempDiv.querySelectorAll('figure').forEach(figure => {\n const { link, id } = JSON.parse(figure.dataset.trixAttachment)\n figure.replaceWith(this.constructLinkElement({ link, url: detail.links[id].url }))\n })\n\n this.paragraphsTarget.innerHTML = tempDiv.innerHTML\n }\n\n constructLinkElement({ link, url}) {\n const linkElement = document.createElement('a')\n this.addClass(linkElement, 'link-primary')\n\n linkElement.innerText = link\n linkElement.href = url\n linkElement.target = '_blank'\n\n return linkElement\n }\n}\n"],"names":["CampaignPreviewController","ApplicationController","useURLValidations","detail","tempDiv","figure","link","id","url","linkElement","__publicField"],"mappings":"sQAIe,MAAKA,UAASC,CAAsB,CAQjD,SAAU,CACRC,EAAkB,IAAI,EACtB,MAAM,QAAO,CACjB,CAEE,cAAc,CAAE,OAAAC,GAAU,CAGxB,GAFA,KAAK,iBAAiB,UAAY,GAE/B,CAACA,EAAO,OAAQ,CACjB,KAAK,iBAAiB,UAAY,KAAK,aAAa,SAAS,WAAW,IAAI,OAAO,KAAK,YACxF,MACN,CAEI,MAAMC,EAAU,SAAS,cAAc,KAAK,EAC5CA,EAAQ,UAAYD,EAAO,KAE3BC,EAAQ,iBAAiB,QAAQ,EAAE,QAAQC,GAAU,CACnD,KAAM,CAAE,KAAAC,EAAM,GAAAC,CAAI,EAAG,KAAK,MAAMF,EAAO,QAAQ,cAAc,EAC7DA,EAAO,YAAY,KAAK,qBAAqB,CAAE,KAAAC,EAAM,IAAKH,EAAO,MAAMI,CAAE,EAAE,GAAG,CAAE,CAAC,CAClF,CAAA,EAED,KAAK,iBAAiB,UAAYH,EAAQ,SAC9C,CAEE,qBAAqB,CAAE,KAAAE,EAAM,IAAAE,CAAG,EAAG,CACjC,MAAMC,EAAc,SAAS,cAAc,GAAG,EAC9C,YAAK,SAASA,EAAa,cAAc,EAEzCA,EAAY,UAAYH,EACxBG,EAAY,KAAOD,EACnBC,EAAY,OAAS,SAEdA,CACX,CACA,CAzCEC,EADkBV,EACX,SAAS,CACd,QAAS,OACT,SAAU,OACV,IAAK,MACT,GAEEU,EAPkBV,EAOX,UAAU,CAAC,YAAY"}