{"version":3,"file":"render.mjs","sources":["src/render.mjs","src/common.mjs"],"sourcesContent":["/**\n * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.\n * Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.\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\tremoveTextContent(container) {\n\t\tcontainer.querySelector('div').textContent = '';\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\t\tMustache: this.Mustache,\n\t\t\t\t\tcustomSettingsData: this.sitesSDK.getProperty('customSettingsData'),\n\t\t\t\t\tid: this.id,\n\t\t\t\t\ttemplate: componentTemplate\n\t\t\t\t});\n\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\tthis.removeTextContent(this.container);\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\tthis.removeTextContent(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\n","// Common Utilities Class\nexport default class {\n\tconstructor() {}\n\n\t/**\n\t * Create the HTML for the component\n\t * @param {Object} context common context for passing dependencies\n\t * @param {Object} args arguments to be passed to the component\n\t * @returns {String} HTML string\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\t\tcustomSettingsData = context.customSettingsData || {nls: {}},\n\t\t\tid = context.id,\n\t\t\ttemplate = context.template;\n\n\t\t// create the model\n\t\tconst model = {\n\t\t\telementId: customSettingsData.nls.elementId || id.split('-')[1],\n\t\t\tunset: false\n\t\t};\n\t\tmodel.unset = model.elementId === id.split('-')[1]\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","removeTextContent","container","querySelector","textContent","Promise","all","importText","importCSS","then","componentResources","componentTemplate","componentHTML","static","context","nls","template","elementId","split","unset","model","render","e","console","log","createHTML","getProperty","innerHTML","hydrate"],"mappings":"QASCA,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,CAEDE,kBAAkBC,GACjBA,EAAUC,cAAc,OAAOC,YAAc,EAC7C,CAIDP,gBAAgBrB,GACf6B,QAAQC,IAAI,CAACjB,aAAakB,WAAW9B,KAAKI,WAAa,kBACtDQ,aAAamB,UAAU/B,KAAKI,WAAa,wBACvC4B,MAAMC,IACR,MAAuBC,EAAGD,EAAmB,GAG1BE,ECvDD,MACpBrC,cAEA,CAMiBsC,kBAACC,GAEjB,MAAc1B,EAAG0B,EAAQ1B,SACxBU,EAAqBgB,EAAQhB,oBAAsB,CAACiB,IAAK,CAAA,GACzDnC,EAAKkC,EAAQlC,GACboC,EAAWF,EAAQE,WAGN,CACbC,UAAWnB,EAAmBiB,IAAIE,WAAarC,EAAGsC,MAAM,KAAK,GAC7DC,OAAO,GAERC,EAAMD,MAAQC,EAAMH,YAAcrC,EAAGsC,MAAM,KAAK,GAGhD,IACC,OAAe9B,EAACiC,OAAOL,EAAUI,EAIjC,CAHC,MAAOE,GAER,OADAC,QAAQC,IAAI,sCAAuCF,GAC5C,EACP,CACD,GDyBmCG,WAAW,CAC3CrC,SAAUX,KAAKW,SACfU,mBAAoBrB,KAAKS,SAASwC,YAAY,sBAC9C9C,GAAIH,KAAKG,GACToC,SAAUL,IAKZlC,KAAKyB,UAAUyB,UAAYf,EAE3BnC,KAAKwB,kBAAkBxB,KAAKyB,UAC5B,GACD,CAID0B,QAAQ1B,GACPzB,KAAKyB,UAAYA,EACjBzB,KAAKwB,kBAAkBC,EACvB,CAGDmB,OAAOnB,GACNzB,KAAKyB,UAAYA,EACjBzB,KAAKoB,iBACL"}