{"version":3,"file":"render.mjs","sources":["src/render.mjs","src/common.mjs"],"sourcesContent":["// Import shared code\nimport CommonUtils from './common.mjs';\n\n// The Custom Component class will be the \"default\" export from the module\nexport default class {\n\tconstructor(args) {\n\t\t// store the args\n\t\tthis.mode = args.viewMode;\n\t\tthis.id = args.id;\n\n\t\t// store the path to the /assets folder\n\t\tthis.assetsPath = import.meta.url.replace('/render.mjs', '');\n\n\t\t// get the OCM environment resources \n\t\tthis.sitesSDK = args.SitesSDK;\n\t\tthis.Mustache = SCSRenderAPI.getMustache();\n\n\t\t// add in the event listeners\n\t\tthis.addEventListeners();\n\t}\n\n\t/**\n\t * add in the listeners for the triggers/actions and whenever the settings values change\n\t * in this case, we want to re-render the component on the screen\n\t */\n\taddEventListeners() {\n\t\t// listen for settings update\n\t\tthis.sitesSDK.subscribe(this.sitesSDK.MESSAGE_TYPES.SETTINGS_UPDATED, (props) => {\n\t\t\tif (props.property === 'customSettingsData') {\n\t\t\t\tthis.renderComponent({\n\t\t\t\t\tcustomSettingsData: props.value\n\t\t\t\t})\n\t\t\t} else if (props.property === 'componentLayout') {\n\t\t\t\tthis.renderComponent({\n\t\t\t\t\tcomponentLayout: props.value\n\t\t\t\t})\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Insert the component's HTML into the page\n\t * afterwords, apply any clickHandlers to elements that were added to the page\n\t */\n\trenderComponent() {\n\t\tPromise.all([SCSRenderAPI.importText(this.assetsPath + '/layout.html'),\n\t\t\tSCSRenderAPI.importCSS(this.assetsPath + '/styles/design.css')\n\t\t]).then((componentResources) => {\n\t\t\tconst componentTemplate = componentResources[0];\n\n\t\t\t// use the common code to generate the HTML for this component based on the componentLayout and customSettingsData\n\t\t\tconst componentHTML = CommonUtils.createHTML({\n\t\t\t\tMustache: this.Mustache,\n\t\t\t\ttemplate: componentTemplate,\n\t\t\t\tSCS: SCS,\n\t\t\t\tapi: SCSRenderAPI\n\t\t\t})\n\n\t\t\t// replace the content of the container with the rendered HTML\n\t\t\tthis.container.innerHTML = componentHTML;\n\t\t});\n\t}\n\n\t// the hydrate method is called when a component has been compiled into the page at runtime \n\t// this gives the opportunity to add any event handlers to the HTML that has been inserted into the page\n\thydrate(container) {\n\t\tthis.container = container;\n\t}\n\n\t// the render method is called to render the component dynamically onto the page\n\trender(container) {\n\t\tthis.container = container;\n\t\tthis.renderComponent();\n\t}\n}","// Common Utilities Class, imported by compile.mjs and render.mjs\nexport default class {\n\tconstructor() { }\n\n\t/**\n\t * Utility function to gather up all the pages for display in the footer\n\t * @param {object} SCS Contains structureMap, navigationRoot, and navigationCurr\n\t * @param {object} api SCSRenderAPI or SCSCompileAPI\n\t * @returns {array} Shaped array of page objects\n\t */\n\n\tstatic getPages(SCS, api) {\n\t\t//get all pages as dictionary\n\t\tconst objPageTree = SCS.structureMap\n\n\t\t//convert dictionary to array\n\t\tconst arPageTree = Object.values(objPageTree)\n\n\t\t//get top level pages\n\t\tconst arRootPages = arPageTree.filter(objPage => objPage.parentId == SCS.navigationRoot && !objPage.hideInNavigation)\n\n\t\tlet arRemovedPages = arRootPages.slice(2);\n\t\tarRemovedPages.reverse();\n\t\tlet indexCounter = 2;\n\t\tfor(let elPage of arRemovedPages) {\n\t\t\tarRootPages.splice(indexCounter,1,elPage);\n\t\t\tindexCounter++;\n\t\t}\n\n\t\tconst arPageList = arRootPages.map(objPage => {\n\t\t\treturn {\n\t\t\t\tname : objPage.name,\n\t\t\t\ttarget : objPage.linkTarget,\n\t\t\t\tlink : api.getPageLinkData(objPage.id).href,\n\t\t\t\tchildren : objPage.children.map(objChild => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tname : SCS.structureMap[objChild].name,\n\t\t\t\t\t\ttarget : api.getPageLinkData(objChild).target,\n\t\t\t\t\t\tlink : api.getPageLinkData(objChild).href\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t}\n\t\t})\n\n\t\treturn arPageList\n\t}\n\n\t/**\n\t * Use mustache to create the markup for the footer\n\t * @param {object} context Passing variables in to build the markup\n\t * @returns {string} HTML markup\n\t */\n\tstatic createHTML(context) {\n\t\t// extract all the required dependencies from the context\n\t\tconst Mustache = context.Mustache\n\t\tconst template = context.template\n\t\tconst SCS = context.SCS\n\t\tconst api = context.api\n\n\t\t// create the model\n\n\t\tconst model = {\n\t\t\tpageTree: this.getPages(SCS, api),\n\t\t\tcopyYear: (new Date()).getFullYear(),\n\t\t\tprivacyLink: api.getPageLinkData(Number(api.getCustomSiteProperty(\"privacyPageId\"))).href,\n\t\t\ttouLink: api.getPageLinkData(Number(api.getCustomSiteProperty(\"touPageId\"))).href\n\t\t};\n\n\n\t\t// render the component\n\t\ttry {\n\t\t\tconst strRendered= Mustache.render(template, model);\n\t\t\treturn strRendered;\n\t\t} catch (e) {\n\t\t\tconsole.log('Failed to expand Mustache template.', e);\n\t\t\treturn '';\n\t\t}\n\t}\n}"],"names":["constructor","args","this","mode","viewMode","id","assetsPath","import","meta","url","replace","sitesSDK","SitesSDK","Mustache","SCSRenderAPI","getMustache","addEventListeners","subscribe","MESSAGE_TYPES","SETTINGS_UPDATED","props","property","renderComponent","customSettingsData","value","componentLayout","Promise","all","importText","importCSS","then","componentResources","componentTemplate","componentHTML","static","SCS","api","objPageTree","structureMap","arRootPages","Object","values","filter","objPage","parentId","navigationRoot","hideInNavigation","slice","arRemovedPages","reverse","indexCounter","elPage","splice","map","name","target","linkTarget","link","getPageLinkData","href","children","objChild","context","template","model","pageTree","getPages","copyYear","Date","getFullYear","privacyLink","Number","getCustomSiteProperty","touLink","render","e","console","log","createHTML","container","innerHTML","hydrate"],"mappings":"QAKCA,YAAYC,GAEXC,KAAKC,KAAOF,EAAKG,SACjBF,KAAKG,GAAKJ,EAAKI,GAGfH,KAAKI,WAAaC,OAAOC,KAAKC,IAAIC,QAAQ,cAAe,IAGzDR,KAAKS,SAAWV,EAAKW,SACrBV,KAAKW,SAAWC,aAAaC,cAG7Bb,KAAKc,mBACL,CAMDA,oBAECd,KAAKS,SAASM,UAAUf,KAAK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