{"version":3,"file":"render.mjs","sources":["src/common.mjs","src/render.mjs"],"sourcesContent":["// Provides shared functionality\n/**\n * Common Utilities Class:\n * Called by both render.mjs and compile.mjs\n */\nexport default class {\n\tconstructor(contentClient, noPermissionToView, compiled) {\n\t\tthis.contentClient = contentClient\n\t\tthis.noPermissionToView =\n\t\t\tnoPermissionToView || 'You do not have permission to view this asset'\n\t\tif (this.contentClient.hasOwnProperty('getLibs')) {\n\t\t\tthis.libs = this.contentClient.getLibs() || {}\n\t\t\tthis.marked = this.libs.marked || (!compiled && window.marked)\n\t\t}\n\t}\n\t// Helper method to make an additional Content REST API call to retrieve all items referenced in the data by their ID.\n\tgetRefItems(ids) {\n\t\t// If no items are requested, just return a resolved Promise.\n\t\t// Calling getItems() with no ‘ids’ returns all items.\n\t\tif (ids.length === 0) {\n\t\t\treturn Promise.resolve({})\n\t\t} else {\n\t\t\treturn this.contentClient.getItems({\n\t\t\t\tids: ids,\n\t\t\t})\n\t\t}\n\t}\n\t//\n\t// Helper Methods to handle specific field types\n\t//\n\tfindReferenceFieldIds(referencedItems, fields) {\n\t\tconst referencedIds = []\n\t\treferencedItems.forEach((referencedItem) => {\n\t\t\tif (fields[referencedItem]) {\n\t\t\t\t// handle multiple or single value content fields\n\t\t\t\t;\n\t\t\t\t(Array.isArray(fields[referencedItem]) ?\n\t\t\t\t\tfields[referencedItem] :\n\t\t\t\t\t[fields[referencedItem]]\n\t\t\t\t).forEach((entry) => {\n\t\t\t\t\tif (entry) {\n\t\t\t\t\t\t// if asset is accessible, add it\n\t\t\t\t\t\tif (!entry.reference || entry.reference.isAccessible) {\n\t\t\t\t\t\t\treferencedIds.push(entry.id)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// asset is not accessible, store the message against the entry\n\t\t\t\t\t\t\tentry.referenceInaccessible = this.noPermissionToView\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t})\n\n\t\treturn referencedIds\n\t}\n\n\tupdateDigitalAssetURLs(digitalAssetFields, fields) {\n\t\tdigitalAssetFields.forEach((digitalAssetField) => {\n\t\t\tif (fields[digitalAssetField]) {\n\t\t\t\t// handle multiple or single value content fields\n\t\t\t\t;\n\t\t\t\t(Array.isArray(fields[digitalAssetField]) ?\n\t\t\t\t\tfields[digitalAssetField] :\n\t\t\t\t\t[fields[digitalAssetField]]\n\t\t\t\t).forEach((entry) => {\n\t\t\t\t\tif (entry) {\n\t\t\t\t\t\tif (!entry.reference || entry.reference.isAccessible) {\n\t\t\t\t\t\t\tif (entry.type === 'Video' || entry.type === 'File') {\n\t\t\t\t\t\t\t\tentry.showName = true\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tentry.url = this.contentClient.getRenditionURL({\n\t\t\t\t\t\t\t\t\tid: entry.id,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// asset is not accessible, store the message against the entry\n\t\t\t\t\t\t\tentry.referenceInaccessible = this.noPermissionToView\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t})\n\t}\n\n\taddReferencedItems(referencedItems, results, fields) {\n\t\t;\n\t\t((results && results.items) || []).forEach((item) => {\n\t\t\treferencedItems.forEach((referencedItem) => {\n\t\t\t\t;\n\t\t\t\t(Array.isArray(fields[referencedItem]) ?\n\t\t\t\t\tfields[referencedItem] :\n\t\t\t\t\t[fields[referencedItem]]\n\t\t\t\t).forEach((entry) => {\n\t\t\t\t\t// Retrieve the reference item from the query result.\n\t\t\t\t\tif (entry && entry.id === item.id) {\n\t\t\t\t\t\tentry.contentItem = item\n\t\t\t\t\t\t// add in assetURLs for any digital asset references in the referenced item\n\t\t\t\t\t\tconst digitalAssetFields = Object.keys(item.fields).filter((key) => {\n\t\t\t\t\t\t\tconst field = item.fields[key]\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\tfield &&\n\t\t\t\t\t\t\t\ttypeof field === 'object' &&\n\t\t\t\t\t\t\t\tfield.typeCategory === 'DigitalAssetType'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t})\n\t\t\t\t\t\tthis.updateDigitalAssetURLs(digitalAssetFields, item.fields)\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t})\n\t\t})\n\t}\n\n\t//handles the theme change that occurs with the theme toggle in custom settings\n\t//If the toggle is activated, the layout will be in dark mode\n\t//If the toggle is not activated, the layout will be in light mode\n\tupdateColorTheme(customSettings, content) {\n\t\tif (customSettings.bTheme === true) {\n\t\t\tcontent.fields.theme = 'dark-mode'\n\t\t} else {\n\t\t\tcontent.fields.theme = 'light-mode'\n\t\t}\n\t}\n\n\t//handles toggle between quicklinks and nav list styles\n\tupdateListType(customSettings, content) {\n\t\tif (customSettings.bType === true) {\n\t\t\tcontent.fields.listType = 'navList'\n\t\t} else {\n\t\t\tcontent.fields.listType = 'quicklinks'\n\t\t}\n\t}\n\n\t/**\n\t * Expand custom macros in the returned HTML\n\t * @param {string} strInput\n\t * @returns {string} HTML string with macros expanded\n\t */\n\texpandMacros = (strInput) => {\n\t\t// replace \"[[page-221]]\" with \"[!--$SCS_PAGE--]221[/!--$SCS_PAGE--]\"\n\t\tlet strOutput = strInput.replace(/\\[\\[page-(\\d+)\\]\\]/g, '[!--$SCS_PAGE--]$1[/!--$SCS_PAGE--]')\n\t\t// replace \"[[asset-221]]\" with the view rendition url for asset 221\n\t\t// replace \"[[asset-221,true]]\" with the download rendition url for asset 221\n\t\t// replace \"[[asset-221,false]]\" with the view rendition url for asset 221\n\t\t\n\t\tconst replaceAssetUrls = (content) => {\n\t\t\tconst regex = /\\[\\[asset-(.*?)(,true|,false)?\\]\\]/g;\n\t\t\treturn content.replace(regex, (match, assetId, downloadFlag) => {\n\t\t\t\tconst shouldDownload = (downloadFlag === \",true\");\n\t\t\t\tconst assetURL = this.contentClient.getRenditionURL({ id: assetId, download: shouldDownload })\n\t\t\t\t// console.log({assetURL})\n\t\t\t\treturn assetURL;\n\t\t\t});\n\t\t};\n\n\t\tstrOutput = replaceAssetUrls(strOutput)\n\n\t\tstrOutput = this.contentClient.expandMacros(strOutput)\n\t\t// console.log(153, {strOutput})\n\t\treturn strOutput\n\t}\n}\n","/* globals Mustache */\nimport CommonUtils from './common.mjs'\n\nexport default class {\n\t// class variables\n\tcontentVersion = '>=1.0.0 <2.0.0'\n\n\t// Content Layout constructor\n\tconstructor(params) {\n\t\t// store passed in values\n\t\tthis.contentItemData = params.contentItemData || {}\n\t\tthis.scsData = params.scsData\n\t\tthis.contentClient = params.contentClient\n\t\tthis.libs = this.contentClient.getLibs() || {}\n\t\t// store path to the \"assets\" folder\n\t\tthis.assetsFolder = import.meta.url.replace('/render.mjs', '')\n\n\t\t// access resources\n\t\tthis.Mustache = params.Mustache || this.libs.Mustache || window.Mustache || Mustache\n\t}\n\n\t// Main rendering function:\n\t// - Updates the data to handle any required additional requests and support granular permissions\n\t// - Expand the Mustache template with the updated data\n\t// - Appends the expanded template HTML to the parentObj DOM element\n\trender(parentObj) {\n\t\tconst contentClient = this.contentClient\n\t\tconst noPermissionToViewMsg = 'You do not have permission to view this asset'\n\t\tconst commonUtils = new CommonUtils(contentClient, noPermissionToViewMsg)\n\n\t\tlet contentType\n\t\tlet customSettings\n\t\tlet secureContent = false\n\n\t\t// extract the content that will be used as the model\n\t\tthis.content = Object.assign({}, this.contentItemData)\n\n\t\t// If used with CECS Sites, Sites will pass in context information via the scsData property.\n\t\tif (this.scsData) {\n\t\t\tthis.content = Object.assign(this.content, {\n\t\t\t\tscsData: this.scsData,\n\t\t\t})\n\t\t\tcontentType = this.content.scsData.showPublishedContent === true ? 'published' : 'draft'\n\t\t\tcustomSettings = this.content.scsData.customSettingsData || {}\n\t\t}\n\n\t\t//\n\t\t// Handle fields specific to this content type.\n\t\t//\n\n\t\t// If displaying detail items, get the IDs of any referenced assets\n\t\t// we will do an additional query to retrieve these so we can render them as well.\n\t\tconst referredFields = ['links']\n\t\tconst referredIds = commonUtils.findReferenceFieldIds(referredFields, this.content.fields)\n\n\t\t//update fields with settings data for theme and style\n\t\tcommonUtils.updateColorTheme(customSettings, this.content)\n\t\tcommonUtils.updateListType(customSettings, this.content)\n\n\t\t//\n\t\t// Fetch any referenced items and resources used to render the content layout\n\t\t//\n\t\tPromise.all([\n\t\t\tcommonUtils.getRefItems(referredIds),\n\t\t\tcontentClient.importText(this.assetsFolder + '/layout.html'),\n\t\t\tcontentClient.importCSS(this.assetsFolder + '/styles/design.css'),\n\t\t]).then((resources) => {\n\t\t\tconst results = resources[0]\n\n\t\t\t// Store the retrieved referenced items in the model used by the template.\n\t\t\tcommonUtils.addReferencedItems(referredFields, results, this.content.fields)\n\n\t\t\t// apply the model to the template\n\t\t\ttry {\n\t\t\t\t// Use Mustache to expand the HTML template with the data.\n\t\t\t\tconst template = this.Mustache.render(resources[1], this.content)\n\t\t\t\tconst templateHtml = commonUtils.expandMacros(template)\n\t\t\t\tconst componentHtml = commonUtils.expandMacros(templateHtml)\n\n\n\n\t\t\t\t// Insert the expanded template into the passed in container.\n\t\t\t\tif (template) {\n\t\t\t\t\tparentObj.insertAdjacentHTML('beforeend', componentHtml)\n\t\t\t\t\tdocument.querySelector('.mobile-title')?.addEventListener('click', e => e.target.parentElement.classList.toggle('active'));\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(e.stack)\n\t\t\t}\n\t\t})\n\t}\n\n\thydrate(parentObj) {\n\t\ttry {\n\t\t\tparentObj.querySelector('.mobile-title').addEventListener('click', e => e.target.parentElement.classList.toggle('active'));\n\t\t} catch (e) {\n\t\t\tconsole.error(e.stack)\n\t\t}\n\t}\n}\n"],"names":["constructor","contentClient","noPermissionToView","compiled","strInput","strOutput","replace","content","match","assetId","downloadFlag","shouldDownload","this","getRenditionURL","id","download","replaceAssetUrls","expandMacros","hasOwnProperty","libs","getLibs","marked","window","getRefItems","ids","length","Promise","resolve","getItems","findReferenceFieldIds","referencedItems","fields","referencedIds","forEach","referencedItem","Array","isArray","entry","reference","isAccessible","push","referenceInaccessible","updateDigitalAssetURLs","digitalAssetFields","digitalAssetField","type","showName","url","addReferencedItems","results","items","item","contentItem","Object","keys","filter","key","field","typeCategory","updateColorTheme","customSettings","bTheme","theme","updateListType","bType","listType","render","params","_defineProperty","contentItemData","scsData","assetsFolder","import","meta","Mustache","parentObj","commonUtils","CommonUtils","assign","showPublishedContent","customSettingsData","referredFields","all","referredIds","importText","importCSS","then","resources","template","templateHtml","componentHtml","insertAdjacentHTML","document","querySelector","addEventListener","e","target","parentElement","classList","toggle","console","error","stack","hydrate"],"mappings":"wHAKe,QACdA,YAAYC,EAAeC,EAAoBC,GAmI/BC,EAAAA,KAAAA,gBAAAA,IAEf,IAAIC,EAAYD,EAASE,QAAQ,sBAAuB,uCAmBxD,OAJAD,EAV0BE,MAEVD,QADD,uCACgB,CAACE,EAAOC,EAASC,KAC9C,MAAoBC,EAAqB,UAAjBD,EAGxB,OAFiBE,KAAKX,cAAcY,gBAAgB,CAAEC,GAAIL,EAASM,SAAUJ,GAE7E,IAIUK,CAAiBX,GAE7BA,EAAYO,KAAKX,cAAcgB,aAAaZ,GAErCA,CAAP,IAvJAO,KAAKX,cAAgBA,EACrBW,KAAKV,mBACJA,GAAsB,gDACnBU,KAAKX,cAAciB,eAAe,aACrCN,KAAKO,KAAOP,KAAKX,cAAcmB,WAAa,CAAA,EAC5CR,KAAKS,OAAST,KAAKO,KAAKE,SAAYlB,GAAYmB,OAAOD,OAExD,CAEDE,YAAYC,GAGX,OAAmB,IAAfA,EAAIC,OACAC,QAAQC,QAAQ,CAAA,GAEhBf,KAAKX,cAAc2B,SAAS,CAClCJ,IAAKA,GAGP,CAIDK,sBAAsBC,EAAiBC,GACtC,MAAMC,EAAgB,GAsBtB,OArBAF,EAAgBG,SAASC,IACpBH,EAAOG,KAGTC,MAAMC,QAAQL,EAAOG,IACrBH,EAAOG,GACP,CAACH,EAAOG,KACPD,SAASI,IACNA,KAEEA,EAA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