{"version":3,"file":"render.mjs","sources":["src/render.mjs","src/common.mjs"],"sourcesContent":["/**\n * Confidential and Proprietary for Oracle Corporation\n *\n * This computer program contains valuable, confidential, and\n * proprietary information. Disclosure, use, or reproduction\n * without the written authorization of Oracle is prohibited.\n *\n * Copyright (c) 2021, Oracle and/or its affiliates.\n */\nimport CommonUtils from './common.mjs';\n\n// The Custom Component class will be the \"default\" export from the module\nexport default class {\n\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 =\n\t\t\timport.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// 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\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// insert the component's HTML into the page \n\t// after it has added the component, it applies any clickHandlers to elements that were added to the page\n\trenderComponent(args) {\n\t\tPromise.all([SCSRenderAPI.importText(this.assetsPath + '/template.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\tcomponentLayout: this.sitesSDK.getProperty('componentLayout'),\n\t\t\t\tcustomSettingsData: this.sitesSDK.getProperty('customSettingsData'),\n\t\t\t\tid: this.id,\n\t\t\t\ttemplate: componentTemplate,\n\t\t\t\tcontentClient: this.sitesSDK.getProperty('contentClient')\n\t\t\t}, args);\n\n\t\t\t// replace the content of the container with the rendered HTML\n\t\t\tthis.container.innerHTML = componentHTML;\n\n\t\t\t// add in the click handlers\n\t\t\tthis.addClickHandlers(this.container);\n\t\t});\n\t}\n\n\taddClickHandlers(container) {\n\t\t//click handlers\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\tthis.addEventListeners()\n\t\tthis.addClickHandlers(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}","/**\n * Confidential and Proprietary for Oracle Corporation\n *\n * This computer program contains valuable, confidential, and\n * proprietary information. Disclosure, use, or reproduction\n * without the written authorization of Oracle is prohibited.\n *\n * Copyright (c) 2021, Oracle and/or its affiliates.\n */\n\n// Common Utilities Class\nexport default class {\n\tconstructor() {}\n\n\tstatic createHTML(context, args) {\n\t\t// extract all the required dependencies from the context\n\t\tconst Mustache = context.Mustache,\n\t\t\tcomponentLayout = context.componentLayout,\n\t\t\tcustomSettingsData = context.customSettingsData,\n\t\t\tid = context.id,\n\t\t\ttemplate = context.template,\n\t\t\tcontentClient = context.contentClient;\n\n\n\t\t// extract the original values (or apply deafult values)\n\t\tconst customData = (args && args.customSettingsData) || customSettingsData || {}\n\n\t\tcustomData.nls = customData.nls || {};\n\n\n\t\t// create the model\n\t\tconst model = {\n\t\t\ttitle: customData.nls.title,\n\t\t\tbodyText: customData.nls.bodyText,\n\t\t\tcolor: customData.color,\n\t\t\tbackgroundImageLink: contentClient.getRenditionURL({ id: customData.backgroundImageID}),\n\t\t\tlogoImageLink: contentClient.getRenditionURL({ id: customData.logoImageID}),\n\t\t\tsiteLink: customData.siteLink,\n\t\t\tstat1Count: customData.stat1Count,\n\t\t\tstat1Label: customData.stat1Label,\n\t\t\tstat2Count: customData.stat2Count,\n\t\t\tstat2Label: customData.stat2Label\n\t\t};\n\n\t\t// render the component\n\t\ttry {\n\t\t\treturn Mustache.render(template, model);\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","context","template","contentClient","customData","nls","title","bodyText","color","backgroundImageLink","getRenditionURL","backgroundImageID","logoImageLink","logoImageID","siteLink","stat1Count","stat1Label","stat2Count","stat2Label","render","model","e","console","log","createHTML","getProperty","container","innerHTML","addClickHandlers","hydrate"],"mappings":"QAcCA,YAAYC,GAEXC,KAAKC,KAAOF,EAAKG,SACjBF,KAAKG,GAAKJ,EAAKI,GAGfH,KAAKI,WACJC,OAAOC,KAAKC,IAAIC,QAAQ,cAAe,IAGxCR,KAAKS,SAAWV,EAAKW,SACrBV,KAAKW,SAAWC,aAAaC,cAG7Bb,KAAKc,mBACL,CAIDA,oBAECd,KAAKS,SAASM,UAAUf,KAAKS,SAASO,cAAcC,kBAAmBC,IAC/C,uBAAnBA,EAAMC,SACTnB,KAAKoB,gBAAgB,CACpBC,mBAAoBH,EAAMI,QAEE,oBAAnBJ,EAAMC,UAChBnB,KAAKoB,gBAAgB,CACpBG,gBAAiBL,EAAMI,OAExB,GAEF,CAIDF,gBAAgBrB,GACfyB,QAAQC,IAAI,CAACb,aAAac,WAAW1B,KAAKI,WAAa,kBACtDQ,aAAae,UA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